예제 #1
0
func Openid(c *common.HTTPContext) (err error) {
	redirect, email, ok, err := gopenid.VerifyAuth(c.Req())
	if err != nil {
		return
	}
	if ok {
		email = strings.ToLower(email)
		c.Session().Values[common.SessionEmail] = email
		u := &User{Id: kol.Id(email)}
		err = c.DB().Get(u)
		if err == kol.NotFound {
			err = nil
			u.Email = email
			u.Ranking = 1
		}
		if err == nil {
			u.Language = common.GetLanguage(c.Req())
			u.DiplicityHost = c.Req().Host
			u.LastLoginAt = time.Now()
			err = c.DB().Set(u)
		}
	} else {
		delete(c.Session().Values, common.SessionEmail)
	}
	c.Close()
	c.Resp().Header().Set("Location", redirect.String())
	c.Resp().WriteHeader(302)
	fmt.Fprintln(c.Resp(), redirect.String())
	return
}
예제 #2
0
func AdminBecome(c *common.HTTPContext) (err error) {
	c.Session().Values[common.SessionEmail] = c.Req().FormValue("become")
	c.Close()
	c.Resp().Header().Set("Location", "/")
	c.Resp().WriteHeader(302)
	fmt.Fprintln(c.Resp(), "/")
	return
}
예제 #3
0
func Logout(c *common.HTTPContext) (err error) {
	delete(c.Session().Values, common.SessionEmail)
	c.Close()
	redirect := c.Req().FormValue("return_to")
	if redirect == "" {
		redirect = fmt.Sprintf("http://%v/", c.Req().Host)
	}
	c.Resp().Header().Set("Location", redirect)
	c.Resp().WriteHeader(302)
	fmt.Fprintln(c.Resp(), redirect)
	return
}