mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-22 18:25:47 +08:00
Fix login.
This commit is contained in:
parent
d30c96038d
commit
cdc1445883
@ -2,6 +2,7 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/object"
|
"github.com/casdoor/casdoor/object"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
@ -92,16 +93,17 @@ func (c *ApiController) Login() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
user, password := form.Username, form.Password
|
userId := fmt.Sprintf("%s/%s", form.Organization, form.Username)
|
||||||
msg := object.CheckUserLogin(user, password)
|
password := form.Password
|
||||||
|
msg := object.CheckUserLogin(userId, password)
|
||||||
|
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
resp = Response{Status: "error", Msg: msg, Data: ""}
|
resp = Response{Status: "error", Msg: msg, Data: ""}
|
||||||
} else {
|
} else {
|
||||||
c.SetSessionUser(user)
|
c.SetSessionUser(userId)
|
||||||
|
|
||||||
util.LogInfo(c.Ctx, "API: [%s] logged in", user)
|
util.LogInfo(c.Ctx, "API: [%s] logged in", userId)
|
||||||
resp = Response{Status: "ok", Msg: "", Data: user}
|
resp = Response{Status: "ok", Msg: "", Data: userId}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Data["json"] = resp
|
c.Data["json"] = resp
|
||||||
|
@ -20,6 +20,11 @@ import (
|
|||||||
"github.com/casdoor/casdoor/object"
|
"github.com/casdoor/casdoor/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (c *ApiController) GetGlobalUsers() {
|
||||||
|
c.Data["json"] = object.GetGlobalUsers()
|
||||||
|
c.ServeJSON()
|
||||||
|
}
|
||||||
|
|
||||||
func (c *ApiController) GetUsers() {
|
func (c *ApiController) GetUsers() {
|
||||||
owner := c.Input().Get("owner")
|
owner := c.Input().Get("owner")
|
||||||
|
|
||||||
|
@ -31,6 +31,16 @@ type User struct {
|
|||||||
Phone string `xorm:"varchar(100)" json:"phone"`
|
Phone string `xorm:"varchar(100)" json:"phone"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetGlobalUsers() []*User {
|
||||||
|
users := []*User{}
|
||||||
|
err := adapter.engine.Desc("created_time").Find(&users)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return users
|
||||||
|
}
|
||||||
|
|
||||||
func GetUsers(owner string) []*User {
|
func GetUsers(owner string) []*User {
|
||||||
users := []*User{}
|
users := []*User{}
|
||||||
err := adapter.engine.Desc("created_time").Find(&users, &User{Owner: owner})
|
err := adapter.engine.Desc("created_time").Find(&users, &User{Owner: owner})
|
||||||
|
@ -44,6 +44,7 @@ func initAPI() {
|
|||||||
beego.Router("/api/add-organization", &controllers.ApiController{}, "POST:AddOrganization")
|
beego.Router("/api/add-organization", &controllers.ApiController{}, "POST:AddOrganization")
|
||||||
beego.Router("/api/delete-organization", &controllers.ApiController{}, "POST:DeleteOrganization")
|
beego.Router("/api/delete-organization", &controllers.ApiController{}, "POST:DeleteOrganization")
|
||||||
|
|
||||||
|
beego.Router("/api/get-global-users", &controllers.ApiController{}, "GET:GetGlobalUsers")
|
||||||
beego.Router("/api/get-users", &controllers.ApiController{}, "GET:GetUsers")
|
beego.Router("/api/get-users", &controllers.ApiController{}, "GET:GetUsers")
|
||||||
beego.Router("/api/get-user", &controllers.ApiController{}, "GET:GetUser")
|
beego.Router("/api/get-user", &controllers.ApiController{}, "GET:GetUser")
|
||||||
beego.Router("/api/update-user", &controllers.ApiController{}, "POST:UpdateUser")
|
beego.Router("/api/update-user", &controllers.ApiController{}, "POST:UpdateUser")
|
||||||
|
@ -66,7 +66,7 @@ class App extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onLogined() {
|
onLoggedIn() {
|
||||||
this.getAccount();
|
this.getAccount();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +226,7 @@ class App extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderLoginIfNotLogined(component) {
|
renderLoginIfNotLoggedIn(component) {
|
||||||
if (this.state.account === null) {
|
if (this.state.account === null) {
|
||||||
return <Redirect to='/login' />
|
return <Redirect to='/login' />
|
||||||
} else if (this.state.account === undefined) {
|
} else if (this.state.account === undefined) {
|
||||||
@ -265,14 +265,14 @@ class App extends Component {
|
|||||||
</Menu>
|
</Menu>
|
||||||
</Header>
|
</Header>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route exact path="/organizations" component={OrganizationListPage}/>
|
<Route exact path="/organizations" render={(props) => this.renderLoginIfNotLoggedIn(<OrganizationListPage account={this.state.account} {...props} />)}/>
|
||||||
<Route exact path="/organizations/:organizationName" component={OrganizationEditPage}/>
|
<Route exact path="/organizations/:organizationName" render={(props) => this.renderLoginIfNotLoggedIn(<OrganizationEditPage account={this.state.account} {...props} />)}/>
|
||||||
<Route exact path="/users" component={UserListPage}/>
|
<Route exact path="/users" render={(props) => this.renderLoginIfNotLoggedIn(<UserListPage account={this.state.account} {...props} />)}/>
|
||||||
<Route exact path="/users/:userName" component={UserEditPage}/>
|
<Route exact path="/users/:organizationName/:userName" render={(props) => this.renderLoginIfNotLoggedIn(<UserEditPage account={this.state.account} {...props} />)}/>
|
||||||
<Route exact path="/providers" component={ProviderListPage}/>
|
<Route exact path="/providers" render={(props) => this.renderLoginIfNotLoggedIn(<ProviderListPage account={this.state.account} {...props} />)}/>
|
||||||
<Route exact path="/providers/:providerName" component={ProviderEditPage}/>
|
<Route exact path="/providers/:providerName" render={(props) => this.renderLoginIfNotLoggedIn(<ProviderEditPage account={this.state.account} {...props} />)}/>
|
||||||
<Route exact path="/applications" component={ApplicationListPage}/>
|
<Route exact path="/applications" render={(props) => this.renderLoginIfNotLoggedIn(<ApplicationListPage account={this.state.account} {...props} />)}/>
|
||||||
<Route exact path="/applications/:applicationName" component={ApplicationEditPage}/>
|
<Route exact path="/applications/:applicationName" render={(props) => this.renderLoginIfNotLoggedIn(<ApplicationEditPage account={this.state.account} {...props} />)}/>
|
||||||
</Switch>
|
</Switch>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -40,7 +40,7 @@ class Face extends React.Component {
|
|||||||
AccountBackend.login(values)
|
AccountBackend.login(values)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.status === 'ok') {
|
if (res.status === 'ok') {
|
||||||
this.props.onLogined();
|
this.props.onLoggedIn();
|
||||||
Setting.showMessage("success", `Logged in successfully`);
|
Setting.showMessage("success", `Logged in successfully`);
|
||||||
Setting.goToLink("/");
|
Setting.goToLink("/");
|
||||||
} else {
|
} else {
|
||||||
@ -53,7 +53,10 @@ class Face extends React.Component {
|
|||||||
return (
|
return (
|
||||||
<Form
|
<Form
|
||||||
name="normal_login"
|
name="normal_login"
|
||||||
initialValues={{ remember: true }}
|
initialValues={{
|
||||||
|
organization: this.getApplicationObj().organization,
|
||||||
|
remember: true
|
||||||
|
}}
|
||||||
onFinish={this.onFinish.bind(this)}
|
onFinish={this.onFinish.bind(this)}
|
||||||
style={{width: "250px"}}
|
style={{width: "250px"}}
|
||||||
size="large"
|
size="large"
|
||||||
@ -104,12 +107,15 @@ class Face extends React.Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const application = this.getApplicationObj();
|
const application = this.getApplicationObj();
|
||||||
|
if (application === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Row>
|
<Row>
|
||||||
<Col span={24} style={{display: "flex", justifyContent: "center"}} >
|
<Col span={24} style={{display: "flex", justifyContent: "center"}} >
|
||||||
<div style={{marginTop: "80px", textAlign: "center"}}>
|
<div style={{marginTop: "80px", textAlign: "center"}}>
|
||||||
<img src={application?.logo} alt={application?.displayName} style={{marginBottom: '50px'}}/>
|
<img src={application.logo} alt={application.displayName} style={{marginBottom: '50px'}}/>
|
||||||
{
|
{
|
||||||
this.renderForm(application)
|
this.renderForm(application)
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,30 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import {Button, Card, Col, Input, Row} from 'antd';
|
import {Button, Card, Col, Input, Row, Select} from 'antd';
|
||||||
import {LinkOutlined} from "@ant-design/icons";
|
|
||||||
import * as UserBackend from "./backend/UserBackend";
|
import * as UserBackend from "./backend/UserBackend";
|
||||||
|
import * as OrganizationBackend from "./backend/OrganizationBackend";
|
||||||
import * as Setting from "./Setting";
|
import * as Setting from "./Setting";
|
||||||
|
|
||||||
|
const { Option } = Select;
|
||||||
|
|
||||||
class UserEditPage extends React.Component {
|
class UserEditPage extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
classes: props,
|
classes: props,
|
||||||
|
organizationName: props.match.params.organizationName,
|
||||||
userName: props.match.params.userName,
|
userName: props.match.params.userName,
|
||||||
user: null,
|
user: null,
|
||||||
|
organizations: [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
this.getUser();
|
this.getUser();
|
||||||
|
this.getOrganizations();
|
||||||
}
|
}
|
||||||
|
|
||||||
getUser() {
|
getUser() {
|
||||||
UserBackend.getUser("admin", this.state.userName)
|
UserBackend.getUser(this.state.organizationName, this.state.userName)
|
||||||
.then((user) => {
|
.then((user) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
user: user,
|
user: user,
|
||||||
@ -27,6 +32,15 @@ class UserEditPage extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getOrganizations() {
|
||||||
|
OrganizationBackend.getOrganizations("admin")
|
||||||
|
.then((res) => {
|
||||||
|
this.setState({
|
||||||
|
organizations: res,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
parseUserField(key, value) {
|
parseUserField(key, value) {
|
||||||
// if ([].includes(key)) {
|
// if ([].includes(key)) {
|
||||||
// value = Setting.myParseInt(value);
|
// value = Setting.myParseInt(value);
|
||||||
@ -53,6 +67,18 @@ class UserEditPage extends React.Component {
|
|||||||
</div>
|
</div>
|
||||||
} style={{marginLeft: '5px'}} type="inner">
|
} style={{marginLeft: '5px'}} type="inner">
|
||||||
<Row style={{marginTop: '10px'}} >
|
<Row style={{marginTop: '10px'}} >
|
||||||
|
<Col style={{marginTop: '5px'}} span={2}>
|
||||||
|
Organization:
|
||||||
|
</Col>
|
||||||
|
<Col span={22} >
|
||||||
|
<Select virtual={false} style={{width: '100%'}} value={this.state.user.owner} onChange={(value => {this.updateUserField('owner', value);})}>
|
||||||
|
{
|
||||||
|
this.state.organizations.map((organization, index) => <Option key={index} value={organization.name}>{organization.name}</Option>)
|
||||||
|
}
|
||||||
|
</Select>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
<Row style={{marginTop: '20px'}} >
|
||||||
<Col style={{marginTop: '5px'}} span={2}>
|
<Col style={{marginTop: '5px'}} span={2}>
|
||||||
Name:
|
Name:
|
||||||
</Col>
|
</Col>
|
||||||
@ -118,16 +144,18 @@ class UserEditPage extends React.Component {
|
|||||||
|
|
||||||
submitUserEdit() {
|
submitUserEdit() {
|
||||||
let user = Setting.deepCopy(this.state.user);
|
let user = Setting.deepCopy(this.state.user);
|
||||||
UserBackend.updateUser(this.state.user.owner, this.state.userName, user)
|
UserBackend.updateUser(this.state.organizationName, this.state.userName, user)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res) {
|
if (res) {
|
||||||
Setting.showMessage("success", `Successfully saved`);
|
Setting.showMessage("success", `Successfully saved`);
|
||||||
this.setState({
|
this.setState({
|
||||||
|
organizationName: this.state.user.owner,
|
||||||
userName: this.state.user.name,
|
userName: this.state.user.name,
|
||||||
});
|
});
|
||||||
this.props.history.push(`/users/${this.state.user.name}`);
|
this.props.history.push(`/users/${this.state.user.owner}/${this.state.user.name}`);
|
||||||
} else {
|
} else {
|
||||||
Setting.showMessage("error", `failed to save: server side failure`);
|
Setting.showMessage("error", `failed to save: server side failure`);
|
||||||
|
this.updateUserField('owner', this.state.organizationName);
|
||||||
this.updateUserField('name', this.state.userName);
|
this.updateUserField('name', this.state.userName);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -19,7 +19,7 @@ class UserListPage extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getUsers() {
|
getUsers() {
|
||||||
UserBackend.getUsers("admin")
|
UserBackend.getGlobalUsers()
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
users: res,
|
users: res,
|
||||||
@ -71,6 +71,20 @@ class UserListPage extends React.Component {
|
|||||||
|
|
||||||
renderTable(users) {
|
renderTable(users) {
|
||||||
const columns = [
|
const columns = [
|
||||||
|
{
|
||||||
|
title: 'Organization',
|
||||||
|
dataIndex: 'owner',
|
||||||
|
key: 'owner',
|
||||||
|
width: '120px',
|
||||||
|
sorter: (a, b) => a.owner.localeCompare(b.owner),
|
||||||
|
render: (text, record, index) => {
|
||||||
|
return (
|
||||||
|
<a href={`/organizations/${text}`}>
|
||||||
|
{text}
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: 'Name',
|
title: 'Name',
|
||||||
dataIndex: 'name',
|
dataIndex: 'name',
|
||||||
@ -79,7 +93,7 @@ class UserListPage extends React.Component {
|
|||||||
sorter: (a, b) => a.name.localeCompare(b.name),
|
sorter: (a, b) => a.name.localeCompare(b.name),
|
||||||
render: (text, record, index) => {
|
render: (text, record, index) => {
|
||||||
return (
|
return (
|
||||||
<Link to={`/users/${text}`}>
|
<Link to={`/users/${record.owner}/${text}`}>
|
||||||
{text}
|
{text}
|
||||||
</Link>
|
</Link>
|
||||||
)
|
)
|
||||||
@ -138,7 +152,7 @@ class UserListPage extends React.Component {
|
|||||||
render: (text, record, index) => {
|
render: (text, record, index) => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Button style={{marginTop: '10px', marginBottom: '10px', marginRight: '10px'}} type="primary" onClick={() => this.props.history.push(`/users/${record.name}`)}>Edit</Button>
|
<Button style={{marginTop: '10px', marginBottom: '10px', marginRight: '10px'}} type="primary" onClick={() => this.props.history.push(`/users/${record.owner}/${record.name}`)}>Edit</Button>
|
||||||
<Popconfirm
|
<Popconfirm
|
||||||
title={`Sure to delete user: ${record.name} ?`}
|
title={`Sure to delete user: ${record.name} ?`}
|
||||||
onConfirm={() => this.deleteUser(index)}
|
onConfirm={() => this.deleteUser(index)}
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
import * as Setting from "../Setting";
|
import * as Setting from "../Setting";
|
||||||
|
|
||||||
|
export function getGlobalUsers() {
|
||||||
|
return fetch(`${Setting.ServerUrl}/api/get-global-users`, {
|
||||||
|
method: "GET",
|
||||||
|
credentials: "include"
|
||||||
|
}).then(res => res.json());
|
||||||
|
}
|
||||||
|
|
||||||
export function getUsers(owner) {
|
export function getUsers(owner) {
|
||||||
return fetch(`${Setting.ServerUrl}/api/get-users?owner=${owner}`, {
|
return fetch(`${Setting.ServerUrl}/api/get-users?owner=${owner}`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user