diff --git a/backend/models/user.js b/backend/models/user.js index af22d667544bcc5a144013ff890e9101a3774b3a..4b9987921ded8b955ce20ac400cc97c434f15562 100644 --- a/backend/models/user.js +++ b/backend/models/user.js @@ -42,6 +42,7 @@ const UserSchema = new mongoose.Schema({ }, student_number: { type: Number, + unique: true, required: true, minlength: 8, maxlength: 8, @@ -53,7 +54,6 @@ const UserSchema = new mongoose.Schema({ }, date_subscription: { type: String, - select: false, default: null, }, url_photo: { diff --git a/backend/routes/auth.js b/backend/routes/auth.js index 5ad9797859630d6490c32c231ee84880b350a7fb..a5f4e782ecea3aa76241f4f10a351e6a5f310dcf 100644 --- a/backend/routes/auth.js +++ b/backend/routes/auth.js @@ -70,10 +70,28 @@ router.post('/login', async (req, res) => { token: `Bearer ${token}` }); }); +router.post('/pay_adhesion', async (req, res) => { + const student_number = req.body.student_number; + + if (!student_number) + return res.status(400); + + const dbUser = await User.findOne({student_number: req.body.student_number}); + + if (dbUser){ + dbUser.date_subscription = "" + (new Date()).toISOString().split('T')[0]; + + dbUser.save(); + return res.status(200).json({ success: "Le payement de la adhesion a été prise en compte." }); + } else { + return res.status(400).json({error : e}); + } +}); + router.get('/me', passport.authenticate('jwt', {session: false}), async function(req, res, next) { const username = req.user.username; const dbUser = await User.findOne({ username }); - res.status(200).json(dbUser); + return res.status(200).json(dbUser); }); router.post('/me/update', passport.authenticate('jwt', {session: false}), async function(req, res, next) { diff --git a/frontend/src/App.js b/frontend/src/App.js index 1b71b85a0c2230789834ffc3c0b5b1abb0ce26ca..89532ce2ae722bcb378f9206b62c3c1192c05c10 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -38,9 +38,6 @@ class App extends Component { <Navbar bg="dark" expand="lg" variant="dark"> <Navbar.Brand>STUDENT</Navbar.Brand> <Nav className="mr-auto"> - <Nav.Link as={Link} to="/"> - Utilisateurs - </Nav.Link> {!this.props.loginState.loggedIn && <Nav.Link as={Link} to="/signup/"> S'inscrire @@ -52,8 +49,8 @@ class App extends Component { </Nav.Link> } { this.props.loginState.loggedIn && - <Nav.Link as={Link} to="/profile/"> - Profil + <Nav.Link as={Link} to="/"> + Profile </Nav.Link> } { this.props.loginState.loggedIn && @@ -101,11 +98,10 @@ class App extends Component { </Modal> } - <Route path="/" exact component={Users} /> + <PrivateRoute path="/" exact component={Profile} /> + <Route path="/login" exact component={Login} /> <Route path="/signup/" component={SignUp} /> - <Route path="/login/" component={Login} /> <Route path="/privacy/" component={Privacy} /> - <PrivateRoute path="/profile/" component={Profile} /> <PrivateRoute path="/bank/" component={Bank} /> </div> </Router> diff --git a/frontend/src/actions/Login.actions.js b/frontend/src/actions/Login.actions.js index 44c4a25ee7fdeaa0f5caade6af2836edb0cf0ca6..23ba633a85d2cd2c2926204984ed57059781bca3 100644 --- a/frontend/src/actions/Login.actions.js +++ b/frontend/src/actions/Login.actions.js @@ -56,8 +56,15 @@ export const login = (loginData, ownProps) => { userService.setToken(data.token); dispatch(fetchUserData()); ownProps.history.push('/'); + + // TODO: do another request to know if user paid adhesion + // make request to get user data + + var paid=true; + + if(paid){ userService.setAdhesion(true); dispatch(loginSuccesPaymentDone(data)); diff --git a/frontend/src/containers/Profile.container.js b/frontend/src/containers/Profile.container.js index 9632eba62166c722bdd6055cd9b2f3e6aafe82aa..18bd3691105ca5269c18ff7cdaf04203f50c0a8e 100644 --- a/frontend/src/containers/Profile.container.js +++ b/frontend/src/containers/Profile.container.js @@ -9,6 +9,8 @@ export class Profile extends React.Component { constructor(props) { super(props); + this.props.fetchUserData(); + this.props.reinitializeState(); this.state = { readOnly: true