Exemplo n.º 1
0
func (f *ThirdPartyBindFilter) OnActionExecuting(ctx *goku.HttpContext) (ar goku.ActionResulter, err error) {

	sessionIdBase, err := ctx.Request.Cookie(config.ThirdPartyCookieKey)
	if err != nil || len(sessionIdBase.Value) == 0 {
		ar = ctx.NotFound("no user binding context found.")
		return
	}
	ctx.Data["thirdPartySessionIdBase"] = sessionIdBase.Value

	profileSessionId := models.ThirdParty_GetThirdPartyProfileSessionId(sessionIdBase.Value)
	profile := models.ThirdParty_GetThirdPartyProfileFromSession(profileSessionId)

	if profile == nil {
		ar = ctx.NotFound("no user binding context found.")
		return
	}

	ctx.ViewData["profile"] = profile
	if len(profile.Email) > 0 {
		sensitiveInfoRemovedEmail := utils.GetSensitiveInfoRemovedEmail(profile.Email)
		ctx.ViewData["directCreateEmail"] = sensitiveInfoRemovedEmail
	}

	var profileShow struct {
		Avatar bool
		Link   bool
		Name   string
	}
	profileShow.Avatar = (len(profile.AvatarUrl) > 0)
	profileShow.Link = (len(profile.Link) > 0)
	profileShow.Name = profile.GetDisplayName()
	ctx.ViewData["profileShow"] = profileShow

	return
}
Exemplo n.º 2
0
func userRecoverPreProcess(ctx *goku.HttpContext) (user *models.User, ur *models.UserRecovery, r goku.ActionResulter) {
	queryStrings := ctx.Request.URL.Query()
	token := queryStrings.Get("token")
	userId, _ := strconv.ParseInt(ctx.RouteData.Params["id"], 10, 64)
	ctx.ViewData["recoverPwdToken"] = token

	if ur = models.User_GetActiveRecoveryRequest(userId, token); ur == nil {
		r = ctx.NotFound("invalid token")
		return
	}

	user = models.User_GetById(userId)
	if user == nil {
		ur = nil
		r = ctx.NotFound("user not found")
	}

	return
}