1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-04 08:40:44 +00:00
seahub/frontend/src/utils/user-api.js

52 lines
1.2 KiB
JavaScript
Raw Normal View History

import axios from 'axios';
import cookie from 'react-cookies';
import { siteRoot } from './constants';
class UserAPI {
init({ server, username, password, token }) {
this.server = server;
this.username = username;
this.password = password;
this.token = token;
if (this.token && this.server) {
this.req = axios.create({
baseURL: this.server,
headers: { 'Authorization': 'Token ' + this.token },
});
}
return this;
}
initForSeahubUsage({ siteRoot, xcsrfHeaders }) {
if (siteRoot && siteRoot.charAt(siteRoot.length - 1) === '/') {
var server = siteRoot.substring(0, siteRoot.length - 1);
this.server = server;
} else {
this.server = siteRoot;
}
this.req = axios.create({
headers: {
'X-CSRFToken': xcsrfHeaders,
}
});
return this;
}
resetPassword(oldPassword, newPassword) {
let url = this.server + '/api/v2.1/user/reset-password/';
let data = {
old_password: oldPassword,
new_password: newPassword
};
return this.req.post(url, data);
}
}
let userAPI = new UserAPI();
let xcsrfHeaders = cookie.load('sfcsrftoken');
userAPI.initForSeahubUsage({ siteRoot, xcsrfHeaders });
export { userAPI };