?
Solved

Login Username AngularJS

Posted on 2014-09-24
3
Medium Priority
?
195 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

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.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

771 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