Registration and activation
This commit is contained in:
49
backend/models/community/user.js
Normal file
49
backend/models/community/user.js
Normal file
@@ -0,0 +1,49 @@
|
||||
import { sequelize } from '../../utils/sequelize.js';
|
||||
import { DataTypes } from 'sequelize';
|
||||
import bcrypt from 'bcrypt';
|
||||
|
||||
const User = sequelize.define('user', {
|
||||
email: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
set(value) {
|
||||
this.setDataValue('email', bcrypt.hashSync(value, 10));
|
||||
}
|
||||
},
|
||||
username: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: true
|
||||
},
|
||||
password: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
set(value) {
|
||||
this.setDataValue('password', bcrypt.hashSync(value, 10));
|
||||
}
|
||||
},
|
||||
registrationDate: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW
|
||||
},
|
||||
active: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
resetToken: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: true
|
||||
},
|
||||
hashedId: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true
|
||||
}
|
||||
}, {
|
||||
tableName: 'user',
|
||||
schema: 'community',
|
||||
underscored: true,
|
||||
});
|
||||
|
||||
export default User;
|
||||
37
backend/models/community/user_param.js
Normal file
37
backend/models/community/user_param.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import { sequelize } from '../../utils/sequelize.js';
|
||||
import { DataTypes } from 'sequelize';
|
||||
import User from './user.js';
|
||||
import UserParamType from '../type/user_param.js';
|
||||
|
||||
const UserParam = sequelize.define('user_param', {
|
||||
userId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: User,
|
||||
key: 'id'
|
||||
}
|
||||
},
|
||||
paramTypeId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: UserParamType,
|
||||
key: 'id'
|
||||
},
|
||||
|
||||
},
|
||||
value: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
tableName: 'user_param',
|
||||
schema: 'community',
|
||||
underscored: true
|
||||
});
|
||||
|
||||
UserParam.belongsTo(User, { foreignKey: 'userId' });
|
||||
UserParam.belongsTo(UserParamType, { foreignKey: 'param_type_id' });
|
||||
|
||||
export default UserParam;
|
||||
13
backend/models/index.js
Normal file
13
backend/models/index.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import User from './community/user.js';
|
||||
import UserParam from './community/user_param.js';
|
||||
import UserParamType from './type/user_param.js';
|
||||
import Login from './logs/login.js';
|
||||
|
||||
const models = {
|
||||
User,
|
||||
UserParam,
|
||||
UserParamType,
|
||||
Login
|
||||
};
|
||||
|
||||
export default models;
|
||||
19
backend/models/logs/login.js
Normal file
19
backend/models/logs/login.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import { sequelize } from '../../utils/sequelize.js';
|
||||
import { DataTypes } from 'sequelize';
|
||||
|
||||
const Login = sequelize.define('login', {
|
||||
userId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false
|
||||
},
|
||||
timestamp: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW
|
||||
}
|
||||
}, {
|
||||
schema: 'logs',
|
||||
tableName: 'login'
|
||||
});
|
||||
|
||||
export default Login;
|
||||
15
backend/models/type/user_param.js
Normal file
15
backend/models/type/user_param.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import { sequelize } from '../../utils/sequelize.js';
|
||||
import { DataTypes } from 'sequelize';
|
||||
|
||||
const UserParamType = sequelize.define('user_param_type', {
|
||||
description: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
}
|
||||
}, {
|
||||
tableName: 'user_param',
|
||||
schema: 'type',
|
||||
underscored: true
|
||||
});
|
||||
|
||||
export default UserParamType;
|
||||
Reference in New Issue
Block a user