mirror of
https://github.com/janishutz/libreevent.git
synced 2025-11-25 05:14:23 +00:00
working user sign up
This commit is contained in:
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
@@ -71,11 +71,12 @@
|
||||
<body>
|
||||
<div class="content">
|
||||
<h1>Email Verification</h1>
|
||||
<p id="text">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.</p>
|
||||
<p id="text">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).</p>
|
||||
<form onsubmit="return submitFunction()" id="form">
|
||||
<select name="2fa" id="2fa">
|
||||
<option value="enhanced">Enhanced</option>
|
||||
<option value="simple">Simple</option>
|
||||
<option value="disabled">Disabled</option>
|
||||
</select><br>
|
||||
<input type="submit" value="Submit" class="submit">
|
||||
</form>
|
||||
@@ -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'
|
||||
|
||||
@@ -71,12 +71,11 @@
|
||||
<body>
|
||||
<div class="content">
|
||||
<h1>Email Verification</h1>
|
||||
<p id="text">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).</p>
|
||||
<p id="text">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.</p>
|
||||
<form onsubmit="return submitFunction()" id="form">
|
||||
<select name="2fa" id="2fa">
|
||||
<option value="enhanced">Enhanced</option>
|
||||
<option value="simple">Simple</option>
|
||||
<option value="disabled">Disabled</option>
|
||||
</select><br>
|
||||
<input type="submit" value="Submit" class="submit">
|
||||
</form>
|
||||
@@ -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'
|
||||
|
||||
69
src/server/ui/en/signup/signupMail.html
Normal file
69
src/server/ui/en/signup/signupMail.html
Normal file
@@ -0,0 +1,69 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Two-Factor Authentication</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
width: 100%;
|
||||
height: 800px;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.content {
|
||||
width: 80%;
|
||||
height: 90%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.ip {
|
||||
color: rgb(94, 94, 94);
|
||||
}
|
||||
|
||||
.logo {
|
||||
width: 70vw;
|
||||
}
|
||||
|
||||
.verify {
|
||||
padding: 20px 30px;
|
||||
background-color: rgb(0, 7, 87);
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
transition: 0.5s all;
|
||||
border-radius: 5px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.verify:hover {
|
||||
background-color: rgb(0, 12, 139);
|
||||
}
|
||||
|
||||
@media only screen and (min-width: 999px) {
|
||||
.logo {
|
||||
width: 20vw;
|
||||
}
|
||||
|
||||
.content {
|
||||
width: 40vw;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="content">
|
||||
<img :src="host + '/otherAssets/logo.png'" alt="Logo" class="logo">
|
||||
<h1>Welcome to {{ pageName }}</h1>
|
||||
<p>To complete your signup at {{ pageName }}, we need you to click the link below to confirm your email.</p>
|
||||
<a :href="host + '/user/signup/confirm?token=' + token" class="verify">Confirm</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user