First commit
This commit is contained in:
176
application/user/signup/user.signup.js
Normal file
176
application/user/signup/user.signup.js
Normal file
@@ -0,0 +1,176 @@
|
||||
|
||||
import user from '../user.js';
|
||||
|
||||
import username from './signup.username.js';
|
||||
|
||||
import password from './signup.password.js';
|
||||
|
||||
import passwordCheck from './signup.passwordCheck.js';
|
||||
|
||||
import signUpButton from './signup.button.js';
|
||||
|
||||
import document from '/unify/document.js';
|
||||
|
||||
import groups from '/user/group/user.group.permission.js';
|
||||
|
||||
import querySQL from '/unify/querySQL.js';
|
||||
|
||||
import adminGroup from '/user/group/user.group.admin.js';
|
||||
|
||||
import header from '/elements/header.js';
|
||||
|
||||
import page from '/elements/page.js';
|
||||
|
||||
import customLabel from "./signup.customLabel.js";
|
||||
|
||||
|
||||
#ifdef SERVER
|
||||
|
||||
//import bcrypt from "bcryptjs";
|
||||
|
||||
import crypto from "node:crypto";
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
export default class signup extends user, page{
|
||||
|
||||
layers = 1;
|
||||
|
||||
customElement = document.createElement("form");
|
||||
|
||||
useCustomElement = true;
|
||||
|
||||
debug = true;
|
||||
|
||||
|
||||
|
||||
|
||||
gridTemplate = ` "header header " 100px
|
||||
"userLabel username " 60px
|
||||
"passwordLabel password " 60px
|
||||
"passwordAgainLabel passwordAgain " 60px
|
||||
"empty signUpButton " 60px
|
||||
`;
|
||||
|
||||
|
||||
paddingRight = 30;
|
||||
|
||||
height = "300px";
|
||||
|
||||
header = new header("Signup");
|
||||
|
||||
// Children
|
||||
userLabel = new customLabel("Username");
|
||||
username = new username();
|
||||
|
||||
passwordLabel = new customLabel("Password");
|
||||
password = new password();
|
||||
|
||||
passwordAgainLabel = new customLabel("Password again");
|
||||
passwordAgain = new passwordCheck();
|
||||
|
||||
signUpButton = new signUpButton();
|
||||
|
||||
flexDirection = "column";
|
||||
|
||||
display = "grid";
|
||||
|
||||
pbkdf2Async(password, salt, iterations, keylen, digest) {
|
||||
|
||||
return new Promise( (res, rej) => {
|
||||
crypto.pbkdf2(password, salt, iterations, keylen, digest, (err, key) => {
|
||||
|
||||
err ? rej(err) : res(key);
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
node async registerUser( username, password, passwordAgain ) {
|
||||
|
||||
/*
|
||||
// Validation
|
||||
if( !this.username.isValid() ) {
|
||||
|
||||
object.status = "error";
|
||||
|
||||
object.error = "please fill in a valid username." ;
|
||||
|
||||
return object;
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
var table = this.table;
|
||||
|
||||
var users = this.find( "username", username );
|
||||
|
||||
var saltRounds = 10;
|
||||
|
||||
//var salt = bcrypt.genSaltSync( saltRounds );
|
||||
//var hash = bcrypt.hashSync( password, salt );
|
||||
|
||||
var salt = crypto.randomBytes(32).toString('base64');
|
||||
|
||||
var iterations = 100;
|
||||
|
||||
|
||||
if( !password ) {
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
if( password != passwordAgain ) {
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
var hash = await crypto.pbkdf2Sync( password, salt, iterations, 64,'SHA256' );
|
||||
|
||||
console.log("hash", hash.toString('hex'));
|
||||
|
||||
console.log("salt", salt);
|
||||
|
||||
if( users.length > 0 ) {
|
||||
|
||||
table.status = "user_exists";
|
||||
|
||||
return table;
|
||||
|
||||
}
|
||||
|
||||
table.username.value = username;
|
||||
|
||||
table.hash.value = await hash.toString('hex');
|
||||
|
||||
table.salt.value = salt;
|
||||
|
||||
table.signed.value = true;
|
||||
|
||||
table.groups.value = 1;
|
||||
|
||||
table.createInstance();
|
||||
|
||||
table.save();
|
||||
|
||||
table.status = "created_user";
|
||||
|
||||
return table;
|
||||
|
||||
}
|
||||
|
||||
permission() {
|
||||
|
||||
this.allow( groups.visitor , "PROCESS" );
|
||||
this.allow( groups.member , "PROCESS" );
|
||||
this.allow( groups.admin , "PROCESS" );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user