Skip to content

Commit

Permalink
#197 should not update session while syncing data
Browse files Browse the repository at this point in the history
  • Loading branch information
brookshi committed Jun 8, 2018
1 parent 905a8a1 commit 2825a0c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions api/controllers/user_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,23 @@ export default class UserController extends BaseController {

@POST()
async login(ctx: Koa.Context, @BodyParam body: DtoUser): Promise<ResObject> {
let checkLogin = await UserService.checkUser(body.email, body.password);
const checkLogin = await this.tryLogin(body);

if (!checkLogin.success) {
return checkLogin;
}

SessionService.login(ctx, (<User>checkLogin.result.user).id);

return checkLogin;
}

private async tryLogin(user: DtoUser) {
let checkLogin = await UserService.checkUser(user.email, user.password);
if (!checkLogin.success) {
return checkLogin;
}

checkLogin.message = Message.get('userLoginSuccess');
(<User>checkLogin.result.user).password = undefined;

Expand All @@ -58,7 +68,7 @@ export default class UserController extends BaseController {
@GET('/user/me')
async getUserInfo(ctx: Koa.Context): Promise<ResObject> {
const user = <User>(<any>ctx).session.user;
return await this.login(ctx, user);
return await this.tryLogin(user);
}

@GET('/user/logout')
Expand Down

0 comments on commit 2825a0c

Please sign in to comment.