Backend support for registration validation.

terms and conditions.
Issues #3 #4
This commit is contained in:
Sagi Dayan 2020-02-15 13:07:23 -05:00
parent b75ac5aa97
commit 1f49924963
8 changed files with 30 additions and 3083 deletions

View file

@ -1,17 +1,15 @@
'use strict' 'use strict'
class IndexController { class IndexController {
async index({auth, view}){ async index({auth, view}) {
try{ try {
await auth.check(); await auth.check();
return view.render('home'); return view.render('home');
}catch(e){ } catch (e) {
const bgIndex = Math.ceil((Math.random()*10)%5); const bgIndex = Math.ceil((Math.random() * 10) % 5);
console.log(bgIndex) return view.render('landing', {bgIndex});
return view.render('landing', {bgIndex});
}
} }
}
} }
module.exports = IndexController module.exports = IndexController

View file

@ -1,21 +1,20 @@
'use strict' 'use strict'
class Register { class Register {
get rules () { get rules() {
return { return {
name: 'required|min:1', name: 'required|min:1', email: 'required|email|unique:users',
email: 'required|email|unique:users', password: 'required|string|min:6', terms: 'required|string|min:1',
password: 'required|string|min:6',
// validation rules
} }
} }
get messages() { get messages() {
return { return {
'name.min': 'Must provide a name', 'name.min': 'Must provide a name',
'email.unique': 'This email is already taken', 'email.unique': 'This email is already taken',
'required': 'This is required', 'required': 'This is required',
'email.unique': 'This email is already taken', 'email.unique': 'This email is already taken',
'password.min': 'Password must be at least 6 chars long' 'password.min': 'Password must be at least 6 chars long',
'terms.min': 'Must confirm terms and conditions'
} }
} }
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -17,6 +17,7 @@ document.addEventListener("DOMContentLoaded", () => {
function validateForm(): void { function validateForm(): void {
isFormValid = form.checkValidity() && isPassMatch && terms.checked; isFormValid = form.checkValidity() && isPassMatch && terms.checked;
submit.disabled = !isFormValid; submit.disabled = !isFormValid;
terms.value = terms.checked ? "on" : "";
} }
validateForm(); validateForm();

View file

@ -80,9 +80,10 @@
<div class="field is-grouped"> <div class="field is-grouped">
<div class="control"> <div class="control">
<label class="checkbox"> <label class="checkbox">
<input type="checkbox" id="chk-register-terms"> <input type="checkbox" id="chk-register-terms" name="terms">
I agree to the <a href="#">terms and conditions</a> I agree to the <a href="#">terms and conditions</a>
</label> </label>
<p class="help is-danger">{{ getErrorFor('terms') ? getErrorFor('terms') : '' }}</p>
<div class="control"> <div class="control">
<button id="btn-register-submit" class="button is-link" disabled="true">Submit</button> <button id="btn-register-submit" class="button is-link" disabled="true">Submit</button>
</div> </div>

View file

@ -65,9 +65,10 @@ Seepur| Register
<div class="field"> <div class="field">
<div class="control"> <div class="control">
<label class="checkbox"> <label class="checkbox">
<input type="checkbox" id="chk-register-terms"> <input type="checkbox" id="chk-register-terms" name="terms">
I agree to the <a href="#">terms and conditions</a> I agree to the <a href="#">terms and conditions</a>
</label> </label>
<p class="help is-danger">{{ getErrorFor('terms') ? getErrorFor('terms') : '' }}</p>
</div> </div>
</div> </div>