summaryrefslogtreecommitdiffstats
path: root/models/user.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/user.go')
-rw-r--r--models/user.go38
1 files changed, 37 insertions, 1 deletions
diff --git a/models/user.go b/models/user.go
index 5f08f9e92d..3c31b3aff4 100644
--- a/models/user.go
+++ b/models/user.go
@@ -5,6 +5,7 @@
package models
import (
+ "encoding/hex"
"errors"
"fmt"
"os"
@@ -17,6 +18,7 @@ import (
"github.com/gogits/git"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/log"
)
// User types.
@@ -139,9 +141,43 @@ func RegisterUser(user *User) (*User, error) {
return user, nil
}
+// get user by erify code
+func getVerifyUser(code string) (user *User) {
+ if len(code) <= base.TimeLimitCodeLength {
+ return nil
+ }
+
+ // use tail hex username query user
+ hexStr := code[base.TimeLimitCodeLength:]
+ if b, err := hex.DecodeString(hexStr); err == nil {
+ if user, err = GetUserByName(string(b)); user != nil {
+ return user
+ }
+ log.Error("user.getVerifyUser: %v", err)
+ }
+
+ return nil
+}
+
+// verify active code when active account
+func VerifyUserActiveCode(code string) (user *User) {
+ minutes := base.Service.ActiveCodeLives
+
+ if user = getVerifyUser(code); user != nil {
+ // time limit code
+ prefix := code[:base.TimeLimitCodeLength]
+ data := base.ToStr(user.Id) + user.Email + user.LowerName + user.Passwd + user.Rands
+
+ if base.VerifyTimeLimitCode(data, minutes, prefix) {
+ return user
+ }
+ }
+ return nil
+}
+
// UpdateUser updates user's information.
func UpdateUser(user *User) (err error) {
- _, err = orm.Id(user.Id).Update(user)
+ _, err = orm.Id(user.Id).UseBool().Update(user)
return err
}