({ request, match, user, session, isRunningLocally }: RequestHandlerParams)
| 17 | const description = 'Login to your account'; |
| 18 | |
| 19 | async function get({ request, match, user, session, isRunningLocally }: RequestHandlerParams) { |
| 20 | if (user) { |
| 21 | return new Response('Redirect', { status: 303, headers: { 'Location': `/` } }); |
| 22 | } |
| 23 | |
| 24 | const isEmailVerificationEnabled = await AppConfig.isEmailVerificationEnabled(); |
| 25 | const isMultiFactorAuthEnabled = await AppConfig.isMultiFactorAuthEnabled() && await UserModel.isThereAnAdmin(); |
| 26 | const isSingleSignOnEnabled = await AppConfig.isSingleSignOnEnabled(); |
| 27 | const config = await AppConfig.getConfig(); |
| 28 | const helpEmail = config.visuals.helpEmail; |
| 29 | |
| 30 | const singleSignOnUrl = isSingleSignOnEnabled |
| 31 | ? (await OidcModel.getSignInUrl({ requestPermissions: config.auth.singleSignOnScopes })) |
| 32 | : undefined; |
| 33 | |
| 34 | const searchParams = new URL(request.url).searchParams; |
| 35 | |
| 36 | const formData = new FormData(); |
| 37 | let notice = ''; |
| 38 | let email = ''; |
| 39 | |
| 40 | if (searchParams.get('success') === 'signup') { |
| 41 | email = searchParams.get('email') || ''; |
| 42 | formData.set('email', email); |
| 43 | |
| 44 | if (await AppConfig.isEmailVerificationEnabled()) { |
| 45 | notice = `You have received a code in your email. Use it to verify your email and login.`; |
| 46 | } else { |
| 47 | notice = `Your account was created successfully. Login below.`; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | const htmlContent = defaultHtmlContent({ |
| 52 | notice, |
| 53 | email, |
| 54 | formData, |
| 55 | isEmailVerificationEnabled, |
| 56 | isMultiFactorAuthEnabled, |
| 57 | isSingleSignOnEnabled, |
| 58 | helpEmail, |
| 59 | singleSignOnUrl, |
| 60 | }); |
| 61 | |
| 62 | return basicLayoutResponse(htmlContent, { |
| 63 | currentPath: match.pathname.input, |
| 64 | titlePrefix, |
| 65 | description, |
| 66 | match, |
| 67 | request, |
| 68 | user, |
| 69 | session, |
| 70 | isRunningLocally, |
| 71 | }); |
| 72 | } |
| 73 | |
| 74 | async function post({ request, match, user, session, isRunningLocally }: RequestHandlerParams) { |
| 75 | if (user) { |
nothing calls this directly
no test coverage detected