mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 01:39:52 +08:00
fix(users): enforce read-only ownership and revocable managed sessions
This commit is contained in:
commit
aafd85cbcc
505 files changed
+59207
-6463
No files matched your search
+6
-3
@@ -9,18 +9,20 @@ export class User {
|
||||
status: UserStatus;
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
sessions?: { digest: string; platform: string }[];
|
||||
|
||||
constructor(options: User) {
|
||||
this.id = options.id;
|
||||
this.username = options.username;
|
||||
this.password = options.password;
|
||||
this.role = options.role || UserRole.user;
|
||||
this.role = options.role ?? UserRole.user;
|
||||
this.status =
|
||||
typeof options.status === 'number' && UserStatus[options.status]
|
||||
? options.status
|
||||
: UserStatus.active;
|
||||
this.createdAt = options.createdAt;
|
||||
this.updatedAt = options.updatedAt;
|
||||
this.sessions = options.sessions || [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +38,7 @@ export enum UserStatus {
|
||||
|
||||
export interface UserInstance extends Model<User, User>, User {}
|
||||
export const UserModel = sequelize.define<UserInstance>('User', {
|
||||
sessions: { type: DataTypes.JSON, allowNull: false, defaultValue: [] },
|
||||
username: {
|
||||
type: DataTypes.STRING,
|
||||
unique: true,
|
||||
@@ -46,11 +49,11 @@ export const UserModel = sequelize.define<UserInstance>('User', {
|
||||
allowNull: false,
|
||||
},
|
||||
role: {
|
||||
type: DataTypes.NUMBER,
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: UserRole.user,
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.NUMBER,
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: UserStatus.active,
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user