Solved

Login Username AngularJS

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

747 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

14 Experts available now in Live!

Get 1:1 Help Now