diff --git a/src/server/backend/credentials/2fa.js b/src/server/backend/credentials/2fa.js index 4351d8a..255783e 100644 --- a/src/server/backend/credentials/2fa.js +++ b/src/server/backend/credentials/2fa.js @@ -87,6 +87,21 @@ class TwoFA { return await renderToString( app ); } + + async generateSignupEmail ( token, domain, pageName ) { + const app = createSSRApp( { + data() { + return { + token: token, + host: domain, + pageName: pageName, + }; + }, + template: '' + fs.readFileSync( path.join( __dirname + '/../../ui/en/signup/signupMail.html' ) ) + } ); + + return await renderToString( app ); + } } module.exports = TwoFA; \ No newline at end of file diff --git a/src/server/backend/userRoutes.js b/src/server/backend/userRoutes.js index 184462e..0c482ac 100644 --- a/src/server/backend/userRoutes.js +++ b/src/server/backend/userRoutes.js @@ -15,6 +15,7 @@ const path = require( 'path' ); const mail = require( './mail/mailSender.js' ); const mailManager = new mail(); const bodyParser = require( 'body-parser' ); +const generator = require( './token.js' ); let responseObjects = {}; let authOk = {}; @@ -146,6 +147,11 @@ module.exports = ( app, settings ) => { if ( status ) { response.send( 'exists' ); } else { + ( async () => { + let tok = generator.generateToken( 60 ); + mailTokens[ tok ] = request.body.mail; + mailManager.sendMail( request.body.mail, await twoFA.generateSignupEmail( tok, settings.yourDomain, settings.name ), 'Confirm your email', settings.mailSender ); + } )(); pwdmanager.hashPassword( request.body.password ).then( hash => { db.writeDataSimple( 'users', 'email', request.body.mail, { 'email': request.body.mail, 'pass': hash, 'first_name': request.body.firstName, 'name': request.body.name, 'two_fa': 'disabled', 'user_data': JSON.stringify( { 'country': request.body.country } ) } ).then( () => { request.session.loggedInUser = true; diff --git a/src/server/ui/en/signup/allowTwoFA.html b/src/server/ui/en/signup/allowTwoFA.html index 9e6db51..fa94970 100644 --- a/src/server/ui/en/signup/allowTwoFA.html +++ b/src/server/ui/en/signup/allowTwoFA.html @@ -71,11 +71,12 @@

Email Verification

-

This website requires you to use Two-Factor Authentication. Please choose your mode below. By default, the enhanced mode is enabled which requires you to type a 6-character code into a field after confirming the mail address. You can change this setting at any point later.

+

We strongly encourage you to enable Two-Factor authentication for your account. Below you have the choice between not enabling it, enabling a mode where you just have to click the link in the email and you're in (simple) and a mode where you have to click the link in the mail and confirm the login by typing the code displayed on the main window (enhanced).


@@ -93,7 +94,7 @@ let data = ''; let fetchOptions = { method: 'post', - body: JSON.stringify( { 'code': data, 'token': location.search.substring( 7 ) } ), + body: JSON.stringify( { 'twoFA': data } ), headers: { 'Content-Type': 'application/json', 'charset': 'utf-8' diff --git a/src/server/ui/en/signup/enforceTwoFA.html b/src/server/ui/en/signup/enforceTwoFA.html index 4771818..32648a5 100644 --- a/src/server/ui/en/signup/enforceTwoFA.html +++ b/src/server/ui/en/signup/enforceTwoFA.html @@ -71,12 +71,11 @@

Email Verification

-

We strongly encourage you to enable Two-Factor authentication for your account. Below you have the choice between not enabling it, enabling a mode where you just have to click the link in the email and you're in (simple) and a mode where you have to click the link in the mail and confirm the login by typing the code displayed on the main window (enhanced).

+

This website requires you to use Two-Factor Authentication. Please choose your mode below. By default, the enhanced mode is enabled which requires you to type a 6-character code into a field after confirming the mail address. You can change this setting at any point later.


@@ -94,7 +93,7 @@ let data = ''; let fetchOptions = { method: 'post', - body: JSON.stringify( { 'code': data, 'token': location.search.substring( 7 ) } ), + body: JSON.stringify( { 'twoFA': data } ), headers: { 'Content-Type': 'application/json', 'charset': 'utf-8' diff --git a/src/server/ui/en/signup/signupMail.html b/src/server/ui/en/signup/signupMail.html new file mode 100644 index 0000000..ef2a40f --- /dev/null +++ b/src/server/ui/en/signup/signupMail.html @@ -0,0 +1,69 @@ + + + + + + Two-Factor Authentication + + + +
+ +

Welcome to {{ pageName }}

+

To complete your signup at {{ pageName }}, we need you to click the link below to confirm your email.

+ Confirm +
+ + \ No newline at end of file