mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 11:20:18 +08:00
fix: check reset phone & email modify rules (#927)
* fix: check reset phone & email modify rules * Update verification.go * Update organization.go Co-authored-by: Yang Luo <hsluoyz@qq.com>
This commit is contained in:
@ -168,13 +168,35 @@ func (c *ApiController) ResetEmailOrPhone() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkDest := dest
|
checkDest := dest
|
||||||
|
org := object.GetOrganizationByUser(user)
|
||||||
if destType == "phone" {
|
if destType == "phone" {
|
||||||
org := object.GetOrganizationByUser(user)
|
phoneItem := object.GetAccountItemByName("Phone", org)
|
||||||
|
if phoneItem == nil {
|
||||||
|
c.ResponseError("Unable to get the phone modify rule.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if pass, errMsg := object.CheckAccountItemModifyRule(phoneItem, user); !pass {
|
||||||
|
c.ResponseError(errMsg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
phonePrefix := "86"
|
phonePrefix := "86"
|
||||||
if org != nil && org.PhonePrefix != "" {
|
if org != nil && org.PhonePrefix != "" {
|
||||||
phonePrefix = org.PhonePrefix
|
phonePrefix = org.PhonePrefix
|
||||||
}
|
}
|
||||||
checkDest = fmt.Sprintf("+%s%s", phonePrefix, dest)
|
checkDest = fmt.Sprintf("+%s%s", phonePrefix, dest)
|
||||||
|
} else if destType == "email" {
|
||||||
|
emailItem := object.GetAccountItemByName("Email", org)
|
||||||
|
if emailItem == nil {
|
||||||
|
c.ResponseError("Unable to get the email modify rule.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if pass, errMsg := object.CheckAccountItemModifyRule(emailItem, user); !pass {
|
||||||
|
c.ResponseError(errMsg)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ret := object.CheckVerificationCode(checkDest, code); len(ret) != 0 {
|
if ret := object.CheckVerificationCode(checkDest, code); len(ret) != 0 {
|
||||||
c.ResponseError(ret)
|
c.ResponseError(ret)
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
package object
|
package object
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/cred"
|
"github.com/casdoor/casdoor/cred"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
"xorm.io/core"
|
"xorm.io/core"
|
||||||
@ -186,3 +188,31 @@ func DeleteOrganization(organization *Organization) bool {
|
|||||||
func GetOrganizationByUser(user *User) *Organization {
|
func GetOrganizationByUser(user *User) *Organization {
|
||||||
return getOrganization("admin", user.Owner)
|
return getOrganization("admin", user.Owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetAccountItemByName(name string, organization *Organization) *AccountItem {
|
||||||
|
if organization == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
for _, accountItem := range organization.AccountItems {
|
||||||
|
if accountItem.Name == name {
|
||||||
|
return accountItem
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func CheckAccountItemModifyRule(accountItem *AccountItem, user *User) (bool, string) {
|
||||||
|
switch accountItem.ModifyRule {
|
||||||
|
case "Admin":
|
||||||
|
if !(user.IsAdmin || user.IsGlobalAdmin) {
|
||||||
|
return false, fmt.Sprintf("Only admin can modify the %s.", accountItem.Name)
|
||||||
|
}
|
||||||
|
case "Immutable":
|
||||||
|
return false, fmt.Sprintf("The %s is immutable.", accountItem.Name)
|
||||||
|
case "Self":
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
return false, fmt.Sprintf("Unknown modify rule %s.", accountItem.ModifyRule)
|
||||||
|
}
|
||||||
|
return true, ""
|
||||||
|
}
|
||||||
|
@ -291,7 +291,7 @@ class UserEditPage extends React.Component {
|
|||||||
}} />
|
}} />
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={11} >
|
<Col span={11} >
|
||||||
{this.state.user.id === this.props.account?.id ? (<ResetModal application={this.state.application} buttonText={i18next.t("user:Reset Email...")} destType={"email"} />) : null}
|
{this.state.user.id === this.props.account?.id ? (<ResetModal application={this.state.application} disabled={disabled} buttonText={i18next.t("user:Reset Email...")} destType={"email"} />) : null}
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
);
|
);
|
||||||
@ -309,7 +309,7 @@ class UserEditPage extends React.Component {
|
|||||||
}} />
|
}} />
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={11} >
|
<Col span={11} >
|
||||||
{this.state.user.id === this.props.account?.id ? (<ResetModal application={this.state.application} buttonText={i18next.t("user:Reset Phone...")} destType={"phone"} />) : null}
|
{this.state.user.id === this.props.account?.id ? (<ResetModal application={this.state.application} disabled={disabled} buttonText={i18next.t("user:Reset Phone...")} destType={"phone"} />) : null}
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user