200 lines
5.0 KiB
JavaScript
200 lines
5.0 KiB
JavaScript
import axiosInstance from './axiosConfig';
|
|
import { loginSuccess } from '../utils/jwt';
|
|
|
|
|
|
/**
|
|
* 获取验证码
|
|
* @returns {Promise<any>} 返回一个包含验证码信息的Promise对象
|
|
*/
|
|
export const getCaptcha = async () => {
|
|
try {
|
|
const response = await axiosInstance.get('/captcha');
|
|
return response.data;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* 用户登录
|
|
* @param {string} qq - 用户名
|
|
* @param {string} password - 密码
|
|
* @param {string} token - 验证码token
|
|
* @param {string} captcha - 用户输入的验证码
|
|
* @returns {Promise<any>} 返回一个包含登录结果信息的Promise对象
|
|
*/
|
|
export const userLogin = async (qq, password, token, captcha) => {
|
|
try {
|
|
const response = await axiosInstance.post('/user/login', {
|
|
qq,
|
|
password,
|
|
token,
|
|
captcha
|
|
});
|
|
|
|
if (response.data.access_token) {
|
|
loginSuccess(response.data.access_token, qq);
|
|
}
|
|
|
|
return response.data;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* 用户注册
|
|
* @param {string} qq_code - QQ号
|
|
* @param {string} password - 密码
|
|
* @param {string} token - 验证码token
|
|
* @param {string} captcha - 用户输入的验证码
|
|
* @returns {Promise<any>} 返回一个包含注册结果信息的Promise对象
|
|
*/
|
|
export const userRegister = async (qq_code, password, token, captcha) => {
|
|
try {
|
|
const response = await axiosInstance.post('/user/register', {
|
|
qq_code,
|
|
password,
|
|
token,
|
|
captcha
|
|
});
|
|
return response.data;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* 管理员修改用户权限
|
|
* @param {string} uuid - 用户uuid
|
|
* @param {string} privilege - 新权限
|
|
* @returns {Promise<void>} 无返回值,成功即为修改成功
|
|
*/
|
|
export const adminChangeUserPrivilege = async (uuid, privilege) => {
|
|
try {
|
|
await axiosInstance.put('/admin/change_user_privilege', {
|
|
uuid,
|
|
privilege
|
|
});
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 用户申请临时权限
|
|
* 需要登录
|
|
* @param {string} privilege - 申请的权限
|
|
* @returns {Promise<void>} 无返回值,成功即为修改成功
|
|
*/
|
|
export const requestTempPrivilege = async (privilege) => {
|
|
try {
|
|
console.log('申请的权限【requestTempPrivilege】privilege:', privilege);
|
|
|
|
await axiosInstance.post('/user/temp_privilege_request', { privilege });
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 管理员为用户添加临时权限
|
|
* 需要admin权限
|
|
* @param {string} uuid - 用户uuid
|
|
* @param {string} privilege - 权限
|
|
* @param {number} exp_time - 过期时间(分钟)
|
|
* @returns {Promise<void>} 无返回值,成功即为修改成功
|
|
*/
|
|
export const adminAddTempPrivilege = async (uuid, privilege, exp_time) => {
|
|
try {
|
|
const payload = { uuid, privilege };
|
|
if (exp_time !== undefined && exp_time !== null && exp_time !== '') {
|
|
payload.exp_time = exp_time;
|
|
}
|
|
await axiosInstance.post('/admin/add_temp_privilege', payload);
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取用户信息
|
|
* 路由: /user/get
|
|
* 方法: GET
|
|
* 参数: uuid | name | qq_code (优先级: uuid > name > qq_code)
|
|
* @param {Object} params - 查询参数 { uuid, name, qq_code }
|
|
* @returns {Promise<Object>} 用户信息对象
|
|
*/
|
|
export const getUserByInfo = async (params = {}) => {
|
|
try {
|
|
const response = await axiosInstance.get('/user/get', { params });
|
|
return response.data;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 修改用户名
|
|
* 路由: /user/changename
|
|
* 方法: PUT
|
|
* 需要登录
|
|
* @param {string} name - 新用户名
|
|
* @returns {Promise<void>} 无返回值,成功即为修改成功
|
|
*/
|
|
export const changeUserName = async (name) => {
|
|
try {
|
|
await axiosInstance.put('/user/changename', { name });
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 用户请求修改密码(发送重置请求)
|
|
* 路由: /user/resetpassword
|
|
* 方法: POST
|
|
* @param {string} uuid - 要修改的用户的uuid
|
|
* @returns {Promise<void>} 无返回值,成功即为请求成功
|
|
*/
|
|
export const requestResetPassword = async (uuid) => {
|
|
try {
|
|
await axiosInstance.post('/user/resetpassword', null, { params: { uuid } });
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 用户修改密码
|
|
* 路由: /user/resetpassword
|
|
* 方法: PUT
|
|
* 需要登录
|
|
* @param {string} token - 请求token
|
|
* @param {string} password - 新密码
|
|
* @returns {Promise<void>} 无返回值,成功即为修改成功
|
|
*/
|
|
export const resetPassword = async (token, password) => {
|
|
try {
|
|
await axiosInstance.put('/user/resetpassword', { token, password });
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 忘记密码
|
|
* @param {string} qq - QQ号
|
|
* @param {string} new_password - 新密码
|
|
* @param {string} token - 验证码token
|
|
* @param {string} captcha - 用户输入的验证码
|
|
*/
|
|
export const forgetPassword = async (qq, new_password, token, captcha) => {
|
|
try {
|
|
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|