diff --git a/backend/models/user.js b/backend/models/user.js index ad6965bed280c486fc2144df98ba28d328591f53..c3c8557755cc9418aef9ba6d6f9b2e4a4b9ddb88 100644 --- a/backend/models/user.js +++ b/backend/models/user.js @@ -72,11 +72,6 @@ UserSchema.plugin(uniqueValidator); UserSchema.pre('save', function(next) { let user = this; - /*if (!user.isModified('password')) { - return next(); - } else { - }*/ - bcrypt .genSalt(12) .then((salt) => { diff --git a/backend/routes/auth.js b/backend/routes/auth.js index a4a5a03ce0ef9ab496e83a11269a07004b309022..00c008080d1e570b0e2e70d6e802a6f5891f4e78 100644 --- a/backend/routes/auth.js +++ b/backend/routes/auth.js @@ -6,12 +6,14 @@ const jwt = require('jsonwebtoken'); const secret = process.env.SECRET || 'some other secret as default'; const passport = require('passport'); +// Headers for accepting request from all endpoints router.options('*', async (req, res, next) => { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "X-Requested-With"); next(); }); +// Request for signup router.post('/signup', async (req, res) => { var errors = {}; const user = await User.findOne({username: req.body.username}); @@ -37,6 +39,7 @@ router.post('/signup', async (req, res) => { return res.status(200).json({}); }); +// Request for login router.post('/login', async (req, res) => { const errors = {}; const username = req.body.username @@ -50,8 +53,7 @@ router.post('/login', async (req, res) => { } isMatch = await bcrypt.compare(password, user.password); - //isMatch = password == user.password; - // return 400 if password does not match + if (!isMatch) { errors.message = "Password is incorrect"; return res.status(400).json(errors); @@ -76,6 +78,7 @@ router.post('/login', async (req, res) => { token: `Bearer ${token}` }); }); +// Request for paid adhesion router.post('/pay_adhesion', async (req, res) => { const student_number = req.body.student_number; @@ -101,12 +104,14 @@ router.post('/pay_adhesion', async (req, res) => { } }); +// Request for connected account infos router.get('/me', passport.authenticate('jwt', {session: false}), async function(req, res, next) { const username = req.user.username; const dbUser = await User.findOne({ username }); return res.status(200).json(dbUser); }); +// Request for updating connected account infos router.post('/me/update', passport.authenticate('jwt', {session: false}), async function(req, res, next) { const username = req.user.username; const firstname = req.body.firstname; @@ -157,6 +162,7 @@ router.post('/me/update', passport.authenticate('jwt', {session: false}), async res.status(200).json(); }); +// Request for all created student accounts router.get('/etudiants', async (req, res) => { const users = await User.find(); res.header("Access-Control-Allow-Origin", "*"); diff --git a/frontend/src/actions/Login.actions.js b/frontend/src/actions/Login.actions.js deleted file mode 100644 index 7f2a953122e4206e14a3c3bb8b8cea41252f2aea..0000000000000000000000000000000000000000 --- a/frontend/src/actions/Login.actions.js +++ /dev/null @@ -1,99 +0,0 @@ -import { userService } from "../services/authentication.service"; -import {fetchUserData} from "./Profile.actions"; - -export const getAuth = () => { - return { - type:'GET_AUTH' - } -} - -export const logoutSuccess = () => { - return { - type:'LOGOUT_SUCCESS' - } -} - -export const loginSuccessWaitForPayment = () => { - return { - type:'LOGIN_SUCCESS_WAIT_PAYMENT' - } -} - -export const loginSuccesPaymentDone = () => { - return { - type:'LOGIN_SUCCESS_PAYMENT_DONE' - } -} - -export const loginFailed = (message) => { - return { - type:'LOGIN_FAILED', - message: message - } -} - -export const loginRequest = () => { - return { - type:'LOGIN_REQUEST' - } -} - -export const login = (loginData, ownProps) => { - return async (dispatch) => { - dispatch(loginRequest()); - - const response = await fetch( "/api/login", { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - }, - body: JSON.stringify(loginData), - }) - - if(response.ok){ - response.json().then(data => { - userService.setToken(data.token); - let user = dispatch(fetchUserData()); - //dispatch(user); - 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)); - } else { - userService.setToken(false); - dispatch(loginSuccessWaitForPayment(data)); - } - }).catch(err => dispatch(loginFailed(err))); - } - else{ - response.json().then(error => { - dispatch(loginFailed(error)); - }).catch(err => dispatch(loginFailed(err))); - } - - return response; - } -} - -export const logout = () => { - return (dispatch) => { - userService.logout(); - dispatch(logoutSuccess()); - } -} - -export const reinitializeState = () => { - return { - type:'REINITIALIZE_STATE' - } -} diff --git a/frontend/src/actions/Login.actions.js.BASE b/frontend/src/actions/Login.actions.js.BASE deleted file mode 100644 index 44c4a25ee7fdeaa0f5caade6af2836edb0cf0ca6..0000000000000000000000000000000000000000 --- a/frontend/src/actions/Login.actions.js.BASE +++ /dev/null @@ -1,92 +0,0 @@ -import { userService } from "../services/authentication.service"; -import {fetchUserData} from "./Profile.actions"; - -export const getAuth = () => { - return { - type:'GET_AUTH' - } -} - -export const logoutSuccess = () => { - return { - type:'LOGOUT_SUCCESS' - } -} - -export const loginSuccessWaitForPayment = () => { - return { - type:'LOGIN_SUCCESS_WAIT_PAYMENT' - } -} - -export const loginSuccesPaymentDone = () => { - return { - type:'LOGIN_SUCCESS_PAYMENT_DONE' - } -} - -export const loginFailed = (message) => { - return { - type:'LOGIN_FAILED', - message: message - } -} - -export const loginRequest = () => { - return { - type:'LOGIN_REQUEST' - } -} - -export const login = (loginData, ownProps) => { - return async (dispatch) => { - dispatch(loginRequest()); - - const response = await fetch( "/api/login", { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - }, - body: JSON.stringify(loginData), - }) - - if(response.ok){ - response.json().then(data => { - userService.setToken(data.token); - dispatch(fetchUserData()); - ownProps.history.push('/'); - // TODO: do another request to know if user paid adhesion - var paid=true; - if(paid){ - userService.setAdhesion(true); - dispatch(loginSuccesPaymentDone(data)); - } else { - userService.setToken(false); - dispatch(loginSuccessWaitForPayment(data)); - } - }).catch(err => dispatch(loginFailed(err))); - } - else{ - response.json().then(error => { - dispatch(loginFailed(error)); - }).catch(err => dispatch(loginFailed(err))); - } - - return response; - } -} - -export const logout = () => { - return (dispatch) => { - userService.logout(); - dispatch(logoutSuccess()); - } -} - -export const reinitializeState = () => { - return { - type:'REINITIALIZE_STATE' - } -} - diff --git a/frontend/src/actions/Login.actions.js.LOCAL b/frontend/src/actions/Login.actions.js.LOCAL deleted file mode 100644 index 23ba633a85d2cd2c2926204984ed57059781bca3..0000000000000000000000000000000000000000 --- a/frontend/src/actions/Login.actions.js.LOCAL +++ /dev/null @@ -1,99 +0,0 @@ -import { userService } from "../services/authentication.service"; -import {fetchUserData} from "./Profile.actions"; - -export const getAuth = () => { - return { - type:'GET_AUTH' - } -} - -export const logoutSuccess = () => { - return { - type:'LOGOUT_SUCCESS' - } -} - -export const loginSuccessWaitForPayment = () => { - return { - type:'LOGIN_SUCCESS_WAIT_PAYMENT' - } -} - -export const loginSuccesPaymentDone = () => { - return { - type:'LOGIN_SUCCESS_PAYMENT_DONE' - } -} - -export const loginFailed = (message) => { - return { - type:'LOGIN_FAILED', - message: message - } -} - -export const loginRequest = () => { - return { - type:'LOGIN_REQUEST' - } -} - -export const login = (loginData, ownProps) => { - return async (dispatch) => { - dispatch(loginRequest()); - - const response = await fetch( "/api/login", { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - }, - body: JSON.stringify(loginData), - }) - - if(response.ok){ - response.json().then(data => { - 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)); - } else { - userService.setToken(false); - dispatch(loginSuccessWaitForPayment(data)); - } - }).catch(err => dispatch(loginFailed(err))); - } - else{ - response.json().then(error => { - dispatch(loginFailed(error)); - }).catch(err => dispatch(loginFailed(err))); - } - - return response; - } -} - -export const logout = () => { - return (dispatch) => { - userService.logout(); - dispatch(logoutSuccess()); - } -} - -export const reinitializeState = () => { - return { - type:'REINITIALIZE_STATE' - } -} - diff --git a/frontend/src/actions/Login.actions.js.REMOTE b/frontend/src/actions/Login.actions.js.REMOTE deleted file mode 100644 index 967ae30ba2cfd66ec78a919aa7905df612459c7b..0000000000000000000000000000000000000000 --- a/frontend/src/actions/Login.actions.js.REMOTE +++ /dev/null @@ -1,93 +0,0 @@ -import { userService } from "../services/authentication.service"; -import {fetchUserData} from "./Profile.actions"; - -export const getAuth = () => { - return { - type:'GET_AUTH' - } -} - -export const logoutSuccess = () => { - return { - type:'LOGOUT_SUCCESS' - } -} - -export const loginSuccessWaitForPayment = () => { - return { - type:'LOGIN_SUCCESS_WAIT_PAYMENT' - } -} - -export const loginSuccesPaymentDone = () => { - return { - type:'LOGIN_SUCCESS_PAYMENT_DONE' - } -} - -export const loginFailed = (message) => { - return { - type:'LOGIN_FAILED', - message: message - } -} - -export const loginRequest = () => { - return { - type:'LOGIN_REQUEST' - } -} - -export const login = (loginData, ownProps) => { - return async (dispatch) => { - dispatch(loginRequest()); - - const response = await fetch( "/api/login", { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - }, - body: JSON.stringify(loginData), - }) - - if(response.ok){ - response.json().then(data => { - userService.setToken(data.token); - let user = dispatch(fetchUserData()); - //dispatch(user); - ownProps.history.push('/'); - // TODO: do another request to know if user paid adhesion - console.log(user) - var paid=true; - if(paid){ - userService.setAdhesion(true); - dispatch(loginSuccesPaymentDone(data)); - } else { - userService.setToken(false); - dispatch(loginSuccessWaitForPayment(data)); - } - }).catch(err => dispatch(loginFailed(err))); - } - else{ - response.json().then(error => { - dispatch(loginFailed(error)); - }).catch(err => dispatch(loginFailed(err))); - } - - return response; - } -} - -export const logout = () => { - return (dispatch) => { - userService.logout(); - dispatch(logoutSuccess()); - } -} - -export const reinitializeState = () => { - return { - type:'REINITIALIZE_STATE' - } -} diff --git a/frontend/src/containers/Bank.container.js b/frontend/src/containers/Bank.container.js index 751bb01d63205feaf8aa2c3f2f25f99af5f3ab46..eb01093636511819fdeb41cb5cf85c854c23c5ca 100644 --- a/frontend/src/containers/Bank.container.js +++ b/frontend/src/containers/Bank.container.js @@ -14,18 +14,9 @@ export class Bank extends React.Component { super(props); } - componentDidUpdate(){ - console.log('PROFILE', this.props.profile); - console.log('BANK', this.props.bank); - console.log('PROPS', this.props); - } - componentDidMount(){ this.props.fetchUserData(); this.props.fetchUserTransactions(this.props.profile.me.student_number); - console.log('MOUNT PROFILE', this.props.profile); - console.log('MOUNT BANK', this.props.bank); - console.log('MOUNT PROPS', this.props); } convertDate(formated_Date){