mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-18 17:25:16 -04:00
Move old backend code to old_src folder
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
c42d2223e8
commit
7b9f9a487b
97 changed files with 7 additions and 7 deletions
|
@ -1,74 +0,0 @@
|
|||
import scrypt from 'scrypt-kdf'
|
||||
import { UUIDV4 } from 'sequelize'
|
||||
import {
|
||||
BeforeCreate,
|
||||
BeforeUpdate,
|
||||
Column,
|
||||
DataType,
|
||||
Default,
|
||||
HasMany,
|
||||
IsEmail,
|
||||
Model,
|
||||
PrimaryKey,
|
||||
Table,
|
||||
Unique
|
||||
} from 'sequelize-typescript'
|
||||
import { Note } from './note'
|
||||
|
||||
@Table
|
||||
export class User extends Model<User> {
|
||||
@PrimaryKey
|
||||
@Default(UUIDV4)
|
||||
@Column(DataType.UUID)
|
||||
id: string
|
||||
|
||||
@Unique
|
||||
@Column(DataType.STRING)
|
||||
profileid: string
|
||||
|
||||
@Column(DataType.TEXT)
|
||||
profile: string
|
||||
|
||||
@Column(DataType.TEXT)
|
||||
history: string
|
||||
|
||||
@Column(DataType.TEXT)
|
||||
accessToken: string
|
||||
|
||||
@Column(DataType.TEXT)
|
||||
refreshToken: string
|
||||
|
||||
@Column(DataType.UUID)
|
||||
deleteToken: string
|
||||
|
||||
@IsEmail
|
||||
@Column(DataType.TEXT)
|
||||
email: string
|
||||
|
||||
@Column(DataType.TEXT)
|
||||
password: string
|
||||
|
||||
@HasMany(() => Note, { foreignKey: 'lastchangeuserId', constraints: false })
|
||||
@HasMany(() => Note, { foreignKey: 'ownerId', constraints: false })
|
||||
|
||||
@BeforeUpdate
|
||||
@BeforeCreate
|
||||
static async updatePasswordHashHook (user: User): Promise<void> {
|
||||
// suggested way to hash passwords to be able to do this asynchronously:
|
||||
// @see https://github.com/sequelize/sequelize/issues/1821#issuecomment-44265819
|
||||
|
||||
if (!user.changed('password')) {
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
return scrypt
|
||||
.kdf(user.getDataValue('password'), { logN: 15, r: 8, p: 1 })
|
||||
.then(keyBuf => {
|
||||
user.setDataValue('password', keyBuf.toString('hex'))
|
||||
})
|
||||
}
|
||||
|
||||
verifyPassword (attempt: string): Promise<boolean> {
|
||||
return scrypt.verify(Buffer.from(this.password, 'hex'), attempt)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue