Skip to content

Commit 0790c03

Browse files
authored
feat: change nickname to username (#24) (#25)
1 parent ace95c8 commit 0790c03

4 files changed

Lines changed: 19 additions & 14 deletions

File tree

lib/core.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ export class Manager {
223223

224224
/**
225225
* 校验密码是否正确
226-
* @param nickname 昵称
226+
* @param username 昵称
227227
* @param password 密码
228228
*/
229-
public verify(nickname: string, password: string) {
230-
return this.userModel.verify(nickname, password);
229+
public verify(username: string, password: string) {
230+
return this.userModel.verify(username, password);
231231
}
232232

233233
/**
@@ -252,7 +252,7 @@ export class Manager {
252252
*/
253253
export class User extends Model {
254254
public id!: number;
255-
public nickname!: string;
255+
public username!: string;
256256
public admin!: number;
257257
public active!: number;
258258
public email!: string;
@@ -268,9 +268,9 @@ export class User extends Model {
268268
// tslint:disable-next-line:variable-name
269269
public delete_time!: Date;
270270

271-
static async verify(nickname: string, password: string): Promise<User> {
271+
static async verify(username: string, password: string): Promise<User> {
272272
// tslint:disable-next-line: await-promise
273-
const user = await this.findOne({ where: { nickname, delete_time: null } });
273+
const user = await this.findOne({ where: { username, delete_time: null } });
274274
if (!user) {
275275
throw new NotFound({ msg: '用户不存在' });
276276
}
@@ -302,7 +302,7 @@ export class User extends Model {
302302
toJSON() {
303303
const origin = {
304304
id: this.id,
305-
nickname: this.nickname,
305+
username: this.username,
306306
admin: this.admin,
307307
active: this.active,
308308
email: this.email,

lib/interface.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { merge } from 'lodash';
33
import { UserAdmin, UserActive } from './enums';
44
import dayjs from 'dayjs';
55
import { generate } from './password-hash';
6-
import {config} from './config';
6+
import { config } from './config';
77

88
/**
99
* 记录信息的mixin
@@ -38,11 +38,16 @@ export let UserInterface = {
3838
primaryKey: true,
3939
autoIncrement: true
4040
},
41-
nickname: {
41+
username: {
4242
type: Sequelize.STRING({ length: 24 }),
4343
allowNull: false,
4444
unique: true
4545
},
46+
nickname: {
47+
type: Sequelize.STRING({ length: 24 }),
48+
comment: '昵称',
49+
allowNull: true
50+
},
4651
avatar: {
4752
// 用户默认生成图像,为null
4853
type: Sequelize.STRING({ length: 500 }),
@@ -51,7 +56,7 @@ export let UserInterface = {
5156
// @ts-ignore
5257
return this.getDataValue('avatar') ? config.getItem('siteDomain') + 'assets/' + this.getDataValue('avatar') : null;
5358
}
54-
59+
5560
},
5661
admin: {
5762
type: Sequelize.TINYINT,

lib/log.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const REG_XP = /(?<=\{)[^}]*(?=\})/g;
2020
* mount: true
2121
* },
2222
* loginRequired,
23-
* logger("{user.nickname}就是皮了一波"),
23+
* logger("{user.username}就是皮了一波"),
2424
* async ctx => {
2525
* ctx.json({
2626
* msg: "物质决定意识,经济基础决定上层建筑"
@@ -56,7 +56,7 @@ function writeLog(template: string, ctx: IRouterContext) {
5656
{
5757
message: message,
5858
user_id: ctx.currentUser.id,
59-
user_name: ctx.currentUser.nickname,
59+
user_name: ctx.currentUser.username,
6060
status_code: statusCode,
6161
method: ctx.request.method,
6262
path: ctx.request.path,

lib/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export function unsets(obj: any, props: Array<string>) {
147147
* message: "昵称不可为空"
148148
* }),
149149
* tslib.__metadata("design:type", String)
150-
* ] , RegisterForm.prototype, "nickname", void 0);
150+
* ] , RegisterForm.prototype, "username", void 0);
151151
* // 可被转化为
152152
* decorate(
153153
* [Length(2, 20, {
@@ -158,7 +158,7 @@ export function unsets(obj: any, props: Array<string>) {
158158
* })],
159159
* String,
160160
* RegisterForm.prototype,
161-
* "nickname"
161+
* "username"
162162
* )
163163
* ```
164164
*/

0 commit comments

Comments
 (0)