Skip to content

Commit

Permalink
Better error handling in login controller
Browse files Browse the repository at this point in the history
  • Loading branch information
evert committed Jul 26, 2024
1 parent aeeda01 commit ac7e29c
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/login/controller/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,17 @@ class LoginController extends Controller {
async post(ctx: Context<any>) {

const principalService = new PrincipalService('insecure');
let user: User;
let identity: PrincipalIdentity;
try {
identity = await services.principalIdentity.findByUri('mailto:' + ctx.request.body.username);
user = await principalService.findByIdentity(identity) as User;
identity = await services.principalIdentity.findByUri('mailto:' + ctx.request.body.userName);
} catch (err) {
if (err instanceof NotFound) {
log(EventType.loginFailed, ctx);
return this.redirectToLogin(ctx, '', 'Incorrect username or password');
} else {
throw err;
}
}
const user = await principalService.findByIdentity(identity) as User;

if (!await userService.validatePassword(user, ctx.request.body.password)) {
log(EventType.loginFailed, ctx.ip(), user.id);
Expand Down

0 comments on commit ac7e29c

Please sign in to comment.