Skip to content

Commit

Permalink
Check the 'validated_at' value of identities when logging in.
Browse files Browse the repository at this point in the history
  • Loading branch information
evert committed Jul 26, 2024
1 parent d2ff72f commit e45e26f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/login/controller/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import * as webAuthnService from '../../mfa/webauthn/service.js';
import { getSetting } from '../../server-settings.js';
import { hasUsers, PrincipalService } from '../../principal/service.js';
import * as userService from '../../user/service.js';
import { User } from '../../types.js';
import { PrincipalIdentity, User } from '../../types.js';
import { isValidRedirect } from '../utilities.js';
import { loginForm } from '../formats/html.js';
import * as services from '../../services.js';

class LoginController extends Controller {

Expand Down Expand Up @@ -47,8 +48,10 @@ class LoginController extends Controller {

const principalService = new PrincipalService('insecure');
let user: User;
let identity: PrincipalIdentity;
try {
user = await principalService.findByIdentity('mailto:' + ctx.request.body.userName) as User;
identity = await services.principalIdentity.findByUri('mailto:' + ctx.request.body.username);
user = await principalService.findByIdentity(identity) as User;
} catch (err) {
if (err instanceof NotFound) {
log(EventType.loginFailed, ctx);
Expand All @@ -67,6 +70,10 @@ class LoginController extends Controller {
log(EventType.loginFailedInactive, ctx.ip(), user.id, ctx.request.headers.get('User-Agent'));
return this.redirectToLogin(ctx, '', 'This account is inactive. Please contact Admin');
}
if (!identity.verifiedAt) {
log(EventType.loginFailedNotVerified, ctx.ip(), user.id, ctx.request.headers.get('User-Agent'));
return this.redirectToLogin(ctx, '', 'This identity has not been verified');
}

if (await this.shouldMfaRedirect(ctx, user)) {
return;
Expand Down

0 comments on commit e45e26f

Please sign in to comment.