mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
Support cred auto-login.
This commit is contained in:
@ -109,7 +109,17 @@ class App extends Component {
|
||||
getAccessTokenParam() {
|
||||
// "/page?access_token=123"
|
||||
const params = new URLSearchParams(this.props.location.search);
|
||||
return params.get("access_token");
|
||||
const accessToken = params.get("access_token");
|
||||
return accessToken === null ? "" : `?accessToken=${accessToken}`;
|
||||
}
|
||||
|
||||
getCredentialParams() {
|
||||
// "/page?username=abc&password=123"
|
||||
const params = new URLSearchParams(this.props.location.search);
|
||||
if (params.get("username") === null || params.get("password") === null) {
|
||||
return "";
|
||||
}
|
||||
return `?username=${params.get("username")}&password=${params.get("password")}`;
|
||||
}
|
||||
|
||||
getUrlWithoutQuery() {
|
||||
@ -118,18 +128,21 @@ class App extends Component {
|
||||
}
|
||||
|
||||
getAccount() {
|
||||
const accessToken = this.getAccessTokenParam();
|
||||
if (accessToken !== null) {
|
||||
let query = this.getAccessTokenParam();
|
||||
if (query === "") {
|
||||
query = this.getCredentialParams();
|
||||
}
|
||||
if (query !== "") {
|
||||
window.history.replaceState({}, document.title, this.getUrlWithoutQuery());
|
||||
}
|
||||
AuthBackend.getAccount(accessToken)
|
||||
AuthBackend.getAccount(query)
|
||||
.then((res) => {
|
||||
let account = null;
|
||||
if (res.status === "ok") {
|
||||
account = res.data;
|
||||
account.organization = res.data2;
|
||||
} else {
|
||||
if (res.msg === "Invalid JWT token") {
|
||||
if (res.msg !== "Please sign in first") {
|
||||
Setting.showMessage("error", `Failed to sign in: ${res.msg}`);
|
||||
}
|
||||
}
|
||||
|
@ -14,9 +14,8 @@
|
||||
|
||||
import {authConfig} from "./Auth";
|
||||
|
||||
export function getAccount(accessToken) {
|
||||
let param = (accessToken === null) ? "" : `?accessToken=${accessToken}`;
|
||||
return fetch(`${authConfig.serverUrl}/api/get-account${param}`, {
|
||||
export function getAccount(query) {
|
||||
return fetch(`${authConfig.serverUrl}/api/get-account${query}`, {
|
||||
method: 'GET',
|
||||
credentials: 'include'
|
||||
}).then(res => res.json());
|
||||
|
@ -65,7 +65,7 @@ export function deleteUser(user) {
|
||||
|
||||
export function uploadAvatar(avatar) {
|
||||
let account;
|
||||
AuthBackend.getAccount(null).then((res) => {
|
||||
AuthBackend.getAccount("").then((res) => {
|
||||
account = res.data;
|
||||
let formData = new FormData();
|
||||
formData.append("avatarfile", avatar);
|
||||
|
Reference in New Issue
Block a user