You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
GHHub/src/stores/Auth.js

83 lines
2.4 KiB
JavaScript

import { makeAutoObservable, runInAction } from "mobx";
import { fetchJSON, postForm } from '@/utils/request';
import { HT_HOST } from "@/config";
import { prepareUrl } from '@/utils/commons';
class Auth {
constructor(root) {
makeAutoObservable(this, { rootStore: false });
this.root = root;
}
valdateUserPassword(usr, pwd) {
const formData = new FormData();
formData.append('username', usr);
formData.append('Password', pwd);
const postUrl = HT_HOST + '/service-CooperateSOA/Login';
return postForm(postUrl, formData)
.then(json => {
if (json.errcode == 0) {
return json.Result.WU_LMI_SN;
} else {
throw new Error(json.errmsg + ': ' + json.errcode);
}
});
}
fetchUserDetail(userId) {
const fetchUrl = prepareUrl(HT_HOST + '/service-CooperateSOA/GetLinkManInfo')
.append('LMI_SN', userId)
.build();
return fetchJSON(fetchUrl)
.then(json => {
if (json.errcode == 0) {
runInAction(() => {
this.login = {
userId: json.Result.LMI_SN,
username: json.Result.LoginName,
travelAgencyId: json.Result.LMI_VEI_SN,
travelAgencyName: json.Result.VName,
telephone: json.Result.LkPhone,
emailAddress: json.Result.LMI_listmail,
cityId: json.Result.citysn
}
});
return json.Result.LoginName;
} else {
throw new Error(json.errmsg + ': ' + json.errcode);
}
});
}
changeUserPassword(password, newPassword) {
const formData = new FormData();
formData.append('UserID', this.login.userId);
formData.append('Password', password);
formData.append('NewPassword', newPassword);
const postUrl = HT_HOST + '/service-CooperateSOA/SetPassword';
return postForm(postUrl, formData)
.then(json => {
if (json.errcode == 0) {
return json;
} else {
throw new Error(json.errmsg + ': ' + json.errcode);
}
});
}
login = {
userId: 1,
username: 'Vu Xuan Giang',
travelAgencyId: 32531, //30008供应商id对应HT的VEI_SN
travelAgencyName: 'ANP',
telephone: '000',
emailAddress: 'abc@123.com',
cityId: 0
}
}
export default Auth;