First commit
This commit is contained in:
86
application/user/signup/signup.button.js
Normal file
86
application/user/signup/signup.button.js
Normal file
@@ -0,0 +1,86 @@
|
||||
|
||||
import button from '/elements/button.js';
|
||||
|
||||
import tools from '/unify/tools.js';
|
||||
|
||||
import document from '/unify/document.js';
|
||||
|
||||
|
||||
export default class signupButton extends button {
|
||||
|
||||
text = "Signup";
|
||||
|
||||
margin = 6;
|
||||
|
||||
async click( event, object ){
|
||||
|
||||
|
||||
var signup = this.parent;
|
||||
/*
|
||||
if( !signin.username.isValid() ) {
|
||||
|
||||
signin.username.focus();
|
||||
|
||||
signin.username.showError( "please fill in a valid username." );
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
if( !signin.password.isValid() ) {
|
||||
|
||||
signin.password.showError("please fill in a valid password.");
|
||||
|
||||
signin.password.focus();
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
if( !signin.passwordAgain.isValid() ) {
|
||||
|
||||
signin.passwordAgain.showError("please fill in a valid password check.");
|
||||
|
||||
signin.passwordAgain.focus();
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
var username = signup.username.value;
|
||||
|
||||
var password = signup.password.value;
|
||||
|
||||
var passwordAgain = signup.passwordAgain.value;
|
||||
|
||||
|
||||
var user = await signup.registerUser( username, password, passwordAgain );
|
||||
|
||||
|
||||
if( user ) {
|
||||
|
||||
switch( user.status ) {
|
||||
|
||||
case "created_user":
|
||||
|
||||
alert("user created you can now sign in.");
|
||||
|
||||
break;
|
||||
|
||||
case "user_exists":
|
||||
|
||||
alert("user already exists.");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
14
application/user/signup/signup.customLabel.js
Normal file
14
application/user/signup/signup.customLabel.js
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
|
||||
import label from '/elements/label.js';
|
||||
|
||||
|
||||
export default class customLabel extends label{
|
||||
|
||||
textAlign = "right";
|
||||
|
||||
alignItems = "end";
|
||||
|
||||
flexDirection = "column";
|
||||
|
||||
}
|
||||
11
application/user/signup/signup.password.js
Normal file
11
application/user/signup/signup.password.js
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
import inputPassword from '/elements/inputPassword.js';
|
||||
|
||||
export default class signupPassword extends inputPassword{
|
||||
|
||||
minLength = 7;
|
||||
|
||||
|
||||
useCustomElement = true;
|
||||
|
||||
}
|
||||
32
application/user/signup/signup.passwordCheck.js
Normal file
32
application/user/signup/signup.passwordCheck.js
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
import inputPassword from '/elements/inputPassword.js';
|
||||
|
||||
export default class signupPasswordCheck extends inputPassword{
|
||||
|
||||
useCustomElement = true;
|
||||
|
||||
async keyup( event ){
|
||||
|
||||
this.value = event.target.value;
|
||||
|
||||
if( this.value == this.parent.password.value ) {
|
||||
|
||||
this.border = "#28a745";
|
||||
|
||||
this.color = "#495057";
|
||||
|
||||
this.shadow = "0px 0px 4px 2px #28a745";
|
||||
|
||||
} else {
|
||||
|
||||
this.border = "1px solid #dc3545";
|
||||
|
||||
this.color = "black";
|
||||
|
||||
this.shadow = "0px 0px 4px 2px #dc3545";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
14
application/user/signup/signup.username.js
Normal file
14
application/user/signup/signup.username.js
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
import username from '../user.username.js';
|
||||
|
||||
import input from '/elements/input.js';
|
||||
|
||||
export default class signUpUsername extends username, input {
|
||||
|
||||
|
||||
propegateEvent = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
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