diff --git a/mpwo_api/mpwo_api/users/auth.py b/mpwo_api/mpwo_api/users/auth.py
index d7f1df1f..68104210 100644
--- a/mpwo_api/mpwo_api/users/auth.py
+++ b/mpwo_api/mpwo_api/users/auth.py
@@ -1,5 +1,5 @@
import datetime
-from flask import Blueprint, jsonify, request
+from flask import Blueprint, current_app, jsonify, request
from sqlalchemy import exc, or_
from mpwo_api import appLog, bcrypt, db
@@ -182,6 +182,21 @@ def edit_user(user_id):
bio = post_data.get('bio')
birth_date = post_data.get('birth_date')
location = post_data.get('location')
+ password = post_data.get('password')
+ password_conf = post_data.get('password_conf')
+
+ if password is not None and password != '':
+ if password_conf != password:
+ response_object = {
+ 'status': 'error',
+ 'message': 'Password and password confirmation don\'t match.\n'
+ }
+ return jsonify(response_object), 400
+ else:
+ password = bcrypt.generate_password_hash(
+ password, current_app.config.get('BCRYPT_LOG_ROUNDS')
+ ).decode()
+
try:
user = User.query.filter_by(id=user_id).first()
user.first_name = first_name
@@ -193,6 +208,8 @@ def edit_user(user_id):
if birth_date
else None
)
+ if password is not None and password != '':
+ user.password = password
db.session.commit()
response_object = {
diff --git a/mpwo_client/src/actions/index.js b/mpwo_client/src/actions/index.js
index d7c21acd..d4fb2445 100644
--- a/mpwo_client/src/actions/index.js
+++ b/mpwo_client/src/actions/index.js
@@ -19,6 +19,14 @@ function ProfileError(message) {
return { type: 'PROFILE_ERROR', message }
}
+function PwdError(message) {
+ return { type: 'PWD_ERROR', message }
+}
+
+function initProfileFormData(user) {
+ return { type: 'INIT_PROFILE_FORM', user }
+}
+
export const handleFormChange = (target, value) => ({
type: 'UPDATE_USER_FORMDATA',
target,
@@ -31,10 +39,6 @@ export const updateProfileFormData = (target, value) => ({
value,
})
-function initProfileFormData(user) {
- return { type: 'INIT_PROFILE_FORM', user }
-}
-
export function getProfile(dispatch) {
return mpwoApi
.getProfile()
@@ -147,7 +151,11 @@ export function handleProfileFormSubmit(event) {
event.preventDefault()
return (dispatch, getState) => {
const state = getState()
- return mpwoApi
+ if (state.formProfile.formProfile.password !==
+ state.formProfile.formProfile.passwordConf) {
+ dispatch(PwdError('Password and password confirmation don\'t match.'))
+ } else {
+ return mpwoApi
.updateProfile(state.formProfile.formProfile)
.then(ret => {
if (ret.status === 'success') {
@@ -160,5 +168,7 @@ export function handleProfileFormSubmit(event) {
.catch(error => {
throw error
})
+ }
+
}
}
diff --git a/mpwo_client/src/components/User/ProfileEdit.jsx b/mpwo_client/src/components/User/ProfileEdit.jsx
index 18c48e7f..78dd96f5 100644
--- a/mpwo_client/src/components/User/ProfileEdit.jsx
+++ b/mpwo_client/src/components/User/ProfileEdit.jsx
@@ -17,6 +17,7 @@ class ProfileEdit extends React.Component {
const { formProfile,
onHandleFormChange,
onHandleProfileFormSubmit,
+ message,
user
} = this.props
return (
@@ -24,6 +25,9 @@ class ProfileEdit extends React.Component {
{message}
+ )}