Exemplo n.º 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
}
Exemplo n.º 2
0
func checkAdminUsers() {
	for name, info := range config.Conf.AdminUsers {
		log.Printf("Admin user : %v", name)
		if info.ResetDBAtStartup {
			os.Remove((&User{Username: name}).dbFile())
		}
		user := CreateUser(name)
		user.SetAttr("admin", DBTRUE)
		user.SetAttr("password", util.StrSHA1(info.Password))
		user.SetAttr("email", info.Email)
		user.SetAttr("fullname", info.FullName)
	}
}
Exemplo n.º 3
0
func settingsView(req *http.Request, s *session) interface{} {
	if s.User == nil {
		return redirectResponse("/login?back=/settings")
	}

	ret := giveTplData{
		"Email":    s.User.GetAttr("email"),
		"FullName": s.User.GetAttr("fullname"),
	}

	if req.FormValue("email") != "" && req.FormValue("fullname") != "" {
		ret["Email"] = req.FormValue("email")
		ret["FullName"] = req.FormValue("fullname")
		s.User.SetAttr("email", req.FormValue("email"))
		s.User.SetAttr("fullname", req.FormValue("fullname"))
		ret["Message"] = messages["InfoUpdated"]
	}

	apw, pw1, pw2 := req.FormValue("apw"), req.FormValue("pw1"), req.FormValue("pw2")
	if apw != "" && pw1 != "" && pw2 != "" {
		if !s.User.CheckPass(apw) {
			ret["Error"] = messages["BadActualPassword"]
		} else if pw1 != pw2 {
			ret["Error"] = messages["MustEnterSamePasswordTwice"]
		} else {
			s.User.SetAttr("password", util.StrSHA1(pw1))
			ret["Message"] = messages["InfoUpdated"]
		}
	}

	lessfuri, ok1 := map[string]int{
		"always":      study.LF_ALWAYS,
		"notknown":    study.LF_NOT_KNOWN,
		"notstudying": study.LF_NOT_STUDYING,
		"never":       study.LF_NEVER,
	}[req.FormValue("lessfuri")]
	anyfuri, ok2 := map[string]int{
		"always": study.AF_ALWAYS,
		"never":  study.AF_NEVER,
	}[req.FormValue("anyfuri")]
	if ok1 && ok2 {
		s.User.SetLessFuri(lessfuri)
		s.User.SetAnyFuri(anyfuri)
		ret["Message"] = messages["InfoUpdated"]
	}

	return ret
}
Exemplo n.º 4
0
func (u *User) CheckPass(pass string) bool {
	return u.GetAttr("password") == util.StrSHA1(pass)
}