update user
This commit is contained in:
@@ -84,26 +84,22 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
updateProfile(req, res) {
|
updateProfile(req, res) {
|
||||||
return memberServices
|
const username = req.user.username;
|
||||||
.updateProfile({
|
const { firstname, lastname, phone } = req.body;
|
||||||
name: req.body.name,
|
const data = {
|
||||||
size: req.body.size,
|
firstname: firstname,
|
||||||
price: req.body.price,
|
lastname: lastname,
|
||||||
status: req.body.status
|
phone: phone
|
||||||
}, { returning: true, where: { id: req.params.id } })
|
}
|
||||||
.then(([rowsUpdate, [updatedRow]]) => res.status(200).send(updatedRow))
|
return memberServices.updateProfile(username, data)
|
||||||
|
.then(([rowsUpdate, [updatedRow]]) => res.status(200).send("Update profile successfully"))
|
||||||
.catch(error => res.status(400).send(error));
|
.catch(error => res.status(400).send(error));
|
||||||
},
|
},
|
||||||
|
|
||||||
updatePassword(req, res) {
|
changePassword(req, res) {
|
||||||
return memberServices
|
memberServices
|
||||||
.updatePassword({
|
.updatePassword(req)
|
||||||
name: req.body.name,
|
.then(([rowsUpdate, [updatedRow]]) => res.status(200).send("Update password successfully"))
|
||||||
size: req.body.size,
|
|
||||||
price: req.body.price,
|
|
||||||
status: req.body.status
|
|
||||||
}, { returning: true, where: { id: req.params.id } })
|
|
||||||
.then(([rowsUpdate, [updatedRow]]) => res.status(200).send(updatedRow))
|
|
||||||
.catch(error => res.status(400).send(error));
|
.catch(error => res.status(400).send(error));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
+4
-225
@@ -1,227 +1,6 @@
|
|||||||
const memberController = require("../controllers").member;
|
const member = require("./member");
|
||||||
const auth = require("../middleware/auth");
|
|
||||||
|
|
||||||
module.exports = app => {
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /v1/user/register:
|
|
||||||
* post:
|
|
||||||
* tags:
|
|
||||||
* - Users
|
|
||||||
* summary: Create a JSONPlaceholder user.
|
|
||||||
* requestBody:
|
|
||||||
* required: true
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: object
|
|
||||||
* properties:
|
|
||||||
* username:
|
|
||||||
* type: string
|
|
||||||
* description: The user's username.
|
|
||||||
* example: test@float.sg
|
|
||||||
* email:
|
|
||||||
* type: string
|
|
||||||
* description: The user's email.
|
|
||||||
* example: test@float.sg
|
|
||||||
* password:
|
|
||||||
* type: string
|
|
||||||
* description: The user's password.
|
|
||||||
* example: test@float.sg
|
|
||||||
* firstname:
|
|
||||||
* type: string
|
|
||||||
* description: The user's firstname.
|
|
||||||
* example: Float
|
|
||||||
* lastname:
|
|
||||||
* type: string
|
|
||||||
* description: The user's lastname.
|
|
||||||
* example: Mobility
|
|
||||||
* phone:
|
|
||||||
* type: string
|
|
||||||
* description: The user's phone.
|
|
||||||
* example: 123456789
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: Created
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: object
|
|
||||||
* properties:
|
|
||||||
* message:
|
|
||||||
* type: striing
|
|
||||||
* description: Message
|
|
||||||
* example: Register successfully
|
|
||||||
* 400:
|
|
||||||
* description: Invalid
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: object
|
|
||||||
* properties:
|
|
||||||
* message:
|
|
||||||
* type: striing
|
|
||||||
* description: Message
|
|
||||||
* example: Failed
|
|
||||||
*/
|
|
||||||
app.post("/api/v1/user/register", memberController.validate('register'), memberController.register);
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /v1/user/login:
|
|
||||||
* post:
|
|
||||||
* tags:
|
|
||||||
* - Users
|
|
||||||
* summary: Create a JSONPlaceholder user.
|
|
||||||
* requestBody:
|
|
||||||
* required: true
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: object
|
|
||||||
* properties:
|
|
||||||
* username:
|
|
||||||
* type: string
|
|
||||||
* description: The user's username.
|
|
||||||
* example: test@float.sg
|
|
||||||
* password:
|
|
||||||
* type: string
|
|
||||||
* description: The user's password.
|
|
||||||
* example: test@float.sg
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: Login success
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: object
|
|
||||||
* properties:
|
|
||||||
* accessToken:
|
|
||||||
* type: string
|
|
||||||
* description: Message
|
|
||||||
* example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3RAZmxvYXQuc2ciLCJpYXQiOjE2NDcwODIxNDIsImV4cCI6MTY0NzA4Mzk0Mn0.fMQYB4ielKPh21QcZFwOJSjlGNCAg8rkvEcKWctxdX8
|
|
||||||
* 400:
|
|
||||||
* description: Invalid
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: object
|
|
||||||
* properties:
|
|
||||||
* message:
|
|
||||||
* type: string
|
|
||||||
* description: Message
|
|
||||||
* example: Wrong username or password
|
|
||||||
*/
|
|
||||||
app.post("/api/v1/user/login", memberController.login);
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /v1/user/forgot-password:
|
|
||||||
* post:
|
|
||||||
* tags:
|
|
||||||
* - Users
|
|
||||||
* summary: Create a JSONPlaceholder user.
|
|
||||||
* requestBody:
|
|
||||||
* required: true
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: object
|
|
||||||
* properties:
|
|
||||||
* email:
|
|
||||||
* type: string
|
|
||||||
* description: The user's username.
|
|
||||||
* example: test@float.sg
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: Login success
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: object
|
|
||||||
* properties:
|
|
||||||
* message:
|
|
||||||
* type: string
|
|
||||||
* description: Message
|
|
||||||
* example: Email has been sent
|
|
||||||
* 400:
|
|
||||||
* description: Invalid
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: object
|
|
||||||
* properties:
|
|
||||||
* message:
|
|
||||||
* type: string
|
|
||||||
* description: Message
|
|
||||||
* example: Wrong email
|
|
||||||
*/
|
|
||||||
app.post("/api/v1/user/forgot-password", memberController.forgotPassword);
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /v1/user/reset-password:
|
|
||||||
* post:
|
|
||||||
* tags:
|
|
||||||
* - Users
|
|
||||||
* summary: Create a JSONPlaceholder user.
|
|
||||||
* requestBody:
|
|
||||||
* required: true
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: object
|
|
||||||
* properties:
|
|
||||||
* email:
|
|
||||||
* type: string
|
|
||||||
* description: The user's username.
|
|
||||||
* example: test@float.sg
|
|
||||||
* mode:
|
|
||||||
* type: integer
|
|
||||||
* description: The reset mode (100: start, 200:confirm, 300:complete)
|
|
||||||
* example: 100
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: Login success
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: object
|
|
||||||
* properties:
|
|
||||||
* accessToken:
|
|
||||||
* type: string
|
|
||||||
* description: Message
|
|
||||||
* example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3RAZmxvYXQuc2ciLCJpYXQiOjE2NDcwODIxNDIsImV4cCI6MTY0NzA4Mzk0Mn0.fMQYB4ielKPh21QcZFwOJSjlGNCAg8rkvEcKWctxdX8
|
|
||||||
* 400:
|
|
||||||
* description: Invalid
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: object
|
|
||||||
* properties:
|
|
||||||
* message:
|
|
||||||
* type: string
|
|
||||||
* description: Message
|
|
||||||
* example: Wrong username or password
|
|
||||||
*/
|
|
||||||
app.post("/api/v1/user/reset-password", memberController.resetPassword);
|
|
||||||
/**
|
|
||||||
* @swagger
|
|
||||||
* /v1/user/profile:
|
|
||||||
* get:
|
|
||||||
* tags:
|
|
||||||
* - Users
|
|
||||||
* summary: Retrieve a single JSONPlaceholder user.
|
|
||||||
* description: Retrieve a single JSONPlaceholder user. Can be used to populate a user profile when prototyping or testing an API.
|
|
||||||
* security: # <--- ADD THIS
|
|
||||||
* - bearerAuth: [] # <--- ADD THIS
|
|
||||||
* responses:
|
|
||||||
* 200:
|
|
||||||
* description: A single user.
|
|
||||||
* content:
|
|
||||||
* application/json:
|
|
||||||
* schema:
|
|
||||||
* type: object
|
|
||||||
* $ref: '#/components/schemas/Member'
|
|
||||||
*/
|
|
||||||
|
|
||||||
app.get("/api/v1/user/profile", auth, memberController.profile);
|
|
||||||
|
|
||||||
|
const url = '/api/v1/';
|
||||||
|
module.exports = (app) => {
|
||||||
|
member(app, url)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,323 @@
|
|||||||
|
const memberController = require("../controllers").member;
|
||||||
|
const auth = require("../middleware/auth");
|
||||||
|
|
||||||
|
module.exports = (app, url) => {
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /v1/user/register:
|
||||||
|
* post:
|
||||||
|
* tags:
|
||||||
|
* - Users
|
||||||
|
* summary: Create a JSONPlaceholder user.
|
||||||
|
* requestBody:
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* username:
|
||||||
|
* type: string
|
||||||
|
* description: The user's username.
|
||||||
|
* example: test@float.sg
|
||||||
|
* email:
|
||||||
|
* type: string
|
||||||
|
* description: The user's email.
|
||||||
|
* example: test@float.sg
|
||||||
|
* password:
|
||||||
|
* type: string
|
||||||
|
* description: The user's password.
|
||||||
|
* example: test@float.sg
|
||||||
|
* firstname:
|
||||||
|
* type: string
|
||||||
|
* description: The user's firstname.
|
||||||
|
* example: Float
|
||||||
|
* lastname:
|
||||||
|
* type: string
|
||||||
|
* description: The user's lastname.
|
||||||
|
* example: Mobility
|
||||||
|
* phone:
|
||||||
|
* type: string
|
||||||
|
* description: The user's phone.
|
||||||
|
* example: 123456789
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Created
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* message:
|
||||||
|
* type: striing
|
||||||
|
* description: Message
|
||||||
|
* example: Register successfully
|
||||||
|
* 400:
|
||||||
|
* description: Invalid
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* message:
|
||||||
|
* type: striing
|
||||||
|
* description: Message
|
||||||
|
* example: Failed
|
||||||
|
*/
|
||||||
|
app.post(url + "user/register", memberController.validate('register'), memberController.register);
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /v1/user/login:
|
||||||
|
* post:
|
||||||
|
* tags:
|
||||||
|
* - Users
|
||||||
|
* summary: Create a JSONPlaceholder user.
|
||||||
|
* requestBody:
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* username:
|
||||||
|
* type: string
|
||||||
|
* description: The user's username.
|
||||||
|
* example: test@float.sg
|
||||||
|
* password:
|
||||||
|
* type: string
|
||||||
|
* description: The user's password.
|
||||||
|
* example: test@float.sg
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Login success
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* accessToken:
|
||||||
|
* type: string
|
||||||
|
* description: Message
|
||||||
|
* example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3RAZmxvYXQuc2ciLCJpYXQiOjE2NDcwODIxNDIsImV4cCI6MTY0NzA4Mzk0Mn0.fMQYB4ielKPh21QcZFwOJSjlGNCAg8rkvEcKWctxdX8
|
||||||
|
* 400:
|
||||||
|
* description: Invalid
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* message:
|
||||||
|
* type: string
|
||||||
|
* description: Message
|
||||||
|
* example: Wrong username or password
|
||||||
|
*/
|
||||||
|
app.post(url + "user/login", memberController.login);
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /v1/user/forgot-password:
|
||||||
|
* post:
|
||||||
|
* tags:
|
||||||
|
* - Users
|
||||||
|
* summary: Create a JSONPlaceholder user.
|
||||||
|
* requestBody:
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* email:
|
||||||
|
* type: string
|
||||||
|
* description: The user's username.
|
||||||
|
* example: test@float.sg
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Login success
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* message:
|
||||||
|
* type: string
|
||||||
|
* description: Message
|
||||||
|
* example: Email has been sent
|
||||||
|
* 400:
|
||||||
|
* description: Invalid
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* message:
|
||||||
|
* type: string
|
||||||
|
* description: Message
|
||||||
|
* example: Wrong email
|
||||||
|
*/
|
||||||
|
app.post(url + "user/forgot-password", memberController.forgotPassword);
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /v1/user/reset-password:
|
||||||
|
* post:
|
||||||
|
* tags:
|
||||||
|
* - Users
|
||||||
|
* summary: Create a JSONPlaceholder user.
|
||||||
|
* requestBody:
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* email:
|
||||||
|
* type: string
|
||||||
|
* description: The user's username.
|
||||||
|
* example: test@float.sg
|
||||||
|
* mode:
|
||||||
|
* type: integer
|
||||||
|
* description: The reset mode
|
||||||
|
* example: 100
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Login success
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* accessToken:
|
||||||
|
* type: string
|
||||||
|
* description: Message
|
||||||
|
* example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3RAZmxvYXQuc2ciLCJpYXQiOjE2NDcwODIxNDIsImV4cCI6MTY0NzA4Mzk0Mn0.fMQYB4ielKPh21QcZFwOJSjlGNCAg8rkvEcKWctxdX8
|
||||||
|
* 400:
|
||||||
|
* description: Invalid
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* message:
|
||||||
|
* type: string
|
||||||
|
* description: Message
|
||||||
|
* example: Wrong username or password
|
||||||
|
*/
|
||||||
|
app.post(url + "user/reset-password", memberController.resetPassword);
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /v1/user/profile:
|
||||||
|
* get:
|
||||||
|
* tags:
|
||||||
|
* - Users
|
||||||
|
* summary: Retrieve a single JSONPlaceholder user.
|
||||||
|
* description: Retrieve a single JSONPlaceholder user. Can be used to populate a user profile when prototyping or testing an API.
|
||||||
|
* security:
|
||||||
|
* - bearerAuth: []
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: A single user.
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* $ref: '#/components/schemas/Member'
|
||||||
|
*/
|
||||||
|
|
||||||
|
app.get(url + "user/profile", auth, memberController.profile);
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /v1/user/update:
|
||||||
|
* put:
|
||||||
|
* tags:
|
||||||
|
* - Users
|
||||||
|
* summary: Update User profile
|
||||||
|
* description: update user's profile
|
||||||
|
* security:
|
||||||
|
* - bearerAuth: []
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: A single user.
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* $ref: '#/components/schemas/Member'
|
||||||
|
*/
|
||||||
|
app.put(url + "user/update", auth, memberController.updateProfile);
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /v1/user/change-password:
|
||||||
|
* put:
|
||||||
|
* tags:
|
||||||
|
* - Users
|
||||||
|
* summary: Update User profile
|
||||||
|
* description: update user's profile
|
||||||
|
* security:
|
||||||
|
* - bearerAuth: []
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: Login success
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* message:
|
||||||
|
* type: string
|
||||||
|
* description: Message
|
||||||
|
* example: Email has been sent
|
||||||
|
* 400:
|
||||||
|
* description: Invalid
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* properties:
|
||||||
|
* message:
|
||||||
|
* type: string
|
||||||
|
* description: Message
|
||||||
|
* example: Wrong email
|
||||||
|
*/
|
||||||
|
app.put(url + "user/change-password", auth, memberController.changePassword);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* app.post("tracklocation");
|
||||||
|
* app.post("savecardpayment");
|
||||||
|
* app.post("getcardpaymentlist");
|
||||||
|
* app.post("managepaymentlist");
|
||||||
|
* app.post("verifysession");
|
||||||
|
* app.post("refreshsession");
|
||||||
|
* app.post("linkemail");
|
||||||
|
* app.post("refreshlinkemail");
|
||||||
|
* app.post("usertransportlist");
|
||||||
|
* app.post("usertransportprofile");
|
||||||
|
* app.post("getdashcarddata");
|
||||||
|
* app.post("loadsavedcards");
|
||||||
|
* app.post("loadsavedcards");
|
||||||
|
* app.post("savedashcard");
|
||||||
|
* app.post("saveuserbudget");
|
||||||
|
* app.post("resetpass");
|
||||||
|
* app.post("settingsarray");
|
||||||
|
* app.post("loadsubsription");
|
||||||
|
* app.post("subscriptionstatus");
|
||||||
|
* app.post("getapplist");
|
||||||
|
* app.post("getslidecarddata");
|
||||||
|
* app.post("subscribedcarddata");
|
||||||
|
* app.post("subscribecard");
|
||||||
|
* app.post("savesurvey");
|
||||||
|
* app.post("pointsdetail");
|
||||||
|
* app.post("loadredeemabale");
|
||||||
|
* app.post("redeempoints");
|
||||||
|
* app.post("managefeature");
|
||||||
|
* app.post("carpool");
|
||||||
|
* app.post("logout");
|
||||||
|
* app.post("logout");
|
||||||
|
* app.post("carpoolstatus");
|
||||||
|
* app.post("getsavedtrips");
|
||||||
|
* app.post("savedtrip");
|
||||||
|
* app.post("removesavedtrip");
|
||||||
|
* app.post("trackcardclick");
|
||||||
|
* app.post("membersettings");
|
||||||
|
* app.post("persnoality");
|
||||||
|
*/
|
||||||
|
|
||||||
|
};
|
||||||
@@ -213,6 +213,52 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
updateProfile(username, data) {
|
||||||
|
return Member
|
||||||
|
.update(data,
|
||||||
|
{
|
||||||
|
returning: true,
|
||||||
|
where: {
|
||||||
|
username: username
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.then(([rowsUpdate, [updatedRow]]) => {
|
||||||
|
return updatedRow
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.log(error)
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
async updatePassword(req) {
|
||||||
|
const username = req.user.username;
|
||||||
|
const user = await Member.findOne({
|
||||||
|
where: { username: username},
|
||||||
|
attributes: ['password', 'username']
|
||||||
|
});
|
||||||
|
const cmp = await bcrypt.compare(req.body.oldPassword, user.password);
|
||||||
|
|
||||||
|
console.log(cmp);
|
||||||
|
if (cmp) {
|
||||||
|
const salt = bcrypt.genSaltSync(10);
|
||||||
|
const hashpassword = bcrypt.hashSync(req.body.newPassword, salt);
|
||||||
|
return Member
|
||||||
|
.update(
|
||||||
|
{
|
||||||
|
password: hashpassword
|
||||||
|
},
|
||||||
|
{
|
||||||
|
returning: true,
|
||||||
|
where: {
|
||||||
|
username: username
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return "Wrong password"
|
||||||
|
},
|
||||||
|
|
||||||
async deactivateAccount(req) {
|
async deactivateAccount(req) {
|
||||||
return Member
|
return Member
|
||||||
.destroy({
|
.destroy({
|
||||||
|
|||||||
Reference in New Issue
Block a user