Esempio n. 1
0
func (h *handler) handleMe(w http.ResponseWriter, r *http.Request, s *session.Session) (interface{}, error) {
	if s != nil {
		if c := s.Get("coder", nil); c != nil {
			return c.(Coder), nil
		}
	}
	return nil, nil
}
Esempio n. 2
0
func (h *handler) handleLogout(w http.ResponseWriter, r *http.Request, s *session.Session) (interface{}, error) {
	if s != nil {
		s.Del("coder")
		if err := s.Save(); err != nil {
			return nil, err
		}
	}
	return nil, nil
}
Esempio n. 3
0
func (h *handler) handleLogin(w http.ResponseWriter, r *http.Request, s *session.Session) (interface{}, error) {
	handle := r.FormValue("handle")
	c, err := h.dbMgr.FetchCoder(handle)
	if err != nil || c == nil {
		return nil, err
	}

	passwd := r.FormValue("passwd")
	if !c.CheckPasswd(passwd) {
		return nil, nil
	}

	s.Set("coder", c)
	if err := s.Save(); err != nil {
		return nil, err
	}

	return c, nil
}