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

查看:151
本文介绍了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.

我想做的事情什么结果
一)。我希望有一个单一的页面,我的项目 http://myproject.com 。结果
湾)一旦用户点击浏览器的URL的基础上,如果用户登录与否,他是一个主页/视图或登录页面psented $ P $ /视图中的相同网址 HTTP ://myproject.com 结果。
角),如果用户没有登录,则填写表单和服务器设置一个 USER_TOKEN 闭会期间,所以到端点的所有进一步的请求将根据<$进行身份验证C $ C> 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

我的困惑结果
一)如何处理使用AngularJS客户端验证?我看到 href=\"https://github.com/witoldsz/angular-http-auth\">和的此处,但不知道如何使用它们结果
湾)我如何present根据用户不同的意见,如果用户在或不符合相同的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的第一次真正感到困惑,以如何下手。任何建议和/或资源都非常AP preciated。

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

查找由安迪乔斯林的注释。

Look for the comment by "Andy Joslin".

<一个href=\"https://groups.google.com/forum/?fromgroups=#!searchin/angular/authentication/angular/POXLTi_JUgg/VwStpoWCPUQJ\">https://groups.google.com/forum/?fromgroups=#!searchin/angular/authentication/angular/POXLTi_JUgg/VwStpoWCPUQJ

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

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