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 (Hash::compare($args['old_password'], $user['salt'], $args['password'])) {
|
||||
unset($args['old_password']);
|
||||
$args['password'] = $args['new_password'];
|
||||
unset($args['new_password']);
|
||||
$args['password'] = Hash::make($args['password'], $user['salt']);
|
||||
$data = Access::update($args, $args['id']);
|
||||
if ($data) {
|
||||
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
|
||||
echo json_encode([
|
||||
'status' => true,
|
||||
'route_to' => '/user' . '/' . $args['id'],
|
||||
'message' => 'Proses berhasil'
|
||||
]);die();
|
||||
}
|
||||
if (isset($args['old_password'])) {
|
||||
if (Hash::compare($args['old_password'], $user['salt'], $args['password'])) {
|
||||
unset($args['old_password']);
|
||||
$args['password'] = $args['new_password'];
|
||||
unset($args['new_password']);
|
||||
$args['password'] = Hash::make($args['password'], $user['salt']);
|
||||
$data = Access::update($args, $args['id']);
|
||||
} else {
|
||||
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
|
||||
echo json_encode([
|
||||
'status' => false,
|
||||
'route_to' => '/user' . '/' . $args['id'],
|
||||
'message' => 'Proses gagal'
|
||||
]);die();
|
||||
}
|
||||
$response = [
|
||||
'status' => false,
|
||||
'message' => 'Password lama tidak sama'
|
||||
];
|
||||
}
|
||||
} else {
|
||||
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
|
||||
echo json_encode([
|
||||
'status' => false,
|
||||
'route_to' => '/user' . '/' . $args['id'],
|
||||
'message' => 'Password lama tidak sama'
|
||||
]);die();
|
||||
}
|
||||
$data = Access::update($args, $args['id']);
|
||||
}
|
||||
if ($data) {
|
||||
$response = [
|
||||
'status' => true,
|
||||
'message' => 'Proses berhasil'
|
||||
];
|
||||
} else {
|
||||
$response = [
|
||||
'status' => false,
|
||||
'message' => 'Proses gagal'
|
||||
];
|
||||
}
|
||||
} else {
|
||||
if (isset($_SERVER['HTTP_CLIENT']) && $_SERVER['HTTP_CLIENT'] == 'api') {
|
||||
echo json_encode([
|
||||
'status' => false,
|
||||
'route_to' => '/user' . '/' . $args['id'],
|
||||
'message' => 'User tidak ditemukan'
|
||||
]);die();
|
||||
}
|
||||
$response = [
|
||||
'status' => false,
|
||||
'message' => 'User tidak ditemukan'
|
||||
];
|
||||
}
|
||||
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
|
||||
})
|
||||
}),
|
||||
m('input.third#oPwd', {
|
||||
type: 'password',
|
||||
required: 'required',
|
||||
style: userProfile.changePassword ?
|
||||
'display: inline-block;'
|
||||
: 'display: none;',
|
||||
placeholder: 'Password Lama',
|
||||
oninput: m.withAttr('value', function(value) {
|
||||
user.current.old_password = value
|
||||
userProfile.changePassword ? [
|
||||
m('input.third#oPwd', {
|
||||
type: 'password',
|
||||
required: 'required',
|
||||
placeholder: 'Password Lama',
|
||||
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
|
||||
})
|
||||
})
|
||||
}),
|
||||
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
|
||||
})
|
||||
})
|
||||
] : null
|
||||
])
|
||||
]),
|
||||
m('tr', [
|
||||
|
@ -66,25 +66,30 @@ var user = {
|
||||
})
|
||||
},
|
||||
editProfile: function() {
|
||||
if (_.isEqual(user.current.re_new_password, user.current.new_password)) {
|
||||
_.unset(user.current, 're_new_password')
|
||||
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
|
||||
})
|
||||
if (!_.isNil(user.current.old_password) && !_.isNil(user.current.re_new_password)) {
|
||||
if (_.isEqual(user.current.re_new_password, user.current.new_password)) {
|
||||
_.unset(user.current, 're_new_password')
|
||||
} else {
|
||||
window.message = 'Password baru tidak sama'
|
||||
m.redraw()
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
window.message = 'Password baru tidak sama'
|
||||
m.redraw()
|
||||
_.unset(user.current, 'new_password')
|
||||
}
|
||||
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