-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from hngprojects/feat/32-Authentication_User_L…
…og_In Authentication - User Log In
- Loading branch information
Showing
21 changed files
with
167 additions
and
5,959 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,36 @@ | ||
import { Request, Response, NextFunction } from "express"; | ||
|
||
import { AuthService } from "../services"; | ||
|
||
/* | ||
*TODO: add validation | ||
*/ | ||
const authService = new AuthService(); | ||
const signUp = async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const { mailSent, newUser, access_token } = await authService.signUp( | ||
req.body | ||
); | ||
res.status(201).json({ mailSent, newUser, access_token }); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
const verifyOtp = async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const { otp, token } = req.body; | ||
const { message } = await authService.verifyEmail(token as string, otp); | ||
res.status(200).json({ message }); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export { signUp, verifyOtp }; | ||
import { Request, Response, NextFunction } from "express"; | ||
import { AuthService } from "../services"; | ||
|
||
const authService = new AuthService(); | ||
|
||
const signUp = async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const { mailSent, newUser, access_token } = await authService.signUp( | ||
req.body | ||
); | ||
res.status(201).json({ mailSent, newUser, access_token }); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
const verifyOtp = async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const { otp, token } = req.body; | ||
const { message } = await authService.verifyEmail(token as string, otp); | ||
res.status(200).json({ message }); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
const login = async (req: Request, res: Response, next: NextFunction) => { | ||
try { | ||
const { access_token, user } = await authService.login(req.body); | ||
res.status(200).json({ access_token, user }); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export { signUp, verifyOtp, login }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from "./User"; | ||
export * from "./Organization"; | ||
export * from "./Profile"; | ||
export * from "./Product"; | ||
export * from "./article"; | ||
export * from "./user"; | ||
export * from "./organization"; | ||
export * from "./profile"; | ||
export * from "./product"; | ||
export * from "./helpcentertopic"; | ||
export * from "./notification"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Entity, PrimaryGeneratedColumn, Column, Unique } from "typeorm"; | ||
import ExtendedBaseEntity from "./extended-base-entity"; | ||
|
||
@Entity() | ||
@Unique(["user_id"]) | ||
export class NotificationSetting extends ExtendedBaseEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
user_id: string; | ||
|
||
@Column() | ||
email_notifications: boolean; | ||
|
||
@Column() | ||
push_notifications: boolean; | ||
|
||
@Column() | ||
sms_notifications: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { | ||
Entity, | ||
PrimaryGeneratedColumn, | ||
Column, | ||
CreateDateColumn, | ||
ManyToOne, | ||
} from "typeorm"; | ||
import ExtendedBaseEntity from "./extended-base-entity"; | ||
import { User } from "."; | ||
|
||
@Entity() | ||
export class Sms extends ExtendedBaseEntity { | ||
@PrimaryGeneratedColumn("uuid") | ||
id: string; | ||
|
||
@Column() | ||
phone_number: string; | ||
|
||
@Column() | ||
message: string; | ||
|
||
@Column() | ||
@ManyToOne(() => User, (user) => user.id) | ||
sender_id: User; | ||
|
||
@CreateDateColumn() | ||
createdAt: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { signUp, verifyOtp } from "../controllers"; | ||
import { signUp, verifyOtp, login } from "../controllers"; | ||
import { Router } from "express"; | ||
|
||
const authRoute = Router(); | ||
|
||
authRoute.post("/signup", signUp); | ||
authRoute.post("/verify-otp", verifyOtp); | ||
authRoute.post("/login", login); | ||
|
||
export { authRoute }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from "./auth.services"; | ||
export * from "./UserServivce"; | ||
export * from "./user.services"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters