mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-04 05:10:19 +08:00
Support auto-login.
This commit is contained in:
@ -17,7 +17,7 @@ import './App.less';
|
||||
import * as Setting from "./Setting";
|
||||
import {DownOutlined, LogoutOutlined, SettingOutlined} from '@ant-design/icons';
|
||||
import {Avatar, BackTop, Dropdown, Layout, Menu} from 'antd';
|
||||
import {Switch, Route, withRouter, Redirect, Link} from 'react-router-dom'
|
||||
import {Link, Redirect, Route, Switch, withRouter} from 'react-router-dom'
|
||||
import OrganizationListPage from "./OrganizationListPage";
|
||||
import OrganizationEditPage from "./OrganizationEditPage";
|
||||
import UserListPage from "./UserListPage";
|
||||
@ -105,11 +105,26 @@ class App extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
getAccessTokenParam() {
|
||||
// "/page?access_token=123"
|
||||
const params = new URLSearchParams(this.props.location.search);
|
||||
return params.get("access_token");
|
||||
}
|
||||
|
||||
getUrlWithoutQuery() {
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
return location.toString().replace(location.search, "");
|
||||
}
|
||||
|
||||
getAccount() {
|
||||
AuthBackend.getAccount()
|
||||
const accessToken = this.getAccessTokenParam();
|
||||
if (accessToken !== null) {
|
||||
window.history.replaceState({}, document.title, this.getUrlWithoutQuery());
|
||||
}
|
||||
AuthBackend.getAccount(accessToken)
|
||||
.then((res) => {
|
||||
this.setState({
|
||||
account: res.data,
|
||||
account: res.status === "ok" ? res.data : null,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ export function showMessage(type, text) {
|
||||
}
|
||||
|
||||
export function isAdminUser(account) {
|
||||
if (account === null) {
|
||||
if (account === undefined || account === null) {
|
||||
return false;
|
||||
}
|
||||
return account.owner === "built-in" || account.isGlobalAdmin === true;
|
||||
|
@ -14,8 +14,9 @@
|
||||
|
||||
import {authConfig} from "./Auth";
|
||||
|
||||
export function getAccount() {
|
||||
return fetch(`${authConfig.serverUrl}/api/get-account`, {
|
||||
export function getAccount(accessToken) {
|
||||
let param = (accessToken === null) ? "" : `?accessToken=${accessToken}`;
|
||||
return fetch(`${authConfig.serverUrl}/api/get-account${param}`, {
|
||||
method: 'GET',
|
||||
credentials: 'include'
|
||||
}).then(res => res.json());
|
||||
|
@ -65,7 +65,7 @@ export function deleteUser(user) {
|
||||
|
||||
export function uploadAvatar(avatar) {
|
||||
let account;
|
||||
AuthBackend.getAccount().then((res) => {
|
||||
AuthBackend.getAccount(null).then((res) => {
|
||||
account = Setting.parseJson(res.data);
|
||||
let formData = new FormData();
|
||||
formData.append("avatarfile", avatar);
|
||||
|
Reference in New Issue
Block a user