Alpha Video Training
Results 1 to 11 of 11

Thread: Saving User Login Name To Local Storage

  1. #1
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    632

    Default Saving User Login Name To Local Storage

    I want to save the last user login name on my login UX to local storage so the next time the user logs in they dont have to type in the username again. I assume I would have to have a variable that would be assigned the string that is inputted into the username textbox. How would exactly how I go about doing something like this?

  2. #2
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,537

    Default Re: Saving User Login Name To Local Storage

    Have a look at video UX_V12--166 : Mobile Applications with Persistent Logins

  3. #3
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    632

    Default Re: Saving User Login Name To Local Storage

    I looked at Persistent Logins video and tried to get that to work but couldnt. I simply want to store the username now and have the username textbox filled with the last username inputted. I couldnt tell by the video how to do it. I assume I would code it something like this:

    dim username as c

    username = e.datasubmitted.username

    BUT do I put this code in after Validate Client Side Event? How do I save that to local storage and set the username textbox to the variable username?

  4. #4
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    632

    Default Re: Saving User Login Name To Local Storage

    Would it be something like this in the after Validate Client Side Event?

    var userObject = {e.datasubmitted.username);
    localStorage.setObject('username', userObject);
    userObject = localStorage.getObject('username');
    username = userObject

  5. #5
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,537

    Default Re: Saving User Login Name To Local Storage

    Pretty much... but you need to check for localStorage... and you don't need to use the event you mention.

    In your Javascript functions put this...

    Code:
    function supports_html5_storage() {
      try {
        return 'localStorage' in window && window['localStorage'] !== null;
      } catch (e) {
        return false;
      }
    }
    In the UX afterLogin event... add this in front of whatever other code you have in there...

    Code:
    var ls = supports_html5_storage();
    if (ls){
    	var lsUserId = {dialog.Object}.getValue('Userid');
    	localStorage.setItem("ls_UserId",lsUserId);
    } else {
    	alert("Local Storage not available");
    }
    You don't really need the alert. If localStorage is there... great... if not... then no persistent UserId... up to you what you want.

    Finally, in the UX onRenderComplete event...

    Code:
    var lsUserId = localStorage.getItem("ls_UserId");
    if (lsUserId){
    	{dialog.Object}.setValue('Userid',lsUserId)
    }

  6. #6
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    632

    Default Re: Saving User Login Name To Local Storage

    In my login UX component I have a textbox called UserName that is where I want the username stored after the user logins

    This is what I have in Javascript Function of that Login UX Component:

    var ls = supports_html5_storage();
    if (ls){
    var lsUserId = {dialog.Object}.getValue('UserName');
    localStorage.setItem("ls_UserId",lsUserId);
    } else {

    }

    This is what I have in afterLogin Event:

    var ls = supports_html5_storage();
    if (ls){
    var lsUserId = {dialog.Object}.getValue('UserName');
    localStorage.setItem("ls_UserId",lsUserId);
    } else {

    }

    {dialog.object}.runAction('Call Main Panel');


    This is what I have in onRenderComplete event:

    var lsUserId = localStorage.getItem("ls_UserId");
    if (lsUserId){
    {dialog.Object}.setValue('UserName',lsUserId)
    }


    HOWEVER, the UserName textbox is not being populate with the last Login Name after logging in

  7. #7
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    632

    Default Re: Saving User Login Name To Local Storage

    Do I have to rebuild it in Phonegap first?

  8. #8
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,537

    Default Re: Saving User Login Name To Local Storage

    Take a look at your Javascript function. If that's code you have... then it's the same as in the afterLogin event... so that's wrong. Check my post again and correct the Javascript function.

  9. #9
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    632

    Default Re: Saving User Login Name To Local Storage

    Sorry, here is the Javascript Function I have:

    function supports_html5_storage() {
    try {
    return 'localStorage' in window && window['localStorage'] !== null;
    } catch (e) {
    return false;
    }
    }

  10. #10
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,537

    Default Re: Saving User Login Name To Local Storage

    Quote Originally Posted by swest View Post
    Do I have to rebuild it in Phonegap first?
    I don't know how your PhoneGap Build app is set up. I didn't know, until this post, that you were working with a PhoneGap Build app.

    The code works in a web app and a PhoneGap Build test app I created.

    When you debug your PhoneGap Build app, are you seeing any console errors?

  11. #11
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    632

    Default Re: Saving User Login Name To Local Storage

    It works. I just had to submit it to Phonegap to rebuild the app. Thanks for your help!

Similar Threads

  1. PhoneGap app using local storage and server storage mixed together
    By lgrupido in forum Mobile & Browser Applications
    Replies: 0
    Last Post: 02-25-2018, 03:23 PM
  2. Local Storage Keys
    By Transpeed in forum Mobile & Browser Applications
    Replies: 4
    Last Post: 09-22-2017, 03:51 AM
  3. Persist to Local Storage
    By Scott B in forum Mobile & Browser Applications
    Replies: 5
    Last Post: 05-05-2017, 01:32 PM
  4. delete local storage
    By jhaytko in forum Mobile & Browser Applications
    Replies: 10
    Last Post: 04-23-2015, 07:36 PM
  5. Local storage question
    By simonjm in forum Mobile & Browser Applications
    Replies: 2
    Last Post: 02-03-2015, 09:17 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •