AngularJS:在单页​​应用程序中使用身份验证的基本示例 [英] AngularJS: Basic example to use authentication in Single Page Application

查看:25
本文介绍了AngularJS:在单页​​应用程序中使用身份验证的基本示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 AngularJS 的新手,并且浏览了他们的教程并对其有所了解.

I am new to AngularJS and gone through their tutorial and got a feel for it.

我为我的项目准备了一个后端,其中每个 REST 端点都需要进行身份验证.

I have a backend for my project ready where each of the REST endpoints needs to be authenticated.

我想做什么
a.) 我想为我的项目 http://myproject.com 设置一个页面.
b.) 一旦用户在浏览器中点击 URL,根据用户是否登录,他会在相同的 URL 下看到主页/视图或登录页面/视图 http://myproject.com.
c.) 如果用户没有登录,它会填写表单并且服务器在会话中设置一个 USER_TOKEN,因此所有对端点的进一步请求都将基于 USER_TOKEN 进行身份验证

What I want to do
a.) I want to have a single page for my project http://myproject.com.
b.) Once a user hits the URL in browser, based on if user is logged in or not, he is presented with a home page/view or login page/view under the same url http://myproject.com.
c.) if a user is not logged in, it fills out the form and server sets a USER_TOKEN in session, so all further requests to endpoints will be authenticated based on USER_TOKEN

我的困惑
a.) 如何使用 AngularJS 处理客户端身份验证?我看到了这里这里 但不明白如何使用它们
b.) 如何根据用户是否在同一 url http://myproject.com

My Confusions
a.) How can I handle client-side authentication using AngularJS? I saw here and here but did not understand how to use them
b.) How can I present different views to user based on if user is logged in or not under same url http://myproject.com

我是第一次使用 angular.js 并且真的对如何开始感到困惑.非常感谢任何建议和/或资源.

I am using angular.js for the very first time and really getting confused as to how to start. Any advices and/or resources are very much appreciated.

推荐答案

我喜欢这种方法并在服务器端实现它,而无需在前端做任何与身份验证相关的事情

I like the approach and implemented it on server-side without doing any authentication related thing on front-end

我最新应用程序的技术"是.. 客户不在乎验证.应用程序中的每一件事都需要先登录,所以服务器总是提供登录页面,除非现有用户是在会话中检测到.如果找到 session.user,则服务器只是发送 index.html.巴姆:-o

My 'technique' on my latest app is.. the client doesn't care about Auth. Every single thing in the app requires a login first, so the server just always serves a login page unless an existing user is detected in the session. If session.user is found, the server just sends index.html. Bam :-o

查找Andrew Joslin"的评论.

Look for the comment by "Andrew Joslin".

https://groups.google.com/forum/?fromgroups=#!searchin/angular/authentication/angular/POXLTi_JUgg/VwStpoWCPUQJ

这篇关于AngularJS:在单页​​应用程序中使用身份验证的基本示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