Solved

Login with Angular JS

Posted on 2014-11-19
3
163 Views
Last Modified: 2015-01-02
Hello

I'm fairly new to Angular and turning an excisting PHP web application in to Angular. It's going well so far but I'm now stuck at the login bit and hoping someone can assist

The system has got several users, each operate in their own area where they can add their customers, update them, delete them etc - we are also running reporting for them

This is how the old system worked with login:
API call to the service using CURL / PHP and if the username / password is correct we take the ID of that user and store is in a session

User login -> Check authentication -> Set ID / Tokein Session -> Display data depending on the ID

Now this works fine and after 20min inactivity the session dies, or the client logs out. On each page we check if there is an ID and if not the user is sent to the login page


In Angular JS I thought there would be a session or similar so I could still use the session state, but I can't find anywhere if we can reach the server-side sessions or not ?


So I thought instead of me trying to do something halfway I would like to hear what is the correct way for me to do this

Once in the system everything will operate with the ID, posts, delete, updates etc will always have for the API or SQL statment "WHERE ID =''"

What's the best way of doing this in Angular JS

User login -> Run API call to see if correct -> If yes what ID is there -> Save ID so we can retrieve it from any page further on in the system (just like you can with a session)

Many thanks
0
Comment
Question by:DanteAdmin
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40453689
once the user try to access a page which need access your server (API request) need to send back an error : user not logged so you handle this and goto login page
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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

773 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