Solved

Login Username AngularJS

Posted on 2014-09-24
3
179 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

867 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now