mirror of
https://github.com/janishutz/libreevent.git
synced 2026-04-29 14:29:25 +02:00
working 2fa system
This commit is contained in:
@@ -8,13 +8,16 @@
|
||||
*/
|
||||
|
||||
const token = require( '../token.js' );
|
||||
// let createSSRApp = require( 'vue' ).createSSRApp;
|
||||
// let renderToString = require( 'vue/server-renderer' ).renderToString;
|
||||
let createSSRApp = require( 'vue' ).createSSRApp;
|
||||
let renderToString = require( 'vue/server-renderer' ).renderToString;
|
||||
const fs = require( 'fs' );
|
||||
const path = require( 'path' );
|
||||
|
||||
class TwoFA {
|
||||
constructor () {
|
||||
this.tokenStore = {};
|
||||
this.references = {};
|
||||
this.pwdChangeTokens = {};
|
||||
}
|
||||
|
||||
registerStandardAuthentication () {
|
||||
@@ -61,6 +64,29 @@ class TwoFA {
|
||||
} else if ( this.tokenStore[ token ]?.mode === 'enhanced' ) return 'enhanced';
|
||||
else return 'invalid';
|
||||
}
|
||||
|
||||
generatePwdChangeToken () {
|
||||
// TODO: Gen token and store in store
|
||||
return 'test';
|
||||
}
|
||||
|
||||
async generateTwoFAMail ( token, ip, domain, pageName ) {
|
||||
const tok = this.generatePwdChangeToken();
|
||||
const app = createSSRApp( {
|
||||
data() {
|
||||
return {
|
||||
token: token,
|
||||
ip: ip,
|
||||
host: domain,
|
||||
pageName: pageName,
|
||||
pwdChangeToken: tok,
|
||||
};
|
||||
},
|
||||
template: '' + fs.readFileSync( path.join( __dirname + '/twoFAMail.html' ) )
|
||||
} );
|
||||
|
||||
return await renderToString( app );
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TwoFA;
|
||||
@@ -19,9 +19,17 @@ const db = require( '../db/db.js' );
|
||||
module.exports.checkpassword = function checkpassword ( email, password ) {
|
||||
return new Promise( resolve => {
|
||||
db.getDataSimple( 'user', 'email', email ).then( data => {
|
||||
bcrypt.compare( password, data ).then( data => {
|
||||
resolve( data );
|
||||
} );
|
||||
if ( data ) {
|
||||
if ( data[ 0 ] ) {
|
||||
bcrypt.compare( password, data[ 0 ].pass ).then( res => {
|
||||
resolve( res );
|
||||
} );
|
||||
} else {
|
||||
resolve( false );
|
||||
}
|
||||
} else {
|
||||
resolve( false );
|
||||
}
|
||||
} );
|
||||
} );
|
||||
};
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<!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 back!</h1>
|
||||
<p>It looks like someone is trying to sign in to your account at {{ pageName }}. If it was you, please click the button below to confirm the login. If not, please <a :href="host + '/account/changePassword?token=' + pwdChangeToken">change</a> your password immediately.</p>
|
||||
<p class="ip">Logging in from IP {{ ip }}.</p>
|
||||
<a :href="host + '/user/2fa?token=' + token" class="verify">Verify</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user