Solved

Login Username AngularJS

Posted on 2014-09-24
3
181 Views
Last Modified: 2014-10-03
I have a login form where I enter username and password. I am using service and will set the current user.
Then I go to next page  and it shows username from the service. All good till I refresh the page using browser
which clears that username. How do store that information?
0
Comment
Question by:rbhargaw
  • 2
3 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 40343013
each time you star your application check status o the user (look for a valid session)

app.controller("mainCtrl", ["$scope", "User", "$location", function($scope, UserService, $location) {
       UserService.checkStatus().then(function(user) {
               if(user.isConnected) {
                   $scope.user = user.infos;
               }
               else {
                   $location.path("/signin"); // not signed, "redirect/open" signin page/view
               }
       });

       // Do other initialization, checking, ....

Open in new window

0
 

Author Comment

by:rbhargaw
ID: 40343039
The service is like these

appRoot.service('sharedUser', function () {

    return {
        getCurrentUser: function () {
            return currentUser;
        },
        setCurrentUser: function (value) {
            currentUser = value;
        }
    };
});

What shall I put in checkStatus?
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40343045
checkStatus do an http request to the server to check the state, return something like :

{ isConnected:true, data : { "nickname":"rbhargaw", "lastname":"bhargaw", ... } }
or if not connected :
{ isConnected:false, data : {} }

each time your user submit a valid username/password, you create a server session ID and store it in the database
so when someone request the homepage you check for the session ID in the database to see if valid or not
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question