lepisi-pengumuman/assets/js/models/user.js

53 lines
1.4 KiB
JavaScript

let m = require('mithril')
var user = {
current: {},
login: function() {
return m.request({
method: 'POST',
url: '/login',
data: user.current,
withCredentials: true,
headers: {client: 'api'}
})
.then(function(response) {
if (response.status == true) {
window.location = response.redirect_to
}
window.message = response.message
})
},
logout: function() {
return m.request({
method: 'GET',
url: '/logout',
withCredentials: true,
headers: {client: 'api', 'x-query': window.location.search}
})
.then(function(response) {
if (response.status) {
window.location = response.redirect_to
}
window.message = response.message
})
},
register: function() {
return m.request({
method: 'POST',
url: '/post/' + window.location.search,
data: user.current,
withCredentials: true,
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
})
}
}
module.exports = user