示例#1
0
文件: login.go 项目: Chownie/Proggin
func LoadPost(ctx *web.Context, val string) {
	output := ""
	conn, _dberr := sqlite.Open("dbs/blog.db")
	utils.ReportErr(_dberr)

	s, _err := conn.Prepare("SELECT * FROM users WHERE name=?")
	utils.ReportErr(_err)

	password := ctx.Params["password"]
	username := ctx.Params["username"]

	s.Exec(username)
	if s.Next() {
		var user utils.User
		err := s.Scan(&user.Id, &user.Name, &user.Password, &user.Salt)
		utils.ReportErr(err)

		var h hash.Hash = sha256.New()
		h.Write([]byte(password + user.Salt))
		if string(h.Sum()) == user.Password {
			fmt.Println("Matching")
			ctx.Redirect(307, "/admin/")
			ctx.SetSecureCookie("id", strconv.Itoa(user.Id), 1*24*60*60)
		}
	} else {
		output = generic(ctx, "")
	}

	conn.Close()

	ctx.WriteString(output)
}
示例#2
0
func LoadPost(ctx *web.Context, val string) {
	username := ctx.Params["username"]
	password := ctx.Params["password"]

	salt := strconv.Itoa64(time.Nanoseconds()) + username

	var h hash.Hash = sha256.New()
	h.Write([]byte(password + salt))

	s, _err := conn.Prepare("INSERT INTO users VALUES(NULL, ?, ?, ?)")
	utils.ReportErr(_err)

	s.Exec(username, string(h.Sum()), salt)
	s.Finalize()
	conn.Close()
	sidebar := utils.Loadmustache("admin.mustache", &map[string]string{})

	//TESTING, REMOVE LATER
	script := "<script type=\"text/javascript\" src=\"../inc/adminref.js\"></script>"
	content := "Welcome to the admin panel, use the control box on your right to control the site content"
	//ENDTESTING

	mapping := map[string]string{"css": "../inc/site.css",
		"title":   "Proggin: Admin panel",
		"sidebar": sidebar,
		"content": content,
		"script":  script}

	output := utils.Loadmustache("frame.mustache", &mapping)
	ctx.WriteString(output)
}