Is it possible to execute JavaScript (in template) just after successful login event or just after a successful logout event. If yes, How?
I don't want to asscociate this with login button click or logout button click on JS level because
Clicking the button is not a guarantee for successful login/logout event
I have a lot of login and logout buttons, many templates and partials so looking for a centralized solution
By the way i am also using python-social-auth.
Here's how I'd approach it.
Make a view which has a template which contains the JS you want to execute on login (it could even be a basically blank page which redirects to somewhere else, or a template which extends another template... there are a myriad of ways to be DRY here, I think).
Set SOCIAL_AUTH_LOGIN_REDIRECT_URL, SOCIAL_AUTH_NEW_USER_REDIRECT_URL, and/or SOCIAL_AUTH_NEW_ASSOCIATION_REDIRECT_URL (whichever of those you decide to use in step 3) in your settings.py.
Make an entry in your urls.py which makes that view accessible to either SOCIAL_AUTH_LOGIN_REDIRECT_URL (or both SOCIAL_AUTH_NEW_USER_REDIRECT_URL and SOCIAL_AUTH_NEW_ASSOCIATION_REDIRECT_URL, if you only want it to execute for new users of your site).
I'm getting those settings variables from the django-social-auth docs.
Related
I have a React/React-Router application that is required to know the context on how users landed on the page. There could be two different cases (1) 302 redirection (2) client-side redirection.
Let me add use cases to give more details around it
(1): users directly hits the URL and landed on a page
(2): Users clicked a button and are redirected to another page via Link API.
I noticed that the react router props contains history object and on (1) case, the history action is POP while on client-side redirection cases (2) it was either PUSH or REPLACE. Would it be a good assumption that I can honor the history action and determine 302 redirection by checking the action === POP?
to suit your particular your use case there are multiple approaches on how we can achieve this let's go over a few you referred to in question
User clicks on a button: so if we have full control over the functionality of a button we can define multiple parameters if a user clicks on it e.g. we can add a query parameter on the forwarding url and on the next page we know where the user came from kinda like this www.example.com/?referrer=oldButton this would indicate clear patterns on how a user came to the page. or in terms of react router, we can pass additional params to access later on another component.
history.push('/path', yourData);
users directly hits the URL and landed on a page: you assumed correct we can use POP, PUSH, REPLACE methods to identify how the user came to land on a specific page. a browser use what we call history, it keeps a record of every page visited before or after another, we can either use it directly or through react-router
Hope that helped :)
I need to send form data to another page that will allow the user to do something in a form and return the result of that form back to the original page? Is this possible? I know it's not ideal, but the issue is that I need to make a "drop-in" solution that does not need to be integrated with other code. I know it's a very specific request and scenario.
I know how to send POST data that doesn't require any user input on the processing page. i.e. I can send POST data to 'calculate.php' which will do the math and send it back, but if I need additional user input on 'calculate.php', how can I still send it back?
An example of expected results would be:
Page #1: User enters a number and presses submit to go to next page.
Page #2: User enters a second number and presses submit to finish.
Back to Page #1: User receives sum of both numbers.
Obviously, this is a really redundant thing to do, but I'm trying to simplify the problem as much as possible.
EDIT: There a few restrictions I forgot to add.
Page #1 is not my application, I am developing Page #2 as a "drop-in" solution for Page #1. Essentially, I can only use Page #1 to call Page #2 and receive a response from it. The problem is that I need to be able to allow for user input on Page #2.
I know I can post to Page #2 and then post to Page #1 again, but what if I need to maintain the state of Page #1. For example, if there's an open Web Socket connection.
Please note, I understand that this may be impossible or extremely difficult, but if I don't ask I'll never know right?
You want it with PHP or any other language. If you are running Php on server side then you can use Global variables like $_GET and $_POST.
Page #1: Use Post/Get method to send data to second page.
Page #2: Receive all fields' values using Globe variables ($_GET and $_POST). You can use these values as default values of form fields. Now submit this data to page 1 using post or get method.
Back to Page #1: Here you will receive the data of first page from second page and newly posted data from page 2
Either of these should work:
Never leave the page - use AJAX / XMLHttpRequest to call out to other pages to process chunks of data
Do everything on page 1 using "postbacks" -- the form targets are the same page, there is a state variable like "stage=1", and you use JavaScript to add set hidden variables for any additional state that's needed.
... PHP state validation and processing for the different stages ...
... one or more blocks of HTML for the page (PHP if / else can be used to choose between multiple page views) ...
Edit for added restrictions:
Have page 2 use postbacks or AJAX to collect the additional information
I figured out a few ways to do it.
Update a Database (or Data Store of some sort, depends on security needs) and have Page #1 listen for events from a separate page (on the same server as the database). Very similar to the way PayPal's Instant Payment Notification (IPN) works. I was actually able to set up server sent events with it as well.
Essentially, Page #1 sends data to Page #2 where the user will perform the function and then Page #2 will send POST data to a listener somewhere (either on the same server or Page #1's server), the listener will update a database and Page #1 will be listening or pulling to an event handler that will send an update once the database updates.
Use JavaScript Child/Parent Window functions. This is okay if Page #1 and Page #2 are on the same server, but can get messy and browsers have a lot of restrictions and it varies depending on browser.
Page #1 will open Page #2 in a child window, after the user performs a function, Page #2 will call a function that accepts the result data on Page #1.
Im new to Meteor/iron-router and am following the Microscope project/ file structure.
My question is :
I dont want the usual drop down login box with {{> loginButtons}}. How do I set up a stand alone authentication page as the primary loaded page if user is not registered or logged in? It will have the usual email/pw and social logins.
This is the basic router code for easy reference.
Do I just tweak the requireLogin part?
I also tried to use accounts-entry package but its fairly tough to figure how to use it.
You could also use an existing package from Atmosphere that provides a full-page login, such as UserAccounts.
One way to do this is to just roll your own implementation with the Meteor.loginWithPassword and Meteor.loginWith<ExternalService> functions. You can call these functions when the relevant buttons on your login page are clicked.
We are trying to implement a web page that each time of page refreshing will not result in the form resubmit, how to achieve that? Is there any Javascript code or HTML can make it WITHOUT external javascript library(jquery, dojo or extJs)
The reason of such design is that the form is going to tie an unique relation to current data with means cannot do it twice but for security reason we have to use POST instead of GET, also after the action we still want to preserve user the right to do similar action on the same page to another relation. so how to avoid a consequence like that?
Thanks.
Suppose that the action to the form submits it to submit_form.php. That file can handle the data and do whatever it needs to do. Then in it's response, it can redirect the browser to a separate page (you'll have to look up the exact method of how to do this depending on what language you write your POST handler in). This separate page can show the results of the form submit using session variables or some other method.
This is the problem: my web application (php) has a wizard feature which gathers customer's data page by page, and stores it in session. If customer tries to navigate away from the page before they have completed the wizard, I would like to display a massage to the effect of "You will lose your data". If the customer chooses to navigate away, the session data should be wiped.
I know that I can intercept this action by binding onpageunload event, but is there a way to then make another call, e.g. ajaxClearWizard() if the customer says "yes"?
PS I can see that, perhaps session shouldn't be used here, but I'm using an existing library, and although this wizard-data-persistence used to be a required feature the business now requires it to be removed :(
Any ideas, alternatives?
Thanks in advance!
window.onbeforeunload = function () {
return 'Your content has not been properly saved yet!';
};
This will make the browser display a confirmation box in middle with above content.