Solved

Login Username AngularJS

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

730 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