/
login.component.ts
84 lines (73 loc) · 1.97 KB
/
login.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import {Component} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {User} from '../models/user.model';
import {FirebaseService} from '../services';
import {prompt} from "ui/dialogs";
import { RouterExtensions } from 'nativescript-angular/router/router-extensions';
@Component({
moduleId: module.id,
selector: 'yw-login',
templateUrl: 'login.html'
})
export class LoginComponent {
user: User;
isLoggingIn = true;
isAuthenticating = false;
constructor(private firebaseService: FirebaseService,
private routerExtensions: RouterExtensions
) {
this.user = new User();
this.user.email = "user@nativescript.org";
this.user.password = "password";
}
submit() {
this.isAuthenticating = true;
if (this.isLoggingIn) {
this.login();
} else {
this.signUp();
}
}
login() {
this.firebaseService.login(this.user)
.then(() => {
this.isAuthenticating = false;
this.routerExtensions.navigate(["/"], { clearHistory: true } );
})
.catch((message:any) => {
this.isAuthenticating = false;
});
}
signUp() {
this.firebaseService.register(this.user)
.then(() => {
this.isAuthenticating = false;
this.toggleDisplay();
})
.catch((message:any) => {
alert(message);
this.isAuthenticating = false;
});
}
forgotPassword() {
prompt({
title: "Forgot Password",
message: "Enter the email address you used to register for Yowwlr to reset your password.",
defaultText: "",
okButtonText: "Ok",
cancelButtonText: "Cancel"
}).then((data) => {
if (data.result) {
this.firebaseService.resetPassword(data.text.trim())
.then((result:any) => {
if(result){
alert(result);
}
});
}
});
}
toggleDisplay() {
this.isLoggingIn = !this.isLoggingIn;
}
}