Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement phone verification service #188

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
c06cbe2
Create service to handle phone verification
BambanzaJuniorThe2nd Dec 8, 2020
076c5d8
Rename methods sendSms and confirmSms in module VerificationService t…
BambanzaJuniorThe2nd Dec 14, 2020
4b126d2
Rename method confirmVerficationSms to confirmVerificationCode
BambanzaJuniorThe2nd Dec 14, 2020
62a9341
Create error message for when there's no record corresponding to a sp…
BambanzaJuniorThe2nd Dec 14, 2020
e31f4d3
Implement user service method for verifying donor by setting isPhoneV…
BambanzaJuniorThe2nd Dec 14, 2020
9d03e4c
Implement user service method for verifying donor by setting isPhoneV…
BambanzaJuniorThe2nd Dec 14, 2020
83c3ae6
Update sms format for phone verification
BambanzaJuniorThe2nd Dec 14, 2020
ec896a3
Commit master branch changes
BambanzaJuniorThe2nd Dec 15, 2020
94e579b
Commit master branch changes
BambanzaJuniorThe2nd Dec 15, 2020
2605035
Create event emitters and listeners for when a user is created or act…
BambanzaJuniorThe2nd Dec 15, 2020
319f286
implement error handling cases for error codes phoneAlreadyVerfied an…
BambanzaJuniorThe2nd Dec 15, 2020
4cb51bf
Resolve error 'Property getAllBeneficiaries does not exist'
BambanzaJuniorThe2nd Dec 15, 2020
6fc8075
Return corresponding verification record after verifying phone number
BambanzaJuniorThe2nd Dec 16, 2020
e8d9113
Design and implement phone verification page
BambanzaJuniorThe2nd Dec 16, 2020
9733a65
Create a route entry for the verify-phone page
BambanzaJuniorThe2nd Dec 17, 2020
c3383ff
Display phone verification-related error message on page in addition …
BambanzaJuniorThe2nd Dec 17, 2020
d3ebd1f
Redirect user to home page upon clicking Return home button
BambanzaJuniorThe2nd Dec 17, 2020
b532cfc
Use await when invoking bitly link shortener method shortenLink
BambanzaJuniorThe2nd Jan 4, 2021
27cb7cc
Update verified user projection label from VERIFIED_DONOR_PROJECTION …
BambanzaJuniorThe2nd Jan 4, 2021
8fb2b7c
Display appropriate error message on verify-phone page
BambanzaJuniorThe2nd Jan 5, 2021
679acd2
Exclude code when fetching phone verification records
BambanzaJuniorThe2nd Jan 6, 2021
b717950
Create endpoint for fetching specific phone verification record
BambanzaJuniorThe2nd Jan 6, 2021
e21c04c
Update utility method generateId to take in a size parameter
BambanzaJuniorThe2nd Jan 6, 2021
0624abe
Redefine method confirmVerificationCode to take in and id and code
BambanzaJuniorThe2nd Jan 6, 2021
32322ae
Redefine method confirmVerifcationCode to be more error-specific
BambanzaJuniorThe2nd Jan 7, 2021
0e5f2f2
Redefine endpoint for confirming verification code to be of HTTP PUT …
BambanzaJuniorThe2nd Jan 7, 2021
5a9087c
Create a frontend verifications service method to fetch speciclear
BambanzaJuniorThe2nd Jan 7, 2021
32d9d33
Implement logic for submitting phone verification code
BambanzaJuniorThe2nd Jan 7, 2021
920b662
Only pass the phone verification code in the request body when hittin…
BambanzaJuniorThe2nd Jan 8, 2021
a105384
Throw phone already verified error in method getById from service Pho…
BambanzaJuniorThe2nd Jan 8, 2021
9417726
Use base_url in link in getPhoneVerificationLink
BambanzaJuniorThe2nd Jan 8, 2021
c2f10b8
Remove access to state field message from verify-phone view
BambanzaJuniorThe2nd Jan 8, 2021
80af806
Implement new verifications service method for creating phone verific…
BambanzaJuniorThe2nd Jan 11, 2021
62e1be6
Create another a db-specific type that includes field code in phone v…
BambanzaJuniorThe2nd Jan 11, 2021
6e7b917
Implement validators and validation schemas for service phone-verific…
BambanzaJuniorThe2nd Jan 11, 2021
ba3e543
Pass user object in body when creating phone verification record
BambanzaJuniorThe2nd Jan 11, 2021
5ca422c
Pass user phone in body when creating phone verification records
BambanzaJuniorThe2nd Jan 11, 2021
6bac957
Remove event emitter emitUserCreated in User service method create
BambanzaJuniorThe2nd Jan 11, 2021
24de1fc
Remove event emitter emitUserCreated in User service method create
BambanzaJuniorThe2nd Jan 11, 2021
45eda17
Redirect user to verify their phone number after signing up
BambanzaJuniorThe2nd Jan 11, 2021
6efa0e2
Remove event emitter emitUserActivated in User service method activat…
BambanzaJuniorThe2nd Jan 11, 2021
6f6ac31
Pass phone to User-service method create upon hitting endpoint for cr…
BambanzaJuniorThe2nd Jan 11, 2021
1840802
Hide sign-up dialog upon redirection to verify-phone page
BambanzaJuniorThe2nd Jan 11, 2021
cf7213c
Fetch phone verification record only if not available in state
BambanzaJuniorThe2nd Jan 11, 2021
c74011e
Reformat phone verification sms to be shorter
BambanzaJuniorThe2nd Jan 11, 2021
380eb14
Fetch phone verification record only if not available in state
BambanzaJuniorThe2nd Jan 11, 2021
3ce4efa
Implement Phone Verification service method to resend new verificatio…
BambanzaJuniorThe2nd Jan 12, 2021
ef351ae
Create endpoint for requesting resend of phone verification code
BambanzaJuniorThe2nd Jan 12, 2021
a6bce31
Implement action for resending phone verification code
BambanzaJuniorThe2nd Jan 12, 2021
242d6b4
Update confirmVerificationCodeInputSchema to allow code as input
BambanzaJuniorThe2nd Jan 12, 2021
3472666
Throw Invalid phone verification code error if supplied code does not…
BambanzaJuniorThe2nd Jan 13, 2021
012c1cb
Create an invalidPhoneVerificationCode error code
BambanzaJuniorThe2nd Jan 13, 2021
9d6a2d8
Update link in getPhoneVerificationLink
BambanzaJuniorThe2nd Jan 13, 2021
728e902
Commit implementation of Verifications service method resendPhoneVeri…
BambanzaJuniorThe2nd Jan 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Return corresponding verification record after verifying phone number
  • Loading branch information
