From 88a2ef129c11cde83f447f49ac1ecfac523b7eaf Mon Sep 17 00:00:00 2001 From: royackerman <62662753+royackerman@users.noreply.github.com> Date: Wed, 8 Jul 2020 12:16:06 +0300 Subject: [PATCH] Frontend: Add Fullname to the Registration and Profile pages (#32) * Add fullname to registration form + validate it + updating it on the profile. * Profile page now supports updating passwords by the user + About Me section. * Support fullname + validation + about me * Support fullname + validation + about me Co-authored-by: Nadav Goldin --- .../src/components/Login/profile.component.js | 13 +++++- .../components/Login/register.component.js | 44 ++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/frontend/zulu/src/components/Login/profile.component.js b/frontend/zulu/src/components/Login/profile.component.js index 09c069e..5b6ebb3 100644 --- a/frontend/zulu/src/components/Login/profile.component.js +++ b/frontend/zulu/src/components/Login/profile.component.js @@ -8,6 +8,10 @@ export default class Profile extends Component { this.state = { currentUser: AuthService.getCurrentUser() }; } + + + + render() { console.log(this.state.currentUser); return ( @@ -19,12 +23,19 @@ export default class Profile extends Component {

Full name:{" "} - {this.state.currentUser.full_name} + {this.state.currentUser.fullname}

Email:{" "} {this.state.currentUser.email}

+ +

+ About Me:{" "} + {this.state.currentUser.fullname} ! What can you tell us about you? +

+ + ); } diff --git a/frontend/zulu/src/components/Login/register.component.js b/frontend/zulu/src/components/Login/register.component.js index 4e64c72..f9dfde8 100644 --- a/frontend/zulu/src/components/Login/register.component.js +++ b/frontend/zulu/src/components/Login/register.component.js @@ -3,6 +3,7 @@ import Form from "react-validation/build/form"; import Input from "react-validation/build/input"; import CheckButton from "react-validation/build/button"; import { isEmail } from "validator"; +import { isAlpha } from "validator"; import AuthService from "../../services/auth.service"; @@ -26,7 +27,19 @@ const email = value => { } }; + const vusername = value => { + if (value.length < 3 || value.length > 20 || !isAlpha(value)) { + return ( +
+ The full name must be between 3 and 20 characters, and only letters are allowed. +
+ ); + } +}; + +// Validator for fullname // +const vfullname = value => { if (value.length < 3 || value.length > 20) { return (
@@ -36,6 +49,8 @@ const vusername = value => { } }; + + const vpassword = value => { if (value.length < 6 || value.length > 40) { return ( @@ -51,6 +66,7 @@ export default class Register extends Component { super(props); this.handleRegister = this.handleRegister.bind(this); this.onChangeUsername = this.onChangeUsername.bind(this); + this.onChangeFullname = this.onChangeFullname.bind(this); this.onChangeEmail = this.onChangeEmail.bind(this); this.onChangePassword = this.onChangePassword.bind(this); @@ -59,6 +75,7 @@ export default class Register extends Component { email: "", password: "", successful: false, + fullName: "", message: "" }; } @@ -69,6 +86,13 @@ export default class Register extends Component { }); } +// onChangeFullname // + onChangeFullname(e) { + this.setState({ + fullName: e.target.value + }); + } + onChangeEmail(e) { this.setState({ email: e.target.value @@ -95,7 +119,8 @@ export default class Register extends Component { AuthService.register( this.state.username, this.state.email, - this.state.password + this.state.password, + this.state.fullName ).then( response => { this.setState({ @@ -151,6 +176,23 @@ export default class Register extends Component { />
+ + +
+ + +
+ + + +