mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-06-02 07:59:56 -04:00
private: adds tokens controller
adds private api adds AuthTokenDto and AuthTokenWithSecretDto adds necessary methods in the users service adds RandomnessError Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
1c7452d066
commit
80c7ae2fa9
10 changed files with 248 additions and 12 deletions
|
@ -4,22 +4,38 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm/index';
|
||||
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { User } from './user.entity';
|
||||
import { Type } from 'class-transformer';
|
||||
|
||||
@Entity()
|
||||
export class AuthToken {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@ManyToOne((_) => User, (user) => user.authToken)
|
||||
@ManyToOne((_) => User, (user) => user.authTokens)
|
||||
user: User;
|
||||
|
||||
@Column()
|
||||
identifier: string;
|
||||
|
||||
@Type(() => Date)
|
||||
@Column('text')
|
||||
createdAt: Date;
|
||||
|
||||
@Column()
|
||||
accessToken: string;
|
||||
|
||||
public static create(
|
||||
user: User,
|
||||
identifier: string,
|
||||
accessToken: string,
|
||||
): Pick<AuthToken, 'user' | 'accessToken'> {
|
||||
const newToken = new AuthToken();
|
||||
newToken.user = user;
|
||||
newToken.identifier = identifier;
|
||||
newToken.accessToken = accessToken;
|
||||
newToken.createdAt = new Date();
|
||||
return newToken;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue