You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.1 KiB
91 lines
2.1 KiB
import {
|
|
changeEmailApi,
|
|
changePwdApi,
|
|
checkAdminApi,
|
|
loginApi,
|
|
sendCodeApi,
|
|
telegramBotApi,
|
|
testTelegramBotApi
|
|
} from "./interface";
|
|
// @ts-ignore
|
|
import {Message} from 'element3/src/components/Message'
|
|
|
|
/**
|
|
* 发送验证码
|
|
* @param userEmail
|
|
*/
|
|
export function sendCode(userEmail: string) {
|
|
return fetch(new Request(sendCodeApi, {method: 'POST', body: JSON.stringify({userEmail})}))
|
|
}
|
|
|
|
/**
|
|
* 更换邮箱
|
|
* @param oldEmail
|
|
* @param newEmail
|
|
* @param code
|
|
*/
|
|
export function changeEmail(oldEmail: string, newEmail: string, code: string) {
|
|
return fetch(new Request(changeEmailApi, {method: 'POST', body: JSON.stringify({oldEmail, newEmail, code})}))
|
|
}
|
|
|
|
/**
|
|
* 更换密码
|
|
* @param userEmail
|
|
* @param password
|
|
*/
|
|
export function changePwd(userEmail: string, password: string) {
|
|
return fetch(new Request(changePwdApi, {method: 'POST', body: JSON.stringify({userEmail, password})}))
|
|
}
|
|
|
|
/**
|
|
* 获取telegram bot
|
|
* @param userEmail
|
|
*/
|
|
export function getTelegramBot(userEmail: string) {
|
|
return fetch(new Request(`${telegramBotApi}?userEmail=${userEmail}`))
|
|
}
|
|
|
|
/**
|
|
* 测试telegram bot token
|
|
* @param token
|
|
*/
|
|
export function testTelegramBot(token: string) {
|
|
return fetch(new Request(testTelegramBotApi(token)))
|
|
}
|
|
|
|
/**
|
|
* 绑定telegram bot
|
|
* @param userEmail
|
|
* @param token
|
|
*/
|
|
export function bindTelegramBot(userEmail: string, token: string) {
|
|
return fetch(new Request(telegramBotApi), {method: 'POST', body: JSON.stringify({userEmail, token})})
|
|
}
|
|
|
|
/**
|
|
* 检查是否存在管理员
|
|
*/
|
|
export function checkAdmin() {
|
|
return fetch(new Request(checkAdminApi), {method: 'GET'})
|
|
}
|
|
|
|
export function login(userEmail: string, password: string) {
|
|
return fetch(new Request(loginApi), {method: 'POST', body: JSON.stringify({userEmail, password})})
|
|
}
|
|
|
|
export type Result = 'OK' | 'FAIL'
|
|
|
|
export interface JSONResponse {
|
|
result: Result,
|
|
body?: any,
|
|
message?: string
|
|
}
|
|
|
|
export function message(res: JSONResponse) {
|
|
new Message({
|
|
showClose: true,
|
|
duration: 3000,
|
|
message: res.message,
|
|
type: res.result === 'OK' ? 'success' : 'error'
|
|
})
|
|
} |