|
1 | 1 | import { Injectable } from '@angular/core'; |
2 | 2 | import { AngularFireAuth, AngularFireDatabase, FirebaseAuthState, AuthProviders, AuthMethods, AngularFire } from "angularfire2"; |
3 | 3 | import { Router } from "@angular/router"; |
| 4 | +import * as firebase from 'firebase'; |
| 5 | + |
| 6 | +export class EmailPasswordCredentials { |
| 7 | + email: string; |
| 8 | + password: string; |
| 9 | +} |
4 | 10 |
|
5 | 11 |
|
6 | 12 | @Injectable() |
@@ -39,11 +45,11 @@ export class AuthService { |
39 | 45 |
|
40 | 46 | // Returns current user display name or Guest |
41 | 47 | get currentUserDisplayName(): string { |
42 | | - if (!this.authenticated) { return 'GUEST' } |
| 48 | + if (!this.authenticated) { return 'Guest' } |
43 | 49 |
|
44 | | - else if (this.currentUserAnonymous) { return 'ANONYMOUS' } |
| 50 | + else if (this.currentUserAnonymous) { return 'Anonymous' } |
45 | 51 |
|
46 | | - else { return this.authState.auth.displayName || 'OAUTH USER' } |
| 52 | + else { return this.authState.auth.displayName || 'User without a Name' } |
47 | 53 |
|
48 | 54 | } |
49 | 55 |
|
@@ -83,20 +89,46 @@ export class AuthService { |
83 | 89 | .catch(error => console.log(error)); |
84 | 90 | } |
85 | 91 |
|
86 | | - //// Email/Password Auth //// |
87 | | - |
88 | | - // emailSignUp(email: string, password: string): firebase.Promise<FirebaseAuthState> { |
89 | | - // return this.af.auth.createUser({ email, password }) |
90 | | - // .then(() => this.writeUserData()) |
91 | | - // .catch(error => console.log(error)); |
92 | | - // } |
| 92 | + // anonymousUpgrade(): firebase.Promise<FirebaseAuthState> { |
| 93 | + // |
| 94 | + // let anonId = this.currentUserId |
93 | 95 | // |
94 | | - // emailLogin(email: string, password: string): firebase.Promise<FirebaseAuthState> { |
95 | | - // return this.af.auth.login({email, password}) |
96 | | - // .then(() => this.writeUserData()) |
97 | | - // .catch(error => console.log(error)); |
| 96 | + // // Login with google |
| 97 | + // return this.googleLogin().then( () => { |
| 98 | + // // get the data snapshot from anonymous account account |
| 99 | + // this.db.object(anonId).subscribe(snapshot => { |
| 100 | + // // map the anonymous user data to the new account. |
| 101 | + // this.db.object(this.currentUserId).update(snapshot) |
| 102 | + // }) |
| 103 | + // }); |
98 | 104 | // } |
99 | 105 |
|
| 106 | + //// Email/Password Auth //// |
| 107 | + |
| 108 | + emailSignUp(credentials: EmailPasswordCredentials): firebase.Promise<FirebaseAuthState> { |
| 109 | + return this.af.auth.createUser(credentials) |
| 110 | + .then(() => this.updateUserData()) |
| 111 | + .catch(error => console.log(error)); |
| 112 | + } |
| 113 | + |
| 114 | + emailLogin(credentials: EmailPasswordCredentials): firebase.Promise<FirebaseAuthState> { |
| 115 | + return this.af.auth.login(credentials, |
| 116 | + { provider: AuthProviders.Password, |
| 117 | + method: AuthMethods.Password |
| 118 | + }) |
| 119 | + .then(() => this.updateUserData()) |
| 120 | + .catch(error => console.log(error)); |
| 121 | + } |
| 122 | + |
| 123 | + // Sends email allowing user to reset password |
| 124 | + resetPassword(email: string) { |
| 125 | + var auth = firebase.auth(); |
| 126 | + |
| 127 | + return auth.sendPasswordResetEmail(email) |
| 128 | + .then(() => console.log("email sent")) |
| 129 | + .catch((error) => console.log(error)) |
| 130 | + } |
| 131 | + |
100 | 132 |
|
101 | 133 | //// Sign Out //// |
102 | 134 |
|
|
0 commit comments