Skip to content

Commit 54a6127

Browse files
committed
Check if user is verified
1 parent 45c3824 commit 54a6127

File tree

8 files changed

+42
-22
lines changed

8 files changed

+42
-22
lines changed

client/src/app/_services/auth.service.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,22 @@ export class AuthService {
5454
return user.token;
5555
}
5656

57+
public isUserVerified() {
58+
const user = JSON.parse(localStorage.getItem('user'));
59+
60+
if (!user) {
61+
return '';
62+
}
63+
64+
return user.verifiedMobile;
65+
}
5766

5867
public generateOtp(){
5968
return this.http.post(
6069
`${this.apiBaseUrl}/users/otp`,{}
6170
);
6271
}
6372

64-
65-
6673
public verifyOtp(otp){
6774
const params = {
6875
otp: otp
@@ -74,8 +81,6 @@ export class AuthService {
7481
);
7582
}
7683

77-
78-
7984
public getUserDetails() {
8085
return this.http.get(
8186
`${this.apiBaseUrl}/users/details`

client/src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div id="navbar">
33
<app-navbar></app-navbar>
44
</div>
5-
<div id="otp-banner" *ngIf="!user.verifiedMobile">
5+
<div id="otp-banner" *ngIf="authService.isAuthenticated() && !authService.isUserVerified()">
66
<div class="columns is-centered has-text-centered">
77
<div class="column is-2" *ngIf="!otpGenerated">
88
<a class="button is-primary" (click)="generateOtp()">Click here to verify your Mobile Number</a>

client/src/app/app.component.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,39 @@ export class AppComponent {
1515

1616
constructor(
1717
private seoService: SEOService,
18-
private authService: AuthService
18+
public authService: AuthService
1919
) {
2020
this.seoService.addSeoData();
2121
}
2222

23-
generateOtp(){
23+
generateOtp() {
2424
this.authService.generateOtp()
2525
.subscribe(
2626
(res) => {
27-
this.otpGenerated= true;
28-
27+
this.otpGenerated = true;
28+
2929
}
3030
)
3131
}
32-
verifyOtp(){
32+
verifyOtp() {
3333
this.authService.verifyOtp(this.otp)
3434
.subscribe(
3535
(res) => {
36-
this.user.verifiedMobile = true;
36+
this.user.verifiedMobile = true;
3737
}
3838
)
3939

4040
}
4141
ngOnInit(): void {
4242
//Called after the constructor, initializing input properties, and the first call to ngOnChanges.
4343
//Add 'implements OnInit' to the class.
44-
this.authService.getUserDetails()
45-
.subscribe(
46-
(res) => {
47-
this.user = res;
48-
}
49-
)
44+
if (this.authService.isAuthenticated()) {
45+
this.authService.getUserDetails()
46+
.subscribe(
47+
(res) => {
48+
this.user = res;
49+
}
50+
)
51+
}
5052
}
5153
}

client/src/app/shelters/shelter-card/shelter-card.component.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<div class="columns">
99
<div class="column is-4">
1010
<p *ngIf="shelter['official']" class="has-text-success">
11-
<i class="fa fa-check"></i>&nbsp;Official Government Shelter
11+
<i class="fa fa-check-circle"></i>&nbsp;Official Government Shelter
1212
</p>
1313
<p class="title">
1414
{{ shelter.name }}
@@ -32,6 +32,9 @@
3232
<div class="column is-4">
3333
<div class="content">
3434
<p>Approx <span class="has-text-weight-bold">{{shelter['distance']}} kms</span> away</p>
35+
<p *ngIf="authService.isUserVerified()" class="has-text-info">
36+
<i class="fa fa-check-circle"></i>&nbsp;Posted by a verified user
37+
</p>
3538
</div>
3639
</div>
3740
</div>

client/src/app/shelters/shelter-card/shelter-card.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Shelter } from '../shelter';
33
import { SheltersService } from 'src/app/_services/shelters.service';
44
import { AlertService } from 'src/app/_services/alert.service';
55
import * as $ from 'jquery';
6+
import { AuthService } from 'src/app/_services/auth.service';
67

78
@Component({
89
selector: 'app-shelter-card',
@@ -41,7 +42,8 @@ export class ShelterCardComponent implements OnInit {
4142

4243
constructor(
4344
private shelterService: SheltersService,
44-
private alertService: AlertService
45+
private alertService: AlertService,
46+
public authService: AuthService
4547
) { }
4648

4749
ngOnInit() {

client/src/app/shelters/shelter-info/shelter-info.component.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@
88
<div class="columns">
99
<div class="column is-4">
1010
<p *ngIf="shelter['official']" class="has-text-success">
11-
<i class="fa fa-check"></i>&nbsp;Official Government Shelter
11+
<i class="fa fa-check-circle"></i>&nbsp;Official Government Shelter
1212
</p>
13+
<p *ngIf="authService.isUserVerified()" class="has-text-info">
14+
<i class="fa fa-check-circle"></i>&nbsp;Posted by a verified user
15+
</p>
16+
<br>
1317
<p class="title">
1418
{{ shelter.name }}
1519
</p>
1620
<p class="subtitle">
1721
{{ shelter.contact }}
1822
</p>
19-
<p class="has-text-weight-bold has-text-grey">Updated on {{shelter.lastUpdated | date: 'mediumDate'}} | {{shelter.lastUpdated | date: 'shortTime'}}</p>
23+
<p class="has-text-weight-bold has-text-grey">Updated on {{shelter.lastUpdated | date: 'mediumDate'}} |
24+
{{shelter.lastUpdated | date: 'shortTime'}}</p>
2025

2126
</div>
2227
<div class="column is-4">

client/src/app/shelters/shelter-info/shelter-info.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { environment } from 'src/environments/environment';
66
import { SheltersService } from 'src/app/_services/shelters.service';
77
import { Shelter } from '../shelter';
88
import { AlertService } from 'src/app/_services/alert.service';
9+
import { AuthService } from 'src/app/_services/auth.service';
910

1011
@Component({
1112
selector: 'app-shelter-info',
@@ -29,7 +30,8 @@ export class ShelterInfoComponent implements OnInit {
2930
constructor(
3031
private route: ActivatedRoute,
3132
private shelterService: SheltersService,
32-
private alertService: AlertService
33+
private alertService: AlertService,
34+
public authService: AuthService
3335
) { }
3436

3537
distance(place) {

server/api/users/util/userFunctions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ async function getUserDetails(user) {
3838
return {
3939
user: {
4040
email: user.email,
41+
verifiedMobile: user.verifiedMobile,
4142
token: createToken(user)
4243
}
4344
}

0 commit comments

Comments
 (0)