Fixed profile edit page issue
This commit is contained in:
parent
ffaec84ba9
commit
77358a9dac
@ -247,46 +247,42 @@ class Home
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (is_array($user)) {
|
if (is_array($user)) {
|
||||||
if (Hash::compare($args['old_password'], $user['salt'], $args['password'])) {
|
if (isset($args['old_password'])) {
|
||||||
unset($args['old_password']);
|
if (Hash::compare($args['old_password'], $user['salt'], $args['password'])) {
|
||||||
$args['password'] = $args['new_password'];
|
unset($args['old_password']);
|
||||||
unset($args['new_password']);
|
$args['password'] = $args['new_password'];
|
||||||
$args['password'] = Hash::make($args['password'], $user['salt']);
|
unset($args['new_password']);
|
||||||
$data = Access::update($args, $args['id']);
|
$args['password'] = Hash::make($args['password'], $user['salt']);
|
||||||
if ($data) {
|
$data = Access::update($args, $args['id']);
|
||||||
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
|
|
||||||
echo json_encode([
|
|
||||||
'status' => true,
|
|
||||||
'route_to' => '/user' . '/' . $args['id'],
|
|
||||||
'message' => 'Proses berhasil'
|
|
||||||
]);die();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
|
$response = [
|
||||||
echo json_encode([
|
'status' => false,
|
||||||
'status' => false,
|
'message' => 'Password lama tidak sama'
|
||||||
'route_to' => '/user' . '/' . $args['id'],
|
];
|
||||||
'message' => 'Proses gagal'
|
|
||||||
]);die();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
|
$data = Access::update($args, $args['id']);
|
||||||
echo json_encode([
|
}
|
||||||
'status' => false,
|
if ($data) {
|
||||||
'route_to' => '/user' . '/' . $args['id'],
|
$response = [
|
||||||
'message' => 'Password lama tidak sama'
|
'status' => true,
|
||||||
]);die();
|
'message' => 'Proses berhasil'
|
||||||
}
|
];
|
||||||
|
} else {
|
||||||
|
$response = [
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Proses gagal'
|
||||||
|
];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
|
$response = [
|
||||||
echo json_encode([
|
'status' => false,
|
||||||
'status' => false,
|
'message' => 'User tidak ditemukan'
|
||||||
'route_to' => '/user' . '/' . $args['id'],
|
];
|
||||||
'message' => 'User tidak ditemukan'
|
}
|
||||||
]);die();
|
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
|
||||||
}
|
$response['route_to'] = '/user' . '/' . $args['id'];
|
||||||
|
echo json_encode($response);die();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,28 +57,24 @@ var userProfile = {
|
|||||||
user.current.new_password = value
|
user.current.new_password = value
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
m('input.third#oPwd', {
|
userProfile.changePassword ? [
|
||||||
type: 'password',
|
m('input.third#oPwd', {
|
||||||
required: 'required',
|
type: 'password',
|
||||||
style: userProfile.changePassword ?
|
required: 'required',
|
||||||
'display: inline-block;'
|
placeholder: 'Password Lama',
|
||||||
: 'display: none;',
|
oninput: m.withAttr('value', function(value) {
|
||||||
placeholder: 'Password Lama',
|
user.current.old_password = value
|
||||||
oninput: m.withAttr('value', function(value) {
|
})
|
||||||
user.current.old_password = value
|
}),
|
||||||
|
m('input.third#rNPwd', {
|
||||||
|
type: 'password',
|
||||||
|
required: 'required',
|
||||||
|
placeholder: 'Ulang Password Baru',
|
||||||
|
oninput: m.withAttr('value', function(value) {
|
||||||
|
user.current.re_new_password = value
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}),
|
] : null
|
||||||
m('input.third#rNPwd', {
|
|
||||||
type: 'password',
|
|
||||||
required: 'required',
|
|
||||||
style: userProfile.changePassword ?
|
|
||||||
'display: inline-block;'
|
|
||||||
: 'display: none;',
|
|
||||||
placeholder: 'Ulang Password Baru',
|
|
||||||
oninput: m.withAttr('value', function(value) {
|
|
||||||
user.current.re_new_password = value
|
|
||||||
})
|
|
||||||
})
|
|
||||||
])
|
])
|
||||||
]),
|
]),
|
||||||
m('tr', [
|
m('tr', [
|
||||||
|
@ -66,25 +66,30 @@ var user = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
editProfile: function() {
|
editProfile: function() {
|
||||||
if (_.isEqual(user.current.re_new_password, user.current.new_password)) {
|
if (!_.isNil(user.current.old_password) && !_.isNil(user.current.re_new_password)) {
|
||||||
_.unset(user.current, 're_new_password')
|
if (_.isEqual(user.current.re_new_password, user.current.new_password)) {
|
||||||
return m.request({
|
_.unset(user.current, 're_new_password')
|
||||||
method: 'POST',
|
} else {
|
||||||
url: '/edit-profile/' + window.location.search,
|
window.message = 'Password baru tidak sama'
|
||||||
data: user.current,
|
m.redraw()
|
||||||
withCredentials: true,
|
return false
|
||||||
headers: {client: 'api', 'x-query': window.location.search}
|
}
|
||||||
})
|
|
||||||
.then(function(response) {
|
|
||||||
if (response.status == true) {
|
|
||||||
user.logout()
|
|
||||||
}
|
|
||||||
window.message = response.message
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
window.message = 'Password baru tidak sama'
|
_.unset(user.current, 'new_password')
|
||||||
m.redraw()
|
|
||||||
}
|
}
|
||||||
|
return m.request({
|
||||||
|
method: 'POST',
|
||||||
|
url: '/edit-profile/' + window.location.search,
|
||||||
|
data: user.current,
|
||||||
|
withCredentials: true,
|
||||||
|
headers: {client: 'api', 'x-query': window.location.search}
|
||||||
|
})
|
||||||
|
.then(function(response) {
|
||||||
|
if (response.status == true) {
|
||||||
|
user.logout()
|
||||||
|
}
|
||||||
|
window.message = response.message
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user