Using firebase, I am using onAuthStateChanged() twice each with a different callback function. I want to know if this is a correct way of using it or its only meant to be called once.
Why do I need 2 different onAuthStateChanged()?
Given a web app with a login system. Assume the user is not logged in yet so I don't want a logout button to show. That is one of the places I am using onAuthStateChanged() that checks if a user is logged in to show a logout button. Now, assume that a user again is not logged-in and is trying to access a page that is restricted to logged-in users. This is the second place I am using onAuthStateChanged(), here I display to the users that they are not signed and that they should first sign in and then after 3 seconds redirect them to the login page, and I display something else if a user is logged in. Also if a user refreshes the page whether they are signed in or not I want it to display the correct content.
TL;DR I just want to know if onAuthStateChanged() is designed to only be used once or is it okay to use it more then once.
Use it as many times as you see fit. I don't think you're going to run into any problems.
Related
I want to force anonymous to register an account before submitting the form.
So I have to allow permission for anonymous to access the form,
Then I use hook_form_FORM_ID_alter to edit form. Then I wanted to redirect submit button to another link if it is clicked by anonymous.(I still have no idea how to do it. It would be nice if anyone can tell me)
Is this the right solution?
For now,
I have a pop-up a login form (Modal forms and Facebook OAuth). In the form there is a register button. Then If user choose to register I want to keep the form that he have already input and show it after he confirm his email.
Thank you.
Off the top of my head, I would allow the form to be submitted either by an anonymous user or a registered one.
in my function MYMODULE_MYFORM_submit() I would check to see if the user is logged in.
If yes proceed as normal, if no, store the form, either in a temp SESSION variable or into a custom MySQL table and forward the user to login/register page (mysite.com/user) using drupal_goto('user')
once the user was registered you could then check for the existence of the form in the SESSION array or your MySQL table, and then carry on with the process as you would if the user had been logged in in the first place
Hope this makes sense or is of help
I would like to track a login event on my website.
The user writes username and pass then clicks on login, the form is submited and server checks if password is correct then redirect to the home page if it is.
But how could I add a Login event to GA? If I add it to the login button it wont be totally accurate as it will count even the failed login attempts.
Any ideas on how to solve this?
Thanks
Chris
Great question!
I think what you want is the Custom Variables that google analytics offers.
Simply put, for each page your user visits you set a custom variable with it's username for example.
I don't think you are interested in the login event, rather you are interested in what a logged in user visits - and this solution solves your problem
The Custom Variables answer will serve your purposes as outlined below but if you want another alternative (or actually really want to use Track Events) you could also add in a parameter to a successful logon which you can then read and process as you wish.
So for example:
Login
This will create a link to your login page. If the login is successful it will redirect back to the current page with the parameter login=true in the URL.
(You could check this parameter via JS for example and fire the Analytics track event call based on this).
One way to do this is let your login redirect to a page which says something like: "Thank you for logging in" and register this pageview to Google Analytics. And then have that page auto redirect you after 5 seconds to the page you were viewing. I've seen this done on a good amount of websites. If your login is using partial refresh you could even do it without having the user pass by a seperate page.
The simplest way is to use virtual pageviews (tutorial). It's a small piece of JS code, that you execute on any event you want. It makes GA think that there was a pageview. So you make a conditional statement like "if login == OK -> create a virtual pageview with URI "virtual/login/OK". Then you simply set this URI as a goal.
Custom Vars can be used for individual users but you need to set up a unique ID so that only you could recognise that once you pull the data out of GA. So in your dbase set a GoogleAnalyticsID against each user, then send that as a custom var to track users.
I have an ASP.Net(VB.Net) project which has various modules/functionality. I want to give users the freedom to set their own default startup page.
I don't know how to get a head-start implementing this feature.
Also, I am NOT using MVC
On the master page place some control to choose current page as default (i.e. button or checkbox). After user has select current page as default you can store the page address to user's profile or any storage you like.
Set the site start page like Default.aspx and in the Page_Load method of this page read user's saved default page if exists and redirect to it.
You'd want to set up a way for the User to store their preferred home page in your database (or your preferred method). Once that's done you should be able to do this in a simple fashion:
ASP.NET WebForms:
On the Master Page / Default page, check to see if they're logged in in your Page_Load event.
If they are, check to see if they have a start up page saved, if they do then use Response.Redirect and send them to their preferred location.
If they don't, or aren't logged in, then show them the default page.
ASP.NET MVC:
On the HomeController's Index method check to see if they're logged in.
If they are, check to see if they have a start up page saved, if they do then use RedirectToAction and send them to their preferred location.
If they don't, or aren't logged in, then show them the default view.
There are probably plenty of other ways to accomplish this as well, but this should be a straight forward way to get your started.
I'm newbie in drupal...
I have a drupal website, and i want to extend its login system - i've been looking around the code but end up with headache.
what i wan to do is:
I want to put additional hidden form inside any login form
create a session variable that will be used on login process (after user click submit) and then destroy the session after that.
extend the login validation system inside drupal based on point 1 & 2 above - so i need to to control if my extended validation is valid (and drupal validation is valid) then go to where? otherwise then go to where?
so with that I'll have my own login system + drupal login system
Is somebody ever try this before?
fyi: I'm using drupal 6
Thank you in Advance for helping me
And
To modify the login form, you will likely need hook_form_alter() and knowledge of the Form API
You can add additional elements to the login form, including hidden fields. Hidden can either mean hidden html form elements (<input type='hidden'/>) or values that are not output in the HTML at all but are stored server side for the corresponding validate and submit functions.
You can add additional functions to $form['#validate'] to change the login criteria (whether the login is accepted or not)
You can add additional functions to $form['#submit'] (note the '#') to add operations to perform after the user's login has passed validation. The default submit handler, user_login_submit(), simply redirects the user to their account page.
You should also consider checking http://drupal.org/project/logintoboggan . Logintoboggan is a module that tweaks and changes Drupal's default login by adding a lot of features. You can see how they achieved certain functionalities by reading the code. That will help you when you write your own code.
I am developing a page whereby users can login and demo some pieces of functionality. I only want to allow the user to demo this once per day.
A small example:
I have a web page with 3 buttons (relating to 3 different scenarios). On page load, I look up the database and check if the current logged in user has run any one of the 3 scenarios available (via an audit table). Each button is enabled/disabled based on the results. If any buttons are enabled, then they have not run that demo yet. By clicking the relative button, the demo runs a record is written into the Audit Table, and the button is disabled.
This was working ok, however, I realised that when I refresh the page (and confirm I want to re-submit the information) the demo runs again.
How can I stop this from happening? I need to only allow the user to run the demo once!
Thanks.
I would suggest that you change your form submission to use the Post/Redirect/Get pattern to avoid a resubmission if they hit refresh on the demo page.
Also, it seems like you should just be able to change the code at the point where it writes the record into the audit table to check to see if the record already exists, and if so, return a different result. I'd be pretty wary about this approach though. The "refresh" functionality of the browser isn't generally something you should be trying to prevent. What happens if a user hits "refresh" in the middle of their demo?
you can check not only on the page load to enable/disable the buttons, but on the button events, you can verify if that task has already been performed