diff --git a/controllers/account.go b/controllers/account.go
index 1df84639..11fdfaa2 100644
--- a/controllers/account.go
+++ b/controllers/account.go
@@ -101,7 +101,6 @@ func (c *ApiController) Signup() {
DisplayName: form.Name,
Avatar: "https://casbin.org/img/casbin.svg",
Email: form.Email,
- PhonePrefix: form.PhonePrefix,
Phone: form.Phone,
Affiliation: form.Affiliation,
IsAdmin: false,
diff --git a/controllers/verification.go b/controllers/verification.go
index 045aebb8..7c39b008 100644
--- a/controllers/verification.go
+++ b/controllers/verification.go
@@ -15,12 +15,24 @@
package controllers
import (
+ "fmt"
"strings"
"github.com/casdoor/casdoor/object"
)
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")
dest := c.Ctx.Request.Form.Get("dest")
remoteAddr := c.Ctx.Request.RemoteAddr
@@ -37,6 +49,12 @@ func (c *ApiController) SendVerificationCode() {
case "email":
ret = object.SendVerificationCodeToEmail(remoteAddr, dest)
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)
}
@@ -71,7 +89,16 @@ func (c *ApiController) ResetEmailOrPhone() {
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)
return
}
@@ -81,15 +108,8 @@ func (c *ApiController) ResetEmailOrPhone() {
user.Email = dest
object.SetUserField(user, "email", user.Email)
case "phone":
- if strings.Index(dest, "+86") == 0 {
- user.PhonePrefix = "86"
- user.Phone = dest[3:]
- } else if strings.Index(dest, "+1") == 0 {
- user.PhonePrefix = "1"
- user.Phone = dest[2:]
- }
+ user.Phone = dest
object.SetUserField(user, "phone", user.Phone)
- object.SetUserField(user, "phone_prefix", user.PhonePrefix)
default:
c.ResponseError("Unknown type.")
return
diff --git a/object/organization.go b/object/organization.go
index a8323d22..b9c40c44 100644
--- a/object/organization.go
+++ b/object/organization.go
@@ -29,6 +29,7 @@ type Organization struct {
Favicon string `xorm:"varchar(100)" json:"favicon"`
PasswordType string `xorm:"varchar(100)" json:"passwordType"`
PasswordSalt string `xorm:"varchar(100)" json:"passwordSalt"`
+ PhonePrefix string `xorm:"varchar(10)" json:"phonePrefix"`
}
func GetOrganizations(owner string) []*Organization {
@@ -91,3 +92,16 @@ func DeleteOrganization(organization *Organization) bool {
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
+}
diff --git a/object/user.go b/object/user.go
index 89bf6d71..2d5c088c 100644
--- a/object/user.go
+++ b/object/user.go
@@ -34,7 +34,6 @@ type User struct {
DisplayName string `xorm:"varchar(100)" json:"displayName"`
Avatar string `xorm:"varchar(255)" json:"avatar"`
Email string `xorm:"varchar(100)" json:"email"`
- PhonePrefix string `xorm:"varchar(10)" json:"phonePrefix"`
Phone string `xorm:"varchar(100)" json:"phone"`
Affiliation string `xorm:"varchar(100)" json:"affiliation"`
Tag string `xorm:"varchar(100)" json:"tag"`
diff --git a/web/src/OrganizationEditPage.js b/web/src/OrganizationEditPage.js
index 49d496f7..e68b65fc 100644
--- a/web/src/OrganizationEditPage.js
+++ b/web/src/OrganizationEditPage.js
@@ -149,6 +149,16 @@ class OrganizationEditPage extends React.Component {
}} />
+