|
@@ -19,14 +19,6 @@ import (
|
|
"github.com/gogits/gogs/modules/base"
|
|
"github.com/gogits/gogs/modules/base"
|
|
)
|
|
)
|
|
|
|
|
|
-var (
|
|
|
|
- UserPasswdSalt string
|
|
|
|
-)
|
|
|
|
-
|
|
|
|
-func init() {
|
|
|
|
- UserPasswdSalt = base.Cfg.MustValue("security", "USER_PASSWD_SALT")
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
// User types.
|
|
// User types.
|
|
const (
|
|
const (
|
|
UT_INDIVIDUAL = iota + 1
|
|
UT_INDIVIDUAL = iota + 1
|
|
@@ -56,6 +48,9 @@ type User struct {
|
|
AvatarEmail string `xorm:"not null"`
|
|
AvatarEmail string `xorm:"not null"`
|
|
Location string
|
|
Location string
|
|
Website string
|
|
Website string
|
|
|
|
+ IsActive bool
|
|
|
|
+ Rands string `xorm:"VARCHAR(10)"`
|
|
|
|
+ Expired time.Time
|
|
Created time.Time `xorm:"created"`
|
|
Created time.Time `xorm:"created"`
|
|
Updated time.Time `xorm:"updated"`
|
|
Updated time.Time `xorm:"updated"`
|
|
}
|
|
}
|
|
@@ -104,6 +99,11 @@ func (user *User) NewGitSig() *git.Signature {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// return a user salt token
|
|
|
|
+func GetUserSalt() string {
|
|
|
|
+ return base.GetRandomString(10)
|
|
|
|
+}
|
|
|
|
+
|
|
// RegisterUser creates record of a new user.
|
|
// RegisterUser creates record of a new user.
|
|
func RegisterUser(user *User) (err error) {
|
|
func RegisterUser(user *User) (err error) {
|
|
isExist, err := IsUserExist(user.Name)
|
|
isExist, err := IsUserExist(user.Name)
|
|
@@ -123,6 +123,8 @@ func RegisterUser(user *User) (err error) {
|
|
user.LowerName = strings.ToLower(user.Name)
|
|
user.LowerName = strings.ToLower(user.Name)
|
|
user.Avatar = base.EncodeMd5(user.Email)
|
|
user.Avatar = base.EncodeMd5(user.Email)
|
|
user.AvatarEmail = user.Email
|
|
user.AvatarEmail = user.Email
|
|
|
|
+ user.Expired = time.Now().Add(3 * 24 * time.Hour)
|
|
|
|
+ user.Rands = GetUserSalt()
|
|
if err = user.EncodePasswd(); err != nil {
|
|
if err = user.EncodePasswd(); err != nil {
|
|
return err
|
|
return err
|
|
} else if _, err = orm.Insert(user); err != nil {
|
|
} else if _, err = orm.Insert(user); err != nil {
|
|
@@ -134,6 +136,11 @@ func RegisterUser(user *User) (err error) {
|
|
}
|
|
}
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // Send confirmation e-mail.
|
|
|
|
+ if base.Service.RegisterEmailConfitm {
|
|
|
|
+
|
|
|
|
+ }
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
@@ -183,7 +190,7 @@ func DeleteUser(user *User) error {
|
|
|
|
|
|
// EncodePasswd encodes password to safe format.
|
|
// EncodePasswd encodes password to safe format.
|
|
func (user *User) EncodePasswd() error {
|
|
func (user *User) EncodePasswd() error {
|
|
- newPasswd, err := scrypt.Key([]byte(user.Passwd), []byte(UserPasswdSalt), 16384, 8, 1, 64)
|
|
|
|
|
|
+ newPasswd, err := scrypt.Key([]byte(user.Passwd), []byte(base.SecretKey), 16384, 8, 1, 64)
|
|
user.Passwd = fmt.Sprintf("%x", newPasswd)
|
|
user.Passwd = fmt.Sprintf("%x", newPasswd)
|
|
return err
|
|
return err
|
|
}
|
|
}
|