Ejemplo n.º 1
0
func ProcessPlayerDelete(res http.ResponseWriter, req *http.Request, base *BaseController) {
	name, err := url.QueryUnescape(mux.Vars(req)["name"])
	if err != nil {
		http.Error(res, "Error processing name url query", 500)
		return
	}
	if !models.CheckCharacterNameOfAccount(name, base.Account.Id) || !models.CheckCharacterAlive(name) {
		http.Redirect(res, req, "/account/manage", 301)
		return
	}
	password := sha1.Sum([]byte(req.PostFormValue("password")))
	if !models.CheckAccountPassword(fmt.Sprintf("%x", password)) {
		base.Session.SetFlash("Password is not correct!", "error")
		http.Redirect(res, req, "/account/manage/delete/"+name, 301)
		return
	}
	delete_time := time.Now().Unix() + (86400 * 60)
	err = models.SoftDeletePlayer(delete_time, name)
	if err != nil {
		http.Error(res, "Error while deleting character", 500)
		return
	}
	delete_time_date := time.Unix(delete_time, 0)
	delete_time_string := fmt.Sprintf("%v %v %v, %v:%v:%v", delete_time_date.Month().String()[:3], delete_time_date.Day(), delete_time_date.Year(), delete_time_date.Hour(), delete_time_date.Minute(), delete_time_date.Second())
	views.Parser.ExecuteTemplate(res, "delete_character_success.html", &DeleteCharacterSuccessResponse{"account-manage", name, delete_time_string})
}
Ejemplo n.º 2
0
func ShowPlayerEdit(res http.ResponseWriter, req *http.Request, base *BaseController) {
	name, err := url.QueryUnescape(mux.Vars(req)["name"])
	if err != nil {
		http.Error(res, "Error processing name url query", 500)
		return
	}
	if !models.CheckCharacterNameOfAccount(name, base.Account.Id) || !models.CheckCharacterAlive(name) {
		http.Redirect(res, req, "/account/manage", 301)
		return
	}
	csrf_token := GenerateToken(12)
	base.Session.SetValue("csrf", csrf_token)
	character_info := models.GetCharacterByName(name)
	r := &EditCharacterResponse{"account-manage", character_info, csrf_token, base.Session.GetFlashes("error")}
	views.Parser.ExecuteTemplate(res, "edit_character.html", r)
}
Ejemplo n.º 3
0
func ProcessPlayerEdit(res http.ResponseWriter, req *http.Request, base *BaseController) {
	name, err := url.QueryUnescape(mux.Vars(req)["name"])
	if err != nil {
		http.Error(res, "Error processing name url query", 500)
		return
	}
	captcha_response, err := captcha.Verify(req.PostFormValue("g-recaptcha-response"))
	if err != nil {
		http.Error(res, "Error checking captcha response", 500)
		return
	}
	if !captcha_response {
		base.Session.SetFlash("Wrong captcha response", "error")
		http.Redirect(res, req, "/account/manage/edit/"+name, 301)
		return
	}
	if !models.CheckCharacterNameOfAccount(name, base.Account.Id) || !models.CheckCharacterAlive(name) {
		http.Redirect(res, req, "/account/manage", 301)
		return
	}
	comment := req.PostFormValue("comment")
	if len(comment) > 100 {
		base.Session.SetFlash("Comment is bigger than 100 characters", "error")
		http.Redirect(res, req, "/account/manage/edit/"+name, 301)
		return
	}
	comment_lines := strings.Split(comment, "\n")
	if len(comment_lines) > 10 {
		base.Session.SetFlash("You cant have more than 10 comment lines", "error")
		http.Redirect(res, req, "/account/manage/edit/"+name, 301)
		return
	}
	signature := req.PostFormValue("signature")
	hide := req.PostFormValue("accountvisible")
	err = models.EditCharacter(name, comment, signature, hide)
	if err != nil {
		http.Error(res, "Error editing character", 500)
		return
	}
	views.Parser.ExecuteTemplate(res, "edit_character_success.html", &EditCharacterSuccessResponse{"account-manage"})
}