mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
feat: move User.PhonePrefix to Organization.PhonePrefix
Signed-off-by: Kininaru <shiftregister233@outlook.com>
This commit is contained in:
@ -101,7 +101,6 @@ func (c *ApiController) Signup() {
|
|||||||
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,
|
||||||
PhonePrefix: form.PhonePrefix,
|
|
||||||
Phone: form.Phone,
|
Phone: form.Phone,
|
||||||
Affiliation: form.Affiliation,
|
Affiliation: form.Affiliation,
|
||||||
IsAdmin: false,
|
IsAdmin: false,
|
||||||
|
@ -15,12 +15,24 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/object"
|
"github.com/casdoor/casdoor/object"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *ApiController) SendVerificationCode() {
|
func (c *ApiController) SendVerificationCode() {
|
||||||
|
userId := c.GetSessionUser()
|
||||||
|
if len(userId) == 0 {
|
||||||
|
c.ResponseError("Please sign in first")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
user := object.GetUser(userId)
|
||||||
|
if user == nil {
|
||||||
|
c.ResponseError("No such user.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
destType := c.Ctx.Request.Form.Get("type")
|
destType := c.Ctx.Request.Form.Get("type")
|
||||||
dest := c.Ctx.Request.Form.Get("dest")
|
dest := c.Ctx.Request.Form.Get("dest")
|
||||||
remoteAddr := c.Ctx.Request.RemoteAddr
|
remoteAddr := c.Ctx.Request.RemoteAddr
|
||||||
@ -37,6 +49,12 @@ func (c *ApiController) SendVerificationCode() {
|
|||||||
case "email":
|
case "email":
|
||||||
ret = object.SendVerificationCodeToEmail(remoteAddr, dest)
|
ret = object.SendVerificationCodeToEmail(remoteAddr, dest)
|
||||||
case "phone":
|
case "phone":
|
||||||
|
org := object.GetOrganizationByName(user.Owner)
|
||||||
|
phonePrefix := "86"
|
||||||
|
if org != nil && org.PhonePrefix != "" {
|
||||||
|
phonePrefix = org.PhonePrefix
|
||||||
|
}
|
||||||
|
dest = fmt.Sprintf("+%s%s", phonePrefix, dest)
|
||||||
ret = object.SendVerificationCodeToPhone(remoteAddr, dest)
|
ret = object.SendVerificationCodeToPhone(remoteAddr, dest)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +89,16 @@ func (c *ApiController) ResetEmailOrPhone() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ret := object.CheckVerificationCode(dest, code); len(ret) != 0 {
|
checkDest := dest
|
||||||
|
if destType == "phone" {
|
||||||
|
org := object.GetOrganizationByName(user.Owner)
|
||||||
|
phonePrefix := "86"
|
||||||
|
if org != nil && org.PhonePrefix != "" {
|
||||||
|
phonePrefix = org.PhonePrefix
|
||||||
|
}
|
||||||
|
checkDest = fmt.Sprintf("+%s%s", phonePrefix, dest)
|
||||||
|
}
|
||||||
|
if ret := object.CheckVerificationCode(checkDest, code); len(ret) != 0 {
|
||||||
c.ResponseError(ret)
|
c.ResponseError(ret)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -81,15 +108,8 @@ func (c *ApiController) ResetEmailOrPhone() {
|
|||||||
user.Email = dest
|
user.Email = dest
|
||||||
object.SetUserField(user, "email", user.Email)
|
object.SetUserField(user, "email", user.Email)
|
||||||
case "phone":
|
case "phone":
|
||||||
if strings.Index(dest, "+86") == 0 {
|
user.Phone = dest
|
||||||
user.PhonePrefix = "86"
|
|
||||||
user.Phone = dest[3:]
|
|
||||||
} else if strings.Index(dest, "+1") == 0 {
|
|
||||||
user.PhonePrefix = "1"
|
|
||||||
user.Phone = dest[2:]
|
|
||||||
}
|
|
||||||
object.SetUserField(user, "phone", user.Phone)
|
object.SetUserField(user, "phone", user.Phone)
|
||||||
object.SetUserField(user, "phone_prefix", user.PhonePrefix)
|
|
||||||
default:
|
default:
|
||||||
c.ResponseError("Unknown type.")
|
c.ResponseError("Unknown type.")
|
||||||
return
|
return
|
||||||
|
@ -29,6 +29,7 @@ type Organization struct {
|
|||||||
Favicon string `xorm:"varchar(100)" json:"favicon"`
|
Favicon string `xorm:"varchar(100)" json:"favicon"`
|
||||||
PasswordType string `xorm:"varchar(100)" json:"passwordType"`
|
PasswordType string `xorm:"varchar(100)" json:"passwordType"`
|
||||||
PasswordSalt string `xorm:"varchar(100)" json:"passwordSalt"`
|
PasswordSalt string `xorm:"varchar(100)" json:"passwordSalt"`
|
||||||
|
PhonePrefix string `xorm:"varchar(10)" json:"phonePrefix"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetOrganizations(owner string) []*Organization {
|
func GetOrganizations(owner string) []*Organization {
|
||||||
@ -91,3 +92,16 @@ func DeleteOrganization(organization *Organization) bool {
|
|||||||
|
|
||||||
return affected != 0
|
return affected != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetOrganizationByName(name string) *Organization {
|
||||||
|
var ret Organization
|
||||||
|
ret.Name = name
|
||||||
|
has, err := adapter.Engine.Get(&ret)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if !has {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &ret
|
||||||
|
}
|
||||||
|
@ -34,7 +34,6 @@ type User struct {
|
|||||||
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"`
|
||||||
PhonePrefix string `xorm:"varchar(10)" json:"phonePrefix"`
|
|
||||||
Phone string `xorm:"varchar(100)" json:"phone"`
|
Phone string `xorm:"varchar(100)" json:"phone"`
|
||||||
Affiliation string `xorm:"varchar(100)" json:"affiliation"`
|
Affiliation string `xorm:"varchar(100)" json:"affiliation"`
|
||||||
Tag string `xorm:"varchar(100)" json:"tag"`
|
Tag string `xorm:"varchar(100)" json:"tag"`
|
||||||
|
@ -149,6 +149,16 @@ class OrganizationEditPage extends React.Component {
|
|||||||
}} />
|
}} />
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
<Row style={{marginTop: '20px'}} >
|
||||||
|
<Col style={{marginTop: '5px'}} span={2}>
|
||||||
|
{i18next.t("general:Phone Prefix")}:
|
||||||
|
</Col>
|
||||||
|
<Col span={22} >
|
||||||
|
<Input addonBefore={"+"} value={this.state.organization.phonePrefix} onChange={e => {
|
||||||
|
this.updateOrganizationField('phonePrefix', e.target.value);
|
||||||
|
}} />
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ export const ResetModal = (props) => {
|
|||||||
let dest = document.getElementById("dest").value;
|
let dest = document.getElementById("dest").value;
|
||||||
let code = document.getElementById("code").value;
|
let code = document.getElementById("code").value;
|
||||||
if (dest === "") {
|
if (dest === "") {
|
||||||
Setting.showMessage("error", i18next.t("user:Empty ") + destType);
|
Setting.showMessage("error", i18next.t("user:Empty " + destType));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (code === "") {
|
if (code === "") {
|
||||||
@ -70,7 +70,7 @@ export const ResetModal = (props) => {
|
|||||||
if (sendCodeCoolDown) return;
|
if (sendCodeCoolDown) return;
|
||||||
let dest = document.getElementById("dest").value;
|
let dest = document.getElementById("dest").value;
|
||||||
if (dest === "") {
|
if (dest === "") {
|
||||||
Setting.showMessage("error", i18next.t("user:Empty ") + destType);
|
Setting.showMessage("error", i18next.t("user:Empty " + destType));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
UserBackend.sendCode(dest, destType).then(res => {
|
UserBackend.sendCode(dest, destType).then(res => {
|
||||||
@ -86,7 +86,7 @@ export const ResetModal = (props) => {
|
|||||||
|
|
||||||
let placeHolder = "";
|
let placeHolder = "";
|
||||||
if (destType === "email") placeHolder = i18next.t("user:Input your email");
|
if (destType === "email") placeHolder = i18next.t("user:Input your email");
|
||||||
else if (destType === "phone") placeHolder = i18next.t("user:Phone prefix is needed");
|
else if (destType === "phone") placeHolder = i18next.t("user:Input your phone number");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Row>
|
<Row>
|
||||||
|
@ -285,7 +285,7 @@ class UserEditPage extends React.Component {
|
|||||||
{i18next.t("general:Phone")}:
|
{i18next.t("general:Phone")}:
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={22} >
|
<Col span={22} >
|
||||||
<Input value={"+" + this.state.user.phonePrefix + this.state.user.phone} disabled/>
|
<Input value={this.state.user.phone} disabled/>
|
||||||
{ this.state.user.id === this.props.account.id ? (<ResetModal buttonText={i18next.t("user:Reset Phone")} destType={"phone"} coolDownTime={60}/>) : null}
|
{ this.state.user.id === this.props.account.id ? (<ResetModal buttonText={i18next.t("user:Reset Phone")} destType={"phone"} coolDownTime={60}/>) : null}
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
@ -52,7 +52,6 @@ class UserListPage extends React.Component {
|
|||||||
displayName: `New User - ${this.state.users.length}`,
|
displayName: `New User - ${this.state.users.length}`,
|
||||||
avatar: "https://casbin.org/img/casbin.svg",
|
avatar: "https://casbin.org/img/casbin.svg",
|
||||||
email: "user@example.com",
|
email: "user@example.com",
|
||||||
phonePrefix: "86",
|
|
||||||
phone: "12345678",
|
phone: "12345678",
|
||||||
affiliation: "Example Inc.",
|
affiliation: "Example Inc.",
|
||||||
tag: "staff",
|
tag: "staff",
|
||||||
|
@ -133,19 +133,6 @@ class SignupPage extends React.Component {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const prefixSelector = (
|
|
||||||
<Form.Item name="phonePrefix" noStyle>
|
|
||||||
<Select
|
|
||||||
style={{
|
|
||||||
width: 80,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Option value="1">+1</Option>
|
|
||||||
<Option value="86">+86</Option>
|
|
||||||
</Select>
|
|
||||||
</Form.Item>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form
|
<Form
|
||||||
{...formItemLayout}
|
{...formItemLayout}
|
||||||
@ -156,7 +143,6 @@ class SignupPage extends React.Component {
|
|||||||
initialValues={{
|
initialValues={{
|
||||||
application: application.name,
|
application: application.name,
|
||||||
organization: application.organization,
|
organization: application.organization,
|
||||||
phonePrefix: '86',
|
|
||||||
}}
|
}}
|
||||||
style={{width: !Setting.isMobile() ? "400px" : "250px"}}
|
style={{width: !Setting.isMobile() ? "400px" : "250px"}}
|
||||||
size="large"
|
size="large"
|
||||||
@ -285,7 +271,6 @@ class SignupPage extends React.Component {
|
|||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<Input
|
<Input
|
||||||
addonBefore={prefixSelector}
|
|
||||||
style={{
|
style={{
|
||||||
width: '100%',
|
width: '100%',
|
||||||
}}
|
}}
|
||||||
|
@ -29,7 +29,8 @@
|
|||||||
"Users under all organizations": "Users under all organizations",
|
"Users under all organizations": "Users under all organizations",
|
||||||
"OAuth providers": "OAuth providers",
|
"OAuth providers": "OAuth providers",
|
||||||
"Applications that requires authentication": "Applications that requires authentication",
|
"Applications that requires authentication": "Applications that requires authentication",
|
||||||
"Swagger": "Swagger"
|
"Swagger": "Swagger",
|
||||||
|
"Phone Prefix": "Phone Prefix"
|
||||||
},
|
},
|
||||||
"signup":
|
"signup":
|
||||||
{
|
{
|
||||||
@ -126,7 +127,7 @@
|
|||||||
"email reset": "Email Reset",
|
"email reset": "Email Reset",
|
||||||
"Code Sent": "Code Sent",
|
"Code Sent": "Code Sent",
|
||||||
"Input your email": "Input your email",
|
"Input your email": "Input your email",
|
||||||
"Phone prefix is needed": "Phone prefix is needed",
|
"Input your phone number": "Input your phone number",
|
||||||
"New phone": "New Phone",
|
"New phone": "New Phone",
|
||||||
"New email": "New Email",
|
"New email": "New Email",
|
||||||
"Code You Received": "Code You Received",
|
"Code You Received": "Code You Received",
|
||||||
|
@ -29,7 +29,8 @@
|
|||||||
"Users under all organizations": "所有组织里的用户",
|
"Users under all organizations": "所有组织里的用户",
|
||||||
"OAuth providers": "OAuth提供方",
|
"OAuth providers": "OAuth提供方",
|
||||||
"Applications that requires authentication": "需要鉴权的应用",
|
"Applications that requires authentication": "需要鉴权的应用",
|
||||||
"Swagger": "API总览"
|
"Swagger": "API总览",
|
||||||
|
"Phone Prefix": "电话前缀"
|
||||||
},
|
},
|
||||||
"signup":
|
"signup":
|
||||||
{
|
{
|
||||||
@ -128,7 +129,7 @@
|
|||||||
"email reset": "邮箱已设置",
|
"email reset": "邮箱已设置",
|
||||||
"Code Sent": "验证码已发送",
|
"Code Sent": "验证码已发送",
|
||||||
"Input your email": "请输入邮箱",
|
"Input your email": "请输入邮箱",
|
||||||
"Phone prefix is needed": "记得输入地区前缀(+86)",
|
"Input your phone number": "输入电话号码",
|
||||||
"New phone": "新的电话号",
|
"New phone": "新的电话号",
|
||||||
"New email": "新的邮箱",
|
"New email": "新的邮箱",
|
||||||
"Code You Received": "你收到的验证码",
|
"Code You Received": "你收到的验证码",
|
||||||
|
Reference in New Issue
Block a user