Added profile edit page
This commit is contained in:
@@ -1,7 +1,26 @@
|
||||
let m = require('mithril')
|
||||
let _ = require('lodash')
|
||||
|
||||
var user = {
|
||||
current: {},
|
||||
loading: false,
|
||||
loadCurrent: function(id) {
|
||||
user.loading = true
|
||||
return m.request({
|
||||
method: 'GET',
|
||||
url: '/api/users/' + id,
|
||||
withCredentials: true
|
||||
})
|
||||
.then(function(result) {
|
||||
if (result.status == true) {
|
||||
user.current = result.data
|
||||
user.current.new_password = user.current.password
|
||||
} else {
|
||||
window.message = result.message
|
||||
}
|
||||
user.loading = false
|
||||
})
|
||||
},
|
||||
login: function() {
|
||||
return m.request({
|
||||
method: 'POST',
|
||||
@@ -40,12 +59,32 @@ var user = {
|
||||
headers: {client: 'api', 'x-query': window.location.search}
|
||||
})
|
||||
.then(function(response) {
|
||||
console.log(response);
|
||||
if (response.status == true) {
|
||||
m.route.set(response.route_to)
|
||||
}
|
||||
window.message = response.message
|
||||
})
|
||||
},
|
||||
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
|
||||
})
|
||||
} else {
|
||||
window.message = 'Password baru tidak sama'
|
||||
m.redraw()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user