Esempio n. 1
0
func ProcessAccountOverviewName(res http.ResponseWriter, req *http.Request, base *BaseController) {
	name := req.PostFormValue("newname")
	if len(name) > 30 || len(name) < 5 {
		base.Session.SetFlash("Your account name should have between 5 - 30 characters!", "error")
		http.Redirect(res, req, "/account/manage/overview/name", 301)
		return
	}
	if models.CheckAccountName(name) {
		base.Session.SetFlash("This name is already used. Please choose another name!", "error")
		http.Redirect(res, req, "/account/manage/overview/name", 301)
		return
	}
	rgxp, err := regexp.Compile(`^[A-Za-z0-9]+$`)
	if err != nil {
		http.Error(res, "Error compiling RegExp at register", 500)
		return
	}
	if !rgxp.MatchString(name) {
		base.Session.SetFlash("This name cannot be used because it contains a forbidden word or combination of letters. Please choose another name!", "error")
		http.Redirect(res, req, "/account/manage/overview/name", 301)
		return
	}
	err = models.ChangeAccountName(base.Account.Id, name)
	if err != nil {
		http.Error(res, "Error while trying to change your account name", 500)
		return
	}
	views.Parser.ExecuteTemplate(res, "account_overview_name_success.html", &AccountOverviewNameSuccessResponse{"account-manage"})
}
Esempio n. 2
0
func ProcessAccountLogin(res http.ResponseWriter, req *http.Request, base *BaseController) {
	name := req.PostFormValue("loginname")
	password := req.PostFormValue("loginpassword")
	captcha_response, err := captcha.Verify(req.PostFormValue("g-recaptcha-response"))
	if err != nil {
		http.Error(res, "Error while checking captcha code", 500)
		return
	}
	if !captcha_response {
		base.Session.SetFlash("Wrong captcha response", "error")
		http.Redirect(res, req, "/account/login", 301)
		return
	}
	if !models.CheckAccountName(name) {
		base.Session.SetFlash("Account name or password is not correct!", "error")
		http.Redirect(res, req, "/account/login", 301)
		return
	}
	account_id, success := models.CheckLogin(name, fmt.Sprintf("%x", sha1.Sum([]byte(password))))
	if !success {
		base.Session.SetFlash("Account name or password is not correct!", "error")
		http.Redirect(res, req, "/account/login", 301)
		return
	}
	token, err := GenerateLoginToken(15)
	if err != nil {
		http.Error(res, "Error while creating login token", 500)
		return
	}
	base.Session.SetValue("token", token)
	base.Session.SetValue("logged", "true")
	err = models.SetAccountTokenByName(account_id, token)
	if err != nil {
		http.Error(res, "Error while changing your account token", 500)
		return
	}
	intended_route, allow := base.Session.GetValue("intended").(string)
	if allow && intended_route != "" {
		base.Session.SetValue("intended", "")
		http.Redirect(res, req, intended_route, 301)
		return
	}
	http.Redirect(res, req, "/account/manage", 301)
}