diff options
author | Unknown <joe2010xtmf@163.com> | 2014-03-19 12:50:44 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-03-19 12:50:44 -0400 |
commit | 35d473f04ac79990a35499fbf3c4998170e655e1 (patch) | |
tree | fca64b6679336766ffc6965f3f09974c9d3da348 /models/user.go | |
parent | c6e12d256833095d76bbb5755261507ecbdaada9 (diff) | |
download | gitea-35d473f04ac79990a35499fbf3c4998170e655e1.tar.gz gitea-35d473f04ac79990a35499fbf3c4998170e655e1.zip |
Finish verify email
Diffstat (limited to 'models/user.go')
-rw-r--r-- | models/user.go | 38 |
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 } |