Example #1
0
func (this *SsoController) User() {
	sig := this.Ctx.Input.Param(":sig")
	if sig == "" {
		this.NotFound("sig is blank")
		return
	}

	sessionObj := uic.ReadSessionBySig(sig)
	if sessionObj == nil {
		this.NotFound("no such sig")
		return
	}

	if int64(sessionObj.Expired) < time.Now().Unix() {
		uic.RemoveSessionByUid(sessionObj.Uid)
		this.SessionExpired()
		return
	}

	u := uic.ReadUserById(sessionObj.Uid)
	if u == nil {
		this.NotFound("no such user")
		return
	}

	this.Data["json"] = map[string]interface{}{
		"user": u,
	}
	this.ServeJson()
}
Example #2
0
func GetNote(noteId int64) (EventNote, error) {
	q := orm.NewOrm()
	q.Using("falcon_portal")
	var eventNote EventNote
	err := q.Raw(`SELECT * from event_note WHERE event_note.id = ?`, noteId).QueryRow(&eventNote)
	if err == nil {
		user := uic.ReadUserById(eventNote.UserId)
		eventNote.UserName = user.Name
	}
	return eventNote, err
}
Example #3
0
)

var FilterLoginUser = func(ctx *context.Context) {
	cookieSig := ctx.GetCookie("sig")
	if cookieSig == "" {
		ctx.Redirect(302, "/auth/login?callback="+ctx.Request.URL.String())
		return
	}

	sessionObj := uic.ReadSessionBySig(cookieSig)
	if sessionObj == nil || int64(sessionObj.Expired) < time.Now().Unix() {
		ctx.Redirect(302, "/auth/login?callback="+ctx.Request.URL.String())
		return
	}

	u := uic.ReadUserById(sessionObj.Uid)
	if u == nil {
		ctx.Redirect(302, "/auth/login?callback="+ctx.Request.URL.String())
		return
	}

	ctx.Input.SetData("CurrentUser", u)
}

var FilterTargetUser = func(ctx *context.Context) {
	userId := ctx.Input.Query("id")
	if userId == "" {
		ctx.ResponseWriter.WriteHeader(403)
		ctx.ResponseWriter.Write([]byte("id is necessary"))
		return
	}