Skip to content

Commit 39aba0c

Browse files
committed
feat: add login module
1 parent f3acbb9 commit 39aba0c

File tree

3 files changed

+171
-0
lines changed

3 files changed

+171
-0
lines changed

src/app/login/login.component.html

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<div class="container">
2+
<div class="row justify-content-center">
3+
<div class="col col-lg-5">
4+
<div class="card">
5+
6+
<div *ngIf="signUpClicked; else loginComponent">
7+
<app-sign-up (onLogin)="getNotification($event)"></app-sign-up>
8+
</div>
9+
<ng-template #loginComponent>
10+
<mat-card>
11+
<mat-card-title>Login</mat-card-title>
12+
<mat-card-content>
13+
<form (ngSubmit)="submit()">
14+
<p>
15+
<mat-form-field>
16+
<input type="text" matInput placeholder="Username" name="username" [(ngModel)]="username">
17+
</mat-form-field>
18+
</p>
19+
20+
<p>
21+
<mat-form-field>
22+
<input type="password" matInput placeholder="Password" name="pass" [(ngModel)]="password">
23+
</mat-form-field>
24+
</p>
25+
26+
<p *ngIf="error" class="error">
27+
{{ error }}
28+
</p>
29+
<div class="button">
30+
<p><a href="javascript:void(0)" (click)="forgotPass()">Forgot Password</a> | <a href="javascript:void(0)" (click)="signUp()">Sign Up</a></p>
31+
<button type="submit" mat-raised-button>Login</button>
32+
</div>
33+
34+
</form>
35+
</mat-card-content>
36+
<mat-card-content>
37+
<div class="fb-login-button" data-width="" data-size="large" data-button-type="login_with" data-auto-logout-link="false" data-use-continue-as="false" ></div>
38+
</mat-card-content>
39+
</mat-card>
40+
</ng-template>
41+
42+
</div>
43+
</div>
44+
</div>
45+
</div>

src/app/login/login.component.scss

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
:host {
2+
display: flex;
3+
justify-content: center;
4+
margin: 100px 0px;
5+
}
6+
7+
.mat-form-field {
8+
width: 100%;
9+
min-width: 300px;
10+
}
11+
12+
mat-card-title,
13+
mat-card-content {
14+
display: flex;
15+
justify-content: center;
16+
}
17+
18+
.error {
19+
padding: 16px;
20+
width: 300px;
21+
color: white;
22+
background-color: red;
23+
}
24+
25+
.button{
26+
display: flex;
27+
justify-content: space-between;
28+
}
29+
30+
.button button{
31+
background: #4a4aff;
32+
color: white;
33+
}

src/app/login/login.component.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { Component, OnInit, NgZone, Input} from '@angular/core';
2+
import { Router } from '@angular/router';
3+
4+
import { SignUpComponent } from '../sign-up/sign-up.component';
5+
declare var FB: any;
6+
7+
8+
@Component({
9+
selector: 'app-login',
10+
templateUrl: './login.component.html',
11+
styleUrls: ['./login.component.scss']
12+
})
13+
export class LoginComponent implements OnInit {
14+
15+
@Input() signUpC : SignUpComponent;
16+
17+
username: String;
18+
password: String;
19+
error: String;
20+
signUpClicked: boolean = false;
21+
22+
constructor(private ngZone: NgZone, private router : Router) { }
23+
24+
ngOnInit() {
25+
(window as any).fbAsyncInit = () => {
26+
FB.init({appId: 'APPID',cookie: true, xfbml: true, version: 'v2.8'});
27+
FB.Event.subscribe('auth.authResponseChange', (response) => {
28+
if (response.status === 'connected') {
29+
this.statusChangeCallback(response)
30+
} else if (response.status === 'not_authorized') {
31+
console.log("Not authorised")
32+
} else {
33+
console.log("error in verifying")
34+
} });
35+
};
36+
37+
(function(d, s, id){
38+
var js, fjs = d.getElementsByTagName(s)[0];
39+
if (d.getElementById(id)) {return;}
40+
js = d.createElement(s); js.id = id;
41+
js.src = "https://connect.facebook.net/en_US/sdk.js";
42+
fjs.parentNode.insertBefore(js, fjs);
43+
}(document, 'script', 'facebook-jssdk'));
44+
}
45+
46+
47+
fetchUserDetail(){
48+
FB.api(
49+
'/me',
50+
'GET',
51+
{"fields":"id,name,birthday,email"},
52+
(response) => {
53+
console.log(response);
54+
this.navigate(['/dashboard']);
55+
}
56+
);
57+
}
58+
59+
public navigate(commands: any[]): void {
60+
this.ngZone.run(() => this.router.navigate(commands)).then();
61+
}
62+
63+
statusChangeCallback(res){
64+
if (res.status === 'connected') {
65+
this.fetchUserDetail();
66+
}
67+
}
68+
69+
70+
submit(){
71+
if(this.username === 'admin' && this.password === 'admin'){
72+
// console.log(this.username, this.password)
73+
this.router.navigate(['dashboard']);
74+
}
75+
else{
76+
this.error = "Wrong Credentials";
77+
}
78+
}
79+
80+
forgotPass(){
81+
alert("Yaay! You clicked on Forgot password.");
82+
}
83+
84+
signUp(){
85+
this.signUpClicked = true;
86+
}
87+
88+
getNotification(value){
89+
if(value === true)
90+
this.signUpClicked = false
91+
}
92+
93+
}

0 commit comments

Comments
 (0)