mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
Move passwordType to org.
This commit is contained in:
parent
fffada894c
commit
f442f11568
@ -90,7 +90,6 @@ func (c *ApiController) Signup() {
|
|||||||
Id: util.GenerateId(),
|
Id: util.GenerateId(),
|
||||||
Type: "normal-user",
|
Type: "normal-user",
|
||||||
Password: form.Password,
|
Password: form.Password,
|
||||||
PasswordType: "plain",
|
|
||||||
DisplayName: form.Name,
|
DisplayName: form.Name,
|
||||||
Avatar: "https://casbin.org/img/casbin.svg",
|
Avatar: "https://casbin.org/img/casbin.svg",
|
||||||
Email: form.Email,
|
Email: form.Email,
|
||||||
|
@ -56,20 +56,22 @@ func CheckUserSignup(organization string, username string, password string, disp
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkPassword(user *User, password string) string {
|
func checkPassword(user *User, password string) string {
|
||||||
if user.PasswordType == "plain" {
|
organization := getOrganization("admin", user.Owner)
|
||||||
|
|
||||||
|
if organization.PasswordType == "plain" {
|
||||||
if password == user.Password {
|
if password == user.Password {
|
||||||
return ""
|
return ""
|
||||||
} else {
|
} else {
|
||||||
return "password incorrect"
|
return "password incorrect"
|
||||||
}
|
}
|
||||||
} else if user.PasswordType == "salt" {
|
} else if organization.PasswordType == "salt" {
|
||||||
if getSaltedPassword(password) == user.Password {
|
if getSaltedPassword(password) == user.Password {
|
||||||
return ""
|
return ""
|
||||||
} else {
|
} else {
|
||||||
return "password incorrect"
|
return "password incorrect"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return fmt.Sprintf("unsupported password type: %s", user.PasswordType)
|
return fmt.Sprintf("unsupported password type: %s", organization.PasswordType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,15 +81,15 @@ func CheckUserLogin(organization string, username string, password string) (*Use
|
|||||||
return nil, "the user does not exist, please sign up first"
|
return nil, "the user does not exist, please sign up first"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if user.IsForbidden {
|
||||||
|
return nil, "the user is forbidden to sign in, please contact the administrator"
|
||||||
|
}
|
||||||
|
|
||||||
msg := checkPassword(user, password)
|
msg := checkPassword(user, password)
|
||||||
if msg != "" {
|
if msg != "" {
|
||||||
return nil, msg
|
return nil, msg
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.IsForbidden {
|
|
||||||
return nil, "the user is forbidden to sign in, please contact the administrator"
|
|
||||||
}
|
|
||||||
|
|
||||||
return user, ""
|
return user, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,11 +15,12 @@ func initBuiltInOrganization() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
organization = &Organization{
|
organization = &Organization{
|
||||||
Owner: "admin",
|
Owner: "admin",
|
||||||
Name: "built-in",
|
Name: "built-in",
|
||||||
CreatedTime: util.GetCurrentTime(),
|
CreatedTime: util.GetCurrentTime(),
|
||||||
DisplayName: "Built-in Organization",
|
DisplayName: "Built-in Organization",
|
||||||
WebsiteUrl: "https://example.com",
|
WebsiteUrl: "https://example.com",
|
||||||
|
PasswordType: "plain",
|
||||||
}
|
}
|
||||||
AddOrganization(organization)
|
AddOrganization(organization)
|
||||||
}
|
}
|
||||||
@ -36,7 +37,6 @@ func initBuiltInUser() {
|
|||||||
CreatedTime: util.GetCurrentTime(),
|
CreatedTime: util.GetCurrentTime(),
|
||||||
Id: util.GenerateId(),
|
Id: util.GenerateId(),
|
||||||
Password: "123",
|
Password: "123",
|
||||||
PasswordType: "plain",
|
|
||||||
DisplayName: "Admin",
|
DisplayName: "Admin",
|
||||||
Avatar: "https://casbin.org/img/casbin.svg",
|
Avatar: "https://casbin.org/img/casbin.svg",
|
||||||
Email: "admin@example.com",
|
Email: "admin@example.com",
|
||||||
|
@ -24,9 +24,10 @@ type Organization struct {
|
|||||||
Name string `xorm:"varchar(100) notnull pk" json:"name"`
|
Name string `xorm:"varchar(100) notnull pk" json:"name"`
|
||||||
CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
|
CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
|
||||||
|
|
||||||
DisplayName string `xorm:"varchar(100)" json:"displayName"`
|
DisplayName string `xorm:"varchar(100)" json:"displayName"`
|
||||||
WebsiteUrl string `xorm:"varchar(100)" json:"websiteUrl"`
|
WebsiteUrl string `xorm:"varchar(100)" json:"websiteUrl"`
|
||||||
Favicon string `xorm:"varchar(100)" json:"favicon"`
|
Favicon string `xorm:"varchar(100)" json:"favicon"`
|
||||||
|
PasswordType string `xorm:"varchar(100)" json:"passwordType"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetOrganizations(owner string) []*Organization {
|
func GetOrganizations(owner string) []*Organization {
|
||||||
|
@ -30,7 +30,6 @@ type User struct {
|
|||||||
Id string `xorm:"varchar(100)" json:"id"`
|
Id string `xorm:"varchar(100)" json:"id"`
|
||||||
Type string `xorm:"varchar(100)" json:"type"`
|
Type string `xorm:"varchar(100)" json:"type"`
|
||||||
Password string `xorm:"varchar(100)" json:"password"`
|
Password string `xorm:"varchar(100)" json:"password"`
|
||||||
PasswordType string `xorm:"varchar(100)" json:"passwordType"`
|
|
||||||
DisplayName string `xorm:"varchar(100)" json:"displayName"`
|
DisplayName string `xorm:"varchar(100)" json:"displayName"`
|
||||||
Avatar string `xorm:"varchar(255)" json:"avatar"`
|
Avatar string `xorm:"varchar(255)" json:"avatar"`
|
||||||
Email string `xorm:"varchar(100)" json:"email"`
|
Email string `xorm:"varchar(100)" json:"email"`
|
||||||
|
@ -30,7 +30,6 @@ func createUserFromOriginalUser(originalUser *User) *object.User {
|
|||||||
Id: strconv.Itoa(originalUser.Id),
|
Id: strconv.Itoa(originalUser.Id),
|
||||||
Type: "normal-user",
|
Type: "normal-user",
|
||||||
Password: originalUser.Password,
|
Password: originalUser.Password,
|
||||||
PasswordType: "salt",
|
|
||||||
DisplayName: originalUser.Name,
|
DisplayName: originalUser.Name,
|
||||||
Avatar: fmt.Sprintf("%s%s", avatarBaseUrl, originalUser.Avatar),
|
Avatar: fmt.Sprintf("%s%s", avatarBaseUrl, originalUser.Avatar),
|
||||||
Email: "",
|
Email: "",
|
||||||
|
@ -13,12 +13,14 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
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 * as OrganizationBackend from "./backend/OrganizationBackend";
|
import * as OrganizationBackend from "./backend/OrganizationBackend";
|
||||||
import * as Setting from "./Setting";
|
import * as Setting from "./Setting";
|
||||||
import i18next from "i18next";
|
import i18next from "i18next";
|
||||||
import {LinkOutlined} from "@ant-design/icons";
|
import {LinkOutlined} from "@ant-design/icons";
|
||||||
|
|
||||||
|
const { Option } = Select;
|
||||||
|
|
||||||
class OrganizationEditPage extends React.Component {
|
class OrganizationEditPage extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -124,6 +126,19 @@ class OrganizationEditPage extends React.Component {
|
|||||||
}} />
|
}} />
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
<Row style={{marginTop: '20px'}} >
|
||||||
|
<Col style={{marginTop: '5px'}} span={2}>
|
||||||
|
{i18next.t("general:Password type")}:
|
||||||
|
</Col>
|
||||||
|
<Col span={22} >
|
||||||
|
<Select virtual={false} style={{width: '100%'}} value={this.state.organization.passwordType} onChange={(value => {this.updateOrganizationField('passwordType', value);})}>
|
||||||
|
{
|
||||||
|
['plain', 'salt']
|
||||||
|
.map((item, index) => <Option key={index} value={item}>{item}</Option>)
|
||||||
|
}
|
||||||
|
</Select>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -142,6 +142,13 @@ class OrganizationListPage extends React.Component {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: i18next.t("general:Password type"),
|
||||||
|
dataIndex: 'passwordType',
|
||||||
|
key: 'passwordType',
|
||||||
|
width: '150px',
|
||||||
|
sorter: (a, b) => a.passwordType.localeCompare(b.passwordType),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: i18next.t("general:Action"),
|
title: i18next.t("general:Action"),
|
||||||
dataIndex: '',
|
dataIndex: '',
|
||||||
|
@ -261,19 +261,6 @@ class UserEditPage extends React.Component {
|
|||||||
</Select>
|
</Select>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<Row style={{marginTop: '20px'}} >
|
|
||||||
<Col style={{marginTop: '5px'}} span={2}>
|
|
||||||
{i18next.t("general:Password type")}:
|
|
||||||
</Col>
|
|
||||||
<Col span={22} >
|
|
||||||
<Select virtual={false} style={{width: '100%'}} value={this.state.user.passwordType} onChange={(value => {this.updateUserField('passwordType', value);})}>
|
|
||||||
{
|
|
||||||
['plain']
|
|
||||||
.map((item, index) => <Option key={index} value={item}>{item}</Option>)
|
|
||||||
}
|
|
||||||
</Select>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
<Row style={{marginTop: '20px'}} >
|
<Row style={{marginTop: '20px'}} >
|
||||||
<Col style={{marginTop: '5px'}} span={2}>
|
<Col style={{marginTop: '5px'}} span={2}>
|
||||||
{i18next.t("general:Password")}:
|
{i18next.t("general:Password")}:
|
||||||
|
@ -130,20 +130,6 @@ class UserListPage extends React.Component {
|
|||||||
return Setting.getFormattedDate(text);
|
return Setting.getFormattedDate(text);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// title: 'Password type',
|
|
||||||
// dataIndex: 'passwordType',
|
|
||||||
// key: 'passwordType',
|
|
||||||
// width: '150px',
|
|
||||||
// sorter: (a, b) => a.passwordType.localeCompare(b.passwordType),
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// title: 'Password',
|
|
||||||
// dataIndex: 'password',
|
|
||||||
// key: 'password',
|
|
||||||
// width: '150px',
|
|
||||||
// sorter: (a, b) => a.password.localeCompare(b.password),
|
|
||||||
// },
|
|
||||||
{
|
{
|
||||||
title: i18next.t("general:Display name"),
|
title: i18next.t("general:Display name"),
|
||||||
dataIndex: 'displayName',
|
dataIndex: 'displayName',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user