예제 #1
0
파일: installer.go 프로젝트: Cloakaac/core
func ProcessInstaller(res http.ResponseWriter, req *http.Request, base *BaseController) {
	if !strings.Contains(req.RemoteAddr, "127.0.0.1") || strings.Contains(req.RemoteAddr, "::1") {
		http.Error(res, "You can only access the installer from your localhost", 500)
		return
	}
	town_name := req.PostFormValue("town")
	account_name := req.PostFormValue("account")
	account_password := req.PostFormValue("password")
	account_email := req.PostFormValue("email")
	character_name := req.PostFormValue("character")
	character_gender := SexToInt(req.PostFormValue("gender"))
	character_vocation := VocationToInt(req.PostFormValue("vocation"))
	err := models.CreateCloakaTables()
	if err != nil {
		http.Error(res, "Error while creating cloaka tables: "+err.Error(), 500)
		return
	}
	err = models.AddTown(town_name, 1)
	if err != nil {
		http.Error(res, "Error while creating town: "+err.Error(), 500)
		return
	}
	sha1password := sha1.Sum([]byte(account_password))
	account_token, err := GenerateLoginToken(15)
	if err != nil {
		http.Error(res, "Error while creating login token", 500)
		return
	}
	err = models.RegisterAccount(
		account_name,
		fmt.Sprintf("%x", sha1password),
		123,
		account_email,
		time.Now().Unix(),
		character_name,
		character_gender,
		character_vocation,
		1,
		account_token,
		1,
	)
	if err != nil {
		http.Error(res, "Error while creating admin account and character: "+err.Error(), 500)
		return
	}
	err = models.CreateArticle("Cloak AAC - Installed", "Cloak AAC was installed successfully!", time.Now().Unix())
	if err != nil {
		http.Error(res, "Error while creating installed article: "+err.Error(), 500)
		return
	}
	base.Session.SetValue("logged", "true")
	base.Session.SetValue("token", account_token)
	res.Write([]byte("Cloaka installed! Restart the app"))
}
예제 #2
0
파일: admin.go 프로젝트: Cloakaac/core
func ProcessAdminNewsCreate(res http.ResponseWriter, req *http.Request, base *BaseController) {
	title := req.PostFormValue("title")
	text := req.PostFormValue("text")
	err := models.CreateArticle(title, text, time.Now().Unix())
	if err != nil {
		http.Error(res, "Error while creating article: "+err.Error(), 500)
		return
	}
	base.Session.SetFlash("Article created successfully!", "success")
	http.Redirect(res, req, "/admin/news", 301)
}