aboutsummaryrefslogtreecommitdiff
path: root/models/user.go
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-03-19 07:21:23 -0400
committerUnknown <joe2010xtmf@163.com>2014-03-19 07:21:23 -0400
commitfbbae2b721c04be740d67b9d227a7578030f93b9 (patch)
tree394b9bb1e2e3b36611d834027ecaf6ee34a8a41d /models/user.go
parent9a666f33773c5d8b66e9ab66598414f62bcfdc11 (diff)
Working on register mail confirmation
Diffstat (limited to 'models/user.go')
-rw-r--r--models/user.go25
1 files changed, 16 insertions, 9 deletions
diff --git a/models/user.go b/models/user.go
index 80af9bd4..579f6a74 100644
--- a/models/user.go
+++ b/models/user.go
@@ -19,14 +19,6 @@ import (
"github.com/gogits/gogs/modules/base"
)
-var (
- UserPasswdSalt string
-)
-
-func init() {
- UserPasswdSalt = base.Cfg.MustValue("security", "USER_PASSWD_SALT")
-}
-
// User types.
const (
UT_INDIVIDUAL = iota + 1
@@ -56,6 +48,9 @@ type User struct {
AvatarEmail string `xorm:"not null"`
Location string
Website string
+ IsActive bool
+ Rands string `xorm:"VARCHAR(10)"`
+ Expired time.Time
Created time.Time `xorm:"created"`
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.
func RegisterUser(user *User) (err error) {
isExist, err := IsUserExist(user.Name)
@@ -123,6 +123,8 @@ func RegisterUser(user *User) (err error) {
user.LowerName = strings.ToLower(user.Name)
user.Avatar = base.EncodeMd5(user.Email)
user.AvatarEmail = user.Email
+ user.Expired = time.Now().Add(3 * 24 * time.Hour)
+ user.Rands = GetUserSalt()
if err = user.EncodePasswd(); err != nil {
return err
} else if _, err = orm.Insert(user); err != nil {
@@ -134,6 +136,11 @@ func RegisterUser(user *User) (err error) {
}
return err
}
+
+ // Send confirmation e-mail.
+ if base.Service.RegisterEmailConfitm {
+
+ }
return nil
}
@@ -183,7 +190,7 @@ func DeleteUser(user *User) error {
// EncodePasswd encodes password to safe format.
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)
return err
}