fmt all go file
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/leanote/leanote/app/info"
|
||||
"github.com/leanote/leanote/app/db"
|
||||
"github.com/leanote/leanote/app/info"
|
||||
. "github.com/leanote/leanote/app/lea"
|
||||
"gopkg.in/mgo.v2/bson"
|
||||
"time"
|
||||
// "strings"
|
||||
// "strings"
|
||||
)
|
||||
|
||||
// Session存储到mongodb中
|
||||
@ -14,9 +14,10 @@ type SessionService struct {
|
||||
}
|
||||
|
||||
func (this *SessionService) Update(sessionId, key string, value interface{}) bool {
|
||||
return db.UpdateByQMap(db.Sessions, bson.M{"SessionId": sessionId},
|
||||
return db.UpdateByQMap(db.Sessions, bson.M{"SessionId": sessionId},
|
||||
bson.M{key: value, "UpdatedTime": time.Now()})
|
||||
}
|
||||
|
||||
// 注销时清空session
|
||||
func (this *SessionService) Clear(sessionId string) bool {
|
||||
return db.Delete(db.Sessions, bson.M{"SessionId": sessionId})
|
||||
@ -24,7 +25,7 @@ func (this *SessionService) Clear(sessionId string) bool {
|
||||
func (this *SessionService) Get(sessionId string) info.Session {
|
||||
session := info.Session{}
|
||||
db.GetByQ(db.Sessions, bson.M{"SessionId": sessionId}, &session)
|
||||
|
||||
|
||||
// 如果没有session, 那么插入一条之
|
||||
if session.Id == "" {
|
||||
session.Id = bson.NewObjectId()
|
||||
@ -33,7 +34,7 @@ func (this *SessionService) Get(sessionId string) info.Session {
|
||||
session.UpdatedTime = session.CreatedTime
|
||||
db.Insert(db.Sessions, session)
|
||||
}
|
||||
|
||||
|
||||
return session
|
||||
}
|
||||
|
||||
@ -45,14 +46,16 @@ func (this *SessionService) LoginTimesIsOver(sessionId string) bool {
|
||||
session := this.Get(sessionId)
|
||||
return session.LoginTimes > 5
|
||||
}
|
||||
|
||||
// 登录成功后清空错误次数
|
||||
func (this *SessionService) ClearLoginTimes(sessionId string) bool {
|
||||
return this.Update(sessionId, "LoginTimes", 0)
|
||||
}
|
||||
|
||||
// 增加错误次数
|
||||
func (this *SessionService) IncrLoginTimes(sessionId string) bool {
|
||||
session := this.Get(sessionId)
|
||||
return this.Update(sessionId, "LoginTimes", session.LoginTimes + 1)
|
||||
return this.Update(sessionId, "LoginTimes", session.LoginTimes+1)
|
||||
}
|
||||
|
||||
//----------
|
||||
@ -75,7 +78,7 @@ func (this *SessionService) SetCaptcha(sessionId, captcha string) bool {
|
||||
func (this *SessionService) GetUserId(sessionId string) string {
|
||||
session := this.Get(sessionId)
|
||||
// 更新updateTime, 避免过期
|
||||
db.UpdateByQMap(db.Sessions, bson.M{"SessionId": sessionId},
|
||||
db.UpdateByQMap(db.Sessions, bson.M{"SessionId": sessionId},
|
||||
bson.M{"UpdatedTime": time.Now()})
|
||||
return session.UserId
|
||||
}
|
||||
|
Reference in New Issue
Block a user