Skip to content

feat: change nickname to username (#24) #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ export class Manager {

/**
* 校验密码是否正确
* @param nickname 昵称
* @param username 昵称
* @param password 密码
*/
public verify(nickname: string, password: string) {
return this.userModel.verify(nickname, password);
public verify(username: string, password: string) {
return this.userModel.verify(username, password);
}

/**
Expand All @@ -252,7 +252,7 @@ export class Manager {
*/
export class User extends Model {
public id!: number;
public nickname!: string;
public username!: string;
public admin!: number;
public active!: number;
public email!: string;
Expand All @@ -268,9 +268,9 @@ export class User extends Model {
// tslint:disable-next-line:variable-name
public delete_time!: Date;

static async verify(nickname: string, password: string): Promise<User> {
static async verify(username: string, password: string): Promise<User> {
// tslint:disable-next-line: await-promise
const user = await this.findOne({ where: { nickname, delete_time: null } });
const user = await this.findOne({ where: { username, delete_time: null } });
if (!user) {
throw new NotFound({ msg: '用户不存在' });
}
Expand Down Expand Up @@ -302,7 +302,7 @@ export class User extends Model {
toJSON() {
const origin = {
id: this.id,
nickname: this.nickname,
username: this.username,
admin: this.admin,
active: this.active,
email: this.email,
Expand Down
11 changes: 8 additions & 3 deletions lib/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { merge } from 'lodash';
import { UserAdmin, UserActive } from './enums';
import dayjs from 'dayjs';
import { generate } from './password-hash';
import {config} from './config';
import { config } from './config';

/**
* 记录信息的mixin
Expand Down Expand Up @@ -38,11 +38,16 @@ export let UserInterface = {
primaryKey: true,
autoIncrement: true
},
nickname: {
username: {
type: Sequelize.STRING({ length: 24 }),
allowNull: false,
unique: true
},
nickname: {
type: Sequelize.STRING({ length: 24 }),
comment: '昵称',
allowNull: true
},
avatar: {
// 用户默认生成图像,为null
type: Sequelize.STRING({ length: 500 }),
Expand All @@ -51,7 +56,7 @@ export let UserInterface = {
// @ts-ignore
return this.getDataValue('avatar') ? config.getItem('siteDomain') + 'assets/' + this.getDataValue('avatar') : null;
}

},
admin: {
type: Sequelize.TINYINT,
Expand Down
4 changes: 2 additions & 2 deletions lib/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const REG_XP = /(?<=\{)[^}]*(?=\})/g;
* mount: true
* },
* loginRequired,
* logger("{user.nickname}就是皮了一波"),
* logger("{user.username}就是皮了一波"),
* async ctx => {
* ctx.json({
* msg: "物质决定意识,经济基础决定上层建筑"
Expand Down Expand Up @@ -56,7 +56,7 @@ function writeLog(template: string, ctx: IRouterContext) {
{
message: message,
user_id: ctx.currentUser.id,
user_name: ctx.currentUser.nickname,
user_name: ctx.currentUser.username,
status_code: statusCode,
method: ctx.request.method,
path: ctx.request.path,
Expand Down
4 changes: 2 additions & 2 deletions lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function unsets(obj: any, props: Array<string>) {
* message: "昵称不可为空"
* }),
* tslib.__metadata("design:type", String)
* ] , RegisterForm.prototype, "nickname", void 0);
* ] , RegisterForm.prototype, "username", void 0);
* // 可被转化为
* decorate(
* [Length(2, 20, {
Expand All @@ -158,7 +158,7 @@ export function unsets(obj: any, props: Array<string>) {
* })],
* String,
* RegisterForm.prototype,
* "nickname"
* "username"
* )
* ```
*/
Expand Down