[AngularFire2] Signup and logout

import {AuthProviders, FirebaseAuthState, FirebaseAuth, AuthMethods} from "angularfire2";import {Injectable} from "@angular/core";import {Subject, BehaviorSubject} from "rxjs";import {AuthInfo} from "./AuthInfo";

@Injectable()export class AuthService {

  static UNKNOW_USER = new AuthInfo(null);

  private authState: FirebaseAuthState = null;  public authInfo$: BehaviorSubject<AuthInfo> = new BehaviorSubject<AuthInfo>(AuthService.UNKNOW_USER);

  constructor(public auth$: FirebaseAuth) {    auth$.subscribe((state: FirebaseAuthState) => {      this.authState = state;    });  }

  signUp(email, password){    return this.fromFirebaseAuthPromise(this.auth$.createUser(      {email, password}    ));  }

  login(email, password) {

    return this.fromFirebaseAuthPromise(this.auth$.login({      email, password    },{      method: AuthMethods.Password,      provider: AuthProviders.Password    }));  }

  logout(){    this.auth$.logout();    this.authInfo$.next(AuthService.UNKNOW_USER);  }

  fromFirebaseAuthPromise(promise) {    const subject = new Subject<any>();

    promise.then((res) => {      const uid = this.authState.uid;      const authInfo = new AuthInfo(uid);      this.authInfo$.next(authInfo);      subject.next(res);      subject.complete();    }, err => {      this.authInfo$.error(err);      subject.error(err);      subject.complete();    });

    return subject.asObservable();  }}
时间: 2024-12-14 06:56:07

[AngularFire2] Signup and logout的相关文章

基于django的视频点播网站开发-step3-注册登录功能

用户注册登录是一个网站的基本功能,django对这部分进行了很好的封装,我们只需要在django的基础上做些简单的修改就可以达到我们想要的效果.在本讲中,我们会用到user中的用户授权方面的一些函数,还会对django中的user进行扩展,以及django中的form验证. 效果展示 注册页面 登录页面 创建users应用 django的设计哲学是,一个应用只提供一种功能,比如users应用只提供用户相关功能,comment应用只提供评论相关功能,这能提高代码的重复利用率. 在django中,只

asp.net实现自动logout

用户登录系统后,如果没有进行任何操作,规定时间后,系统会自动弹出对话框,提示用户重新登录. 代码如下: <script type="text/javascript"> var timer; var wait = 20; // waiting time in minutes document.onmousemove = resetTimer; function resetTimer() { var timeoutPopup_display = document.getElem

How to Log Users Login and Logout Details Through Oracle Forms

Log user's login and logout details in to table through Oracle Forms using POST-LOGON and PRE-LOGOUT triggers to track the user's login and logout activity for auditing purposes. In this example one table and a sequence object is used to log the data

laravel5.2之logout注销账号无效

问题描述:laravel5.2的框架,使用框架auth用户认证后,进行账号注销退出的时候,无法实现. 只有清除浏览器缓存,才能实现账号退出. 解决办法: 改变路由 Route::get('auth/logout', 'Auth\[email protected]'); 然后在你的AuthController的构造函数(constructor)里加上这段代码 public function __construct() { $this->middleware('guest', ['except' =

[AngularFire2] Building an Authentication Observable Data Service

After successfully login, we want something help to check whether user has already login or not. And we will use Observable to do that. Create AuthInfo.ts: export class AuthInfo { constructor(private uid$: string){ } isLoggedIn() { return !!this.uid$

SQL Server的Audit login与Audit logout

对于SQL Server数据库,当进行数据库连接建立时会触发Audit login 事件:而当有某个数据库连接关闭时将触发Audit logout 事件. 注意,在SQLSERVER的事件探查器中,我们通过观察可以发现,Audit login 和 匹配的Audit logout 事件使用的是同一个SPID,而且Audit logout 事件记录的Start Time正是Audit login事件产生的时间.如下图.

Logout: 究竟用GET还是POST?

ReSTful风格api设计中,遇到了一个问题 logout究竟用get还是post? 理论上来说logout安全(logout没有改变服务器状态,只是改变了session)且幂等,应该是get 但是用get在2010年前可能是正确答案,只不过现在的浏览器普遍具备pre load(预加载)功能,用get就悲剧了 so,post吧

Spring Security笔记:自定义Login/Logout Filter、AuthenticationProvider、AuthenticationToken

在前面的学习中,配置文件中的<http>...</http>都是采用的auto-config="true"这种自动配置模式,根据Spring Security文档的说明: ------------------ auto-config Automatically registers a login form, BASIC authentication, logout services. If set to "true", all of thes

【shiro】authc与logout

DefaultFilterChainManager会默认添加org.apache.shiro.web.filter.mgt.DefaultFilter中声明的拦截器: Java代码 public enum DefaultFilter { anon(AnonymousFilter.class), authc(FormAuthenticationFilter.class), authcBasic(BasicHttpAuthenticationFilter.class), logout(LogoutF