本文整理匯總了Golang中github.com/ginuerzh/sports/models.RedisLogger.SetOnlineUser方法的典型用法代碼示例。如果您正苦於以下問題:Golang RedisLogger.SetOnlineUser方法的具體用法?Golang RedisLogger.SetOnlineUser怎麽用?Golang RedisLogger.SetOnlineUser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ginuerzh/sports/models.RedisLogger
的用法示例。
在下文中一共展示了RedisLogger.SetOnlineUser方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: loginHandlerV2
func loginHandlerV2(request *http.Request, resp http.ResponseWriter,
redis *models.RedisLogger, form loginFormV2) {
user := &models.Account{}
if exists, _ := models.CheckUserExists(form.Id, form.Type); !exists {
writeResponse(request.RequestURI, resp,
nil, errors.NewError(errors.AuthError, "該用戶還未注冊"))
return
}
user.FindPass(form.Id, form.Type, Md5(form.Password))
if len(user.Id) == 0 {
writeResponse(request.RequestURI, resp,
nil, errors.NewError(errors.AuthError))
return
}
if user.TimeLimit < 0 {
writeResponse(request.RequestURI, resp,
nil, errors.NewError(errors.AuthError, "賬戶已禁用"))
return
}
token := Uuid() + "-" + strconv.FormatInt(time.Now().AddDate(0, 0, 30).Unix(), 10)
redis.SetOnlineUser(token, user.Id)
data := map[string]interface{}{
"access_token": token,
"userid": user.Id,
//"last_login_time": user.LastLogin.Unix(),
}
writeResponse(request.RequestURI, resp, data, nil)
}
示例2: regHandlerV2
func regHandlerV2(request *http.Request, resp http.ResponseWriter,
redis *models.RedisLogger, form regFormV2) {
exists, err := models.CheckUserExists(form.Id, form.Type)
if err != nil {
writeResponse(request.RequestURI, resp,
nil, errors.NewError(errors.DbError))
return
}
if exists {
writeResponse(request.RequestURI, resp,
nil, errors.NewError(errors.UserExistError))
return
}
dbw, err := getNewWallet()
if err != nil {
writeResponse(request.RequestURI, resp,
nil, errors.NewError(errors.DbError, "創建錢包失敗"))
return
}
user := &models.Account{
Role: form.Type,
Password: Md5(form.Password),
Nickname: form.Nickname,
Profile: form.Profile,
Gender: form.Gender,
Birth: form.Birthday,
Wallet: *dbw,
RegTime: time.Now(),
}
switch form.Type {
case models.AccountPhone:
user.Phone = form.Id
case models.AccountWeibo:
user.Weibo = form.Id
case models.AccountEmail:
fallthrough
default:
user.Email = form.Id
}
if err := user.Save(); err != nil {
writeResponse(request.RequestURI, resp, nil, err)
return
}
token := Uuid() + "-" + strconv.FormatInt(time.Now().AddDate(0, 0, 30).Unix(), 10)
data := map[string]string{"access_token": token, "userid": user.Id}
writeResponse(request.RequestURI, resp, data, nil)
redis.LogRegister(user.Id, form.Type)
redis.SetOnlineUser(token, user.Id)
// ws push
//regNotice(user.Id, redis)
}
示例3: loginHandler
func loginHandler(request *http.Request, resp http.ResponseWriter, redis *models.RedisLogger, form loginForm) {
user := &models.Account{}
var err error
var reg bool
token := Uuid() + "-" + strconv.FormatInt(time.Now().AddDate(0, 0, 30).Unix(), 10)
switch form.Type {
case "weibo":
reg, user, err = weiboLogin(form.Userid, form.Password, redis)
case "weixin":
writeResponse(request.RequestURI, resp, nil, errors.NewError(errors.UnimplementedError))
return
case "usrpass":
fallthrough
default:
var find bool
if find, err = user.FindByUserPass(strings.ToLower(form.Userid), Md5(form.Password)); !find {
if err == nil {
err = errors.NewError(errors.AuthError)
}
}
}
if err != nil {
writeResponse(request.RequestURI, resp, nil, err)
return
}
if user.TimeLimit < 0 {
writeResponse(request.RequestURI, resp, nil, errors.NewError(errors.AuthError, "賬戶已禁用"))
return
}
redis.SetOnlineUser(token, user.Id)
data := map[string]interface{}{
"access_token": token,
"userid": user.Id,
"register": reg,
"last_login_time": user.LastLogin.Unix(),
"ExpEffect": Awards{},
}
writeResponse(request.RequestURI, resp, data, nil)
}
示例4: registerHandler
func registerHandler(request *http.Request, resp http.ResponseWriter, redis *models.RedisLogger, form userRegForm) {
user := &models.Account{}
t := ""
if phone, _ := strconv.ParseUint(form.Email, 10, 64); phone > 0 {
user.Phone = form.Email
t = models.AccountPhone
} else {
user.Email = strings.ToLower(form.Email)
t = models.AccountEmail
}
if exists, _ := user.Exists(t); exists {
writeResponse(request.RequestURI, resp, nil, errors.NewError(errors.UserExistError))
return
}
//user.Nickname = form.Nickname
user.Password = Md5(form.Password)
user.Role = t
user.RegTime = time.Now()
dbw, err := getNewWallet()
if err != nil {
writeResponse(request.RequestURI, resp, nil, errors.NewError(errors.DbError, "wallet: "+err.Error()))
return
}
user.Wallet = *dbw
if err := user.Save(); err != nil {
writeResponse(request.RequestURI, resp, nil, err)
} else {
token := Uuid() + "-" + strconv.FormatInt(time.Now().AddDate(0, 0, 30).Unix(), 10)
data := map[string]string{"access_token": token, "userid": user.Id}
writeResponse(request.RequestURI, resp, data, nil)
redis.LogRegister(user.Id, t)
redis.SetOnlineUser(token, user.Id)
// ws push
regNotice(user.Id, redis)
}
}