BambanzaJuniorThe2nd committed Dec 16, 2020
commit 6fc807502f08ff97bd56b06a2617291087f44f63
2 changes: 2 additions & 0 deletions server/src/core/event/event-bus.ts
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ export class EventBus extends EventEmitter {
}

onUserCreated(listener: Listener<UserCreatedEventData>): void {
console.log('In onUserCreated...');
this.on(EventName.USER_CREATED, listener);
}

@@ -45,6 +46,7 @@ export class EventBus extends EventEmitter {
}

emitUserCreated(eventData: UserCreatedEventData): void {
console.log('In emitUserCreated...');
this.innerEmit(EventName.USER_CREATED, eventData);
}

4 changes: 2 additions & 2 deletions server/src/core/link-generator/link-generator-service.ts
Original file line number Diff line number Diff line change
@@ -59,11 +59,11 @@ export class Links implements LinkGeneratorService {
}

async getPhoneVerificationLink(code: string, shorten: boolean = true): Promise<string> {
const link: string = `${this.args.baseUrl}/confirm/phone/${code}`;
const link: string = `${this.args.baseUrl}/verifications/phone/${code}`;
if (shorten) {
return this.args.shortener.shortenLink(link);
}

return link;
}
}
22 changes: 17 additions & 5 deletions server/src/core/phone-verification/phone-verification-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Db, Collection } from 'mongodb';
import { Db, Collection, FindAndModifyWriteOpResultObject } from 'mongodb';
import { generateId } from '../util';
import { VerificationService } from './types';
import { VerificationRecord, VerificationService } from './types';
import { UserService, User } from '../user';
import { SmsProvider } from '../sms';
import { Links } from '../link-generator';
@@ -12,7 +12,7 @@ import { UserCreatedEventData, UserActivatedEventData } from '../user';

const COLLECTION = 'phone-verifications';

export interface PhoneVerificationRecord {
export interface PhoneVerificationRecord extends VerificationRecord {
_id: string,
phone: string,
isVerified: boolean,
@@ -86,6 +86,7 @@ export class PhoneVerification implements VerificationService {
try {
const code = generateId();
const link = await this.args.links.getPhoneVerificationLink(code);
console.log('generated link: ', link);
const smsMessage = createPhoneVerificationSms(user, link);
await this.args.smsProvider.sendSms(user.phone, smsMessage);
}
@@ -96,7 +97,7 @@ export class PhoneVerification implements VerificationService {
}
}

async confirmVerificationCode(code: string): Promise<void> {
async confirmVerificationCode(code: string): Promise<PhoneVerificationRecord> {
try {
const record = await this.collection.findOne({ _id: code });
if (!record) {
@@ -106,8 +107,19 @@ export class PhoneVerification implements VerificationService {
throw createPhoneAlreadyVerifiedError(messages.ERROR_PHONE_ALREADY_VERIFIED);
}
else {
const user = await this.args.users.getByPhone(record.phone);
const result = await this.collection.findOneAndUpdate(
{ _id: code },
{
$set: { isVerified: true },
$currentDate: { updatedAt: true },
},
{ upsert: true, returnOriginal: false }
);

const user = await this.args.users.getByPhone(result.value.phone);
await this.args.users.verifyUser(user);
return result.value;

}
}
catch(e) {
9 changes: 8 additions & 1 deletion server/src/core/phone-verification/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { User } from '../user';

export interface VerificationRecord {
_id: string,
isVerified: boolean,
createdAt: Date,
updatedAt: Date,
}

export interface VerificationService {
createIndexes(): Promise<void>;
sendVerificationSms(user: User): Promise<void>;
confirmVerificationCode(code: string): Promise<void>;
confirmVerificationCode(code: string): Promise<VerificationRecord>;
}