Example #1
0
func registerView(req *http.Request, s *session) interface{} {
	rurl := req.FormValue("back")
	if rurl == "" {
		rurl = "/"
	}

	ret := giveTplData{
		"ReturnTo": rurl,
	}

	if req.FormValue("username") != "" {
		if req.FormValue("password") == "" {
			ret["Error"] = messages["MustEnterPassword"]
		} else if req.FormValue("password2") != req.FormValue("password") {
			ret["Error"] = messages["MustEnterSamePasswordTwice"]
		} else if req.FormValue("email") == "" {
			ret["Error"] = messages["MustEnterEmail"]
		} else if study.GetUser(req.FormValue("username")) != nil {
			ret["Error"] = messages["UsernameTaken"]
		} else {
			u := study.CreateUser(req.FormValue("username"))
			u.SetAttr("admin", study.DBFALSE)
			u.SetAttr("password", util.StrSHA1(req.FormValue("password")))
			u.SetAttr("email", req.FormValue("email"))
			u.SetAttr("fullname", req.FormValue("fullname"))
			return redirectResponse("/login?back=" + rurl)
		}
	}

	return ret
}
Example #2
0
func loginView(req *http.Request, s *session) interface{} {
	rurl := req.FormValue("back")
	if rurl == "" {
		rurl = "/"
	}

	if req.FormValue("username") != "" && req.FormValue("password") != "" {
		user := study.GetUser(req.FormValue("username"))
		if user != nil && user.CheckPass(req.FormValue("password")) {
			s.User = user
			s.Admin = false
			if user.GetAttr("admin") == study.DBTRUE {
				if _, ok := config.Conf.AdminUsers[user.Username]; ok {
					s.Admin = true
				} else {
					user.SetAttr("admin", study.DBFALSE)
				}
			}
			return redirectResponse(rurl)
		}
		return giveTplData{
			"ReturnTo": rurl,
			"Error":    messages["BadUserOrPass"],
		}
	}
	return giveTplData{
		"ReturnTo": rurl,
	}
}