mirror of
https://github.com/casdoor/casdoor.git
synced 2025-08-09 14:37:58 +08:00

* fix: update webAuthnBufferDecode to support Base64URL for WebAuthn updates * feat: enable verification code when the login password is wrong * fix: only enable captcha when login in password * fix: disable login error limits when captcha on * fix: pass "enableCaptcha" as an optional param * fix: change enbleCapctah to optional bool param
152 lines
4.6 KiB
JavaScript
152 lines
4.6 KiB
JavaScript
// Copyright 2021 The Casdoor Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
import {authConfig} from "./Auth";
|
|
import * as Setting from "../Setting";
|
|
|
|
export function getAccount(query) {
|
|
return fetch(`${authConfig.serverUrl}/api/get-account${query}`, {
|
|
method: "GET",
|
|
credentials: "include",
|
|
headers: {
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
},
|
|
}).then(res => res.json());
|
|
}
|
|
|
|
export function signup(values) {
|
|
return fetch(`${authConfig.serverUrl}/api/signup`, {
|
|
method: "POST",
|
|
credentials: "include",
|
|
body: JSON.stringify(values),
|
|
headers: {
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
},
|
|
}).then(res => res.json());
|
|
}
|
|
|
|
export function getEmailAndPhone(organization, username) {
|
|
return fetch(`${authConfig.serverUrl}/api/get-email-and-phone?organization=${organization}&username=${username}`, {
|
|
method: "GET",
|
|
credentials: "include",
|
|
headers: {
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
},
|
|
}).then((res) => res.json());
|
|
}
|
|
|
|
export function oAuthParamsToQuery(oAuthParams) {
|
|
// login
|
|
if (oAuthParams === null) {
|
|
return "";
|
|
}
|
|
|
|
// code
|
|
return `?clientId=${oAuthParams.clientId}&responseType=${oAuthParams.responseType}&redirectUri=${encodeURIComponent(oAuthParams.redirectUri)}&scope=${oAuthParams.scope}&state=${oAuthParams.state}&nonce=${oAuthParams.nonce}&code_challenge_method=${oAuthParams.challengeMethod}&code_challenge=${oAuthParams.codeChallenge}`;
|
|
}
|
|
|
|
export function getApplicationLogin(oAuthParams) {
|
|
return fetch(`${authConfig.serverUrl}/api/get-app-login${oAuthParamsToQuery(oAuthParams)}`, {
|
|
method: "GET",
|
|
credentials: "include",
|
|
headers: {
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
},
|
|
}).then(res => res.json());
|
|
}
|
|
|
|
export function login(values, oAuthParams) {
|
|
return fetch(`${authConfig.serverUrl}/api/login${oAuthParamsToQuery(oAuthParams)}`, {
|
|
method: "POST",
|
|
credentials: "include",
|
|
body: JSON.stringify(values),
|
|
headers: {
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
},
|
|
}).then(res => res.json());
|
|
}
|
|
|
|
export function loginCas(values, params) {
|
|
return fetch(`${authConfig.serverUrl}/api/login?service=${params.service}`, {
|
|
method: "POST",
|
|
credentials: "include",
|
|
body: JSON.stringify(values),
|
|
headers: {
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
},
|
|
}).then(res => res.json());
|
|
}
|
|
|
|
export function logout() {
|
|
return fetch(`${authConfig.serverUrl}/api/logout`, {
|
|
method: "POST",
|
|
credentials: "include",
|
|
headers: {
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
},
|
|
}).then(res => res.json());
|
|
}
|
|
|
|
export function unlink(values) {
|
|
return fetch(`${authConfig.serverUrl}/api/unlink`, {
|
|
method: "POST",
|
|
credentials: "include",
|
|
body: JSON.stringify(values),
|
|
headers: {
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
},
|
|
}).then(res => res.json());
|
|
}
|
|
|
|
export function getSamlLogin(providerId, relayState) {
|
|
return fetch(`${authConfig.serverUrl}/api/get-saml-login?id=${providerId}&relayState=${relayState}`, {
|
|
method: "GET",
|
|
credentials: "include",
|
|
headers: {
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
},
|
|
}).then(res => res.json());
|
|
}
|
|
|
|
export function loginWithSaml(values, param) {
|
|
return fetch(`${authConfig.serverUrl}/api/login${param}`, {
|
|
method: "POST",
|
|
credentials: "include",
|
|
body: JSON.stringify(values),
|
|
headers: {
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
},
|
|
}).then(res => res.json());
|
|
}
|
|
|
|
export function getWechatMessageEvent() {
|
|
return fetch(`${Setting.ServerUrl}/api/get-webhook-event`, {
|
|
method: "GET",
|
|
credentials: "include",
|
|
headers: {
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
},
|
|
}).then(res => res.json());
|
|
}
|
|
|
|
export function getCaptchaStatus(values) {
|
|
return fetch(`${Setting.ServerUrl}/api/get-captcha-status?organization=${values["organization"]}&user_id=${values["username"]}`, {
|
|
method: "GET",
|
|
credentials: "include",
|
|
headers: {
|
|
"Accept-Language": Setting.getAcceptLanguage(),
|
|
},
|
|
}).then(res => res.json());
|
|
}
|