75 lines
1.6 KiB
JavaScript
Vendored
75 lines
1.6 KiB
JavaScript
Vendored
import m from "mithril"
|
|
|
|
export const User = {
|
|
list: [],
|
|
current: {},
|
|
message: "",
|
|
error: "",
|
|
fetchList: function() {
|
|
m.request({
|
|
method: "GET",
|
|
url: ""
|
|
})
|
|
.then(function(res) {
|
|
User.list = res
|
|
})
|
|
.catch(function(e) {
|
|
User.error = e.message
|
|
})
|
|
},
|
|
fetchCurrent: function() {
|
|
m.request({
|
|
method: "GET",
|
|
url: ""
|
|
})
|
|
.then(function(res) {
|
|
User.current = res
|
|
})
|
|
.catch(function(e) {
|
|
User.error = e.message
|
|
})
|
|
},
|
|
regist: function() {
|
|
m.request({
|
|
method: "POST",
|
|
url: "",
|
|
data: User.current,
|
|
withCredentials: true
|
|
})
|
|
.then(function(res) {
|
|
User.message = res
|
|
})
|
|
.catch(function(e) {
|
|
User.error = e.message
|
|
})
|
|
},
|
|
login: function() {
|
|
m.request({
|
|
method: "GET",
|
|
url: "",
|
|
data: User.current,
|
|
withCredentials: true
|
|
})
|
|
.then(function(res) {
|
|
/* Must set header here*/
|
|
User.message = res
|
|
})
|
|
.catch(function(e) {
|
|
User.error = e.message
|
|
})
|
|
},
|
|
logout: function() {
|
|
m.request({
|
|
method: "GET",
|
|
url: "",
|
|
withCredentials: true
|
|
})
|
|
.then(function(res) {
|
|
User.message = res
|
|
})
|
|
.catch(function(e) {
|
|
User.error = e.message
|
|
})
|
|
}
|
|
}
|