From 1846a3e9d85a80284e073c3727dd2bd998fc00db Mon Sep 17 00:00:00 2001 From: STEINMETZ THOMAS <thomas.steinmetz2@etu.unistra.fr> Date: Fri, 19 Nov 2021 11:04:52 +0100 Subject: [PATCH] :sparkles: add checkbox --- backend/routes/auth.js | 11 ++++----- frontend/src/containers/SignUp.container.js | 25 +++++++++++++++++---- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/backend/routes/auth.js b/backend/routes/auth.js index 5815c6e..5ad9797 100644 --- a/backend/routes/auth.js +++ b/backend/routes/auth.js @@ -9,15 +9,16 @@ const passport = require('passport'); router.post('/signup', async (req, res) => { var errors = {}; const user = await User.findOne({username: req.body.username}); - + const newUser = new User({ - username: req.body.username, - password: req.body.password, + username: req.body.username, + password: req.body.password, lastname: req.body.lastname, firstname: req.body.firstname, email: req.body.email, date_birth: req.body.date_birth, - student_number: req.body.student_number + student_number: req.body.student_number, + accept_condition: req.accept_condition }); try { @@ -113,7 +114,7 @@ router.post('/me/update', passport.authenticate('jwt', {session: false}), async dbUser.email = email; if (date_birth) dbUser.date_birth = date_birth; - + try { await dbUser.save(); } catch (e) { diff --git a/frontend/src/containers/SignUp.container.js b/frontend/src/containers/SignUp.container.js index 2650648..28cbcca 100644 --- a/frontend/src/containers/SignUp.container.js +++ b/frontend/src/containers/SignUp.container.js @@ -18,6 +18,7 @@ export class SignUp extends React.Component { email: "", student_number: null, date_birth: "", + accept_condition: false }; this.register = this.register.bind(this); } @@ -32,13 +33,21 @@ export class SignUp extends React.Component { } validateForm() { - return this.state.username.length > 0 && this.state.password.length > 0; + return this.state.username.length > 0 && this.state.password.length > 0 && this.state.accept_condition === true; } handleChange = event => { - this.setState({ - [event.target.id]: event.target.value - }); + if(event.target.id === "accept_condition"){ + this.setState({ + [event.target.id]: event.target.checked + }); + } else { + this.setState({ + [event.target.id]: event.target.value + }); + } + + } @@ -113,6 +122,14 @@ export class SignUp extends React.Component { onChange={this.handleChange} /> </Form.Group> + <Form.Group controlId="accept_condition"> + <Form.Check + type="checkbox" + label="En soumettant ce formulaire, j'accepte la politique de confidentialité" + checked={this.state.accept_condition} + onChange={this.handleChange} + /> + </Form.Group> <Button block disabled={!this.validateForm()} -- GitLab