Implement user registration and email verification features
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
//app/models/user/emailVerification.model.js
|
||||
module.exports = (sequelize, DataTypes) => {
|
||||
const EmailVerification = sequelize.define(
|
||||
"EmailVerification",
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.STRING,
|
||||
primaryKey: true,
|
||||
},
|
||||
|
||||
user_id: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
|
||||
tokenHash: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
|
||||
expiresAt: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
},
|
||||
|
||||
usedAt: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
},
|
||||
{
|
||||
tableName: "email_verifications",
|
||||
timestamps: true,
|
||||
}
|
||||
);
|
||||
|
||||
EmailVerification.associate = (db) => {
|
||||
EmailVerification.belongsTo(db.User, {
|
||||
foreignKey: "user_id",
|
||||
as: "user",
|
||||
});
|
||||
};
|
||||
|
||||
return EmailVerification;
|
||||
};
|
||||
@@ -36,9 +36,25 @@ module.exports = (sequelize, DataTypes) => {
|
||||
allowNull: false
|
||||
},
|
||||
accountType: {
|
||||
type: DataTypes.ENUM("user", "admin", "superadmin", "manager", "business_customer", "rider", "customer","support_agent"),
|
||||
defaultValue: "user"
|
||||
}
|
||||
type: DataTypes.ENUM("admin", "superadmin", "manager", "business_customer", "rider", "customer","support_agent"),
|
||||
defaultValue: "customer"
|
||||
},
|
||||
accountStatus: {
|
||||
type: DataTypes.ENUM(
|
||||
"PENDING_VERIFICATION",
|
||||
"ACTIVE",
|
||||
"SUSPENDED",
|
||||
"DEACTIVATED"
|
||||
),
|
||||
allowNull: false,
|
||||
defaultValue: "PENDING_VERIFICATION",
|
||||
},
|
||||
emailVerifiedAt: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
|
||||
},
|
||||
{
|
||||
tableName: "users",
|
||||
@@ -55,6 +71,11 @@ module.exports = (sequelize, DataTypes) => {
|
||||
foreignKey: "user_id",
|
||||
as: "profile",
|
||||
});
|
||||
|
||||
User.hasMany(db.EmailVerification, {
|
||||
foreignKey: "user_id",
|
||||
as: "emailVerifications",
|
||||
});
|
||||
};
|
||||
|
||||
return User;
|
||||
|
||||
Reference in New Issue
Block a user