added email verification
This commit is contained in:
@@ -14,6 +14,7 @@ export let operationCodes = {
|
||||
LOGIN: 'LOGIN',
|
||||
SIGN_UP: 'SIGN_UP',
|
||||
RESET_PASSWORD: 'RESET_PASSWORD',
|
||||
EMAIL_VERIFICATION: 'EMAIL_VERIFICATION',
|
||||
|
||||
FIND_BY_EMAIL: 'FIND_BY_EMAIL',
|
||||
MODIFY_USER: 'MODIFY_USER',
|
||||
|
||||
@@ -9,6 +9,7 @@ export class AuthOperations implements OperationPlugin {
|
||||
LOGIN: 'LOGIN',
|
||||
SIGN_UP: 'SIGN_UP',
|
||||
RESET_PASSWORD: 'RESET_PASSWORD',
|
||||
EMAIL_VERIFICATION: 'EMAIL_VERIFICATION',
|
||||
};
|
||||
|
||||
// Utility function to validate email format
|
||||
@@ -147,10 +148,35 @@ export class AuthOperations implements OperationPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public static async handleEmailVerification(parsedMessage: ParsedMessage): Promise<ParsedMessage> {
|
||||
const { email } = parsedMessage.metaInfo || {};
|
||||
|
||||
if (!AuthOperations.isValidEmail(email)) {
|
||||
return {
|
||||
operationCode: operationCodes.ERR,
|
||||
metaInfo: { message: 'Invalid email format.' },
|
||||
};
|
||||
}
|
||||
|
||||
const user = userDatabase.findByEmail(email);
|
||||
if (!user) {
|
||||
return {
|
||||
operationCode: operationCodes.ERR,
|
||||
metaInfo: { message: 'User not found.' },
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
operationCode: operationCodes.OK,
|
||||
metaInfo: { message: 'Email verified successfully.' },
|
||||
};
|
||||
}
|
||||
|
||||
// Register operations with the OperationHandler
|
||||
public register(operationHandler: OperationHandler): void {
|
||||
operationHandler.registerHandler(AuthOperations.operationCodes.LOGIN, AuthOperations.handleLogin);
|
||||
operationHandler.registerHandler(AuthOperations.operationCodes.SIGN_UP, AuthOperations.handleSignUp);
|
||||
operationHandler.registerHandler(AuthOperations.operationCodes.RESET_PASSWORD, AuthOperations.handleResetPassword);
|
||||
operationHandler.registerHandler(AuthOperations.operationCodes.EMAIL_VERIFICATION, AuthOperations.handleEmailVerification);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user