示例#1
0
文件: context.go 项目: kiwih/heyfyi
func (c *Context) DoPasswordResetRequestHandler(rw web.ResponseWriter, req *web.Request) {

	req.ParseForm()

	var p ResetPasswordForm

	if err := decoder.Decode(&p, req.PostForm); err != nil {
		c.SetErrorMessage(rw, req, "Decoding error: "+err.Error())
		http.Redirect(rw, req.Request, ResetPasswordUrl.Make(), http.StatusSeeOther)
		return
	}

	accountIdStr, ok := req.PathParams["accountId"]
	if !ok {
		http.Error(rw, "400: Bad account ID", http.StatusBadRequest)
		//next(rw, req)
		return
	}

	resetVerificationCode, ok := req.PathParams["resetVerificationCode"]
	if !ok {
		http.Error(rw, "400: Bad verification code", http.StatusBadRequest)
		return
	}

	if p.Password != p.ConfirmPassword {
		c.SetErrorMessage(rw, req, "Your passwords don't match!")
		http.Redirect(rw, req.Request, ResetPasswordUrl.Make("accountId", accountIdStr, "resetVerificationCode", resetVerificationCode), http.StatusSeeOther)
		return
	}

	//get the account ID from the URL
	accountId, err := strconv.ParseInt(accountIdStr, 10, 64)
	if err != nil {
		http.Error(rw, "400: Bad account ID", http.StatusBadRequest)
		return
	}

	a, err := c.Storage.LoadAccountFromId(accountId)
	if err != nil {
		http.Error(rw, "404: Account not found", http.StatusNotFound)
		return
	}

	if err := a.ApplyPasswordResetVerificationCode(c.Storage, resetVerificationCode, p.Password); err != nil {
		c.SetErrorMessage(rw, req, err.Error())
		http.Redirect(rw, req.Request, ResetPasswordUrl.Make("accountId", accountIdStr, "resetVerificationCode", resetVerificationCode), http.StatusSeeOther)
		return
	}

	c.SetNotificationMessage(rw, req, "Password reset - you may now sign in!")
	http.Redirect(rw, req.Request, HomeUrl.Make(), http.StatusFound)
}
示例#2
0
func (c *Context) convertSQL(rw web.ResponseWriter, req *web.Request) {

	// Check for POST
	if req.Request.Method == "POST" {
		req.ParseForm()
		c.RawSQL = req.Request.FormValue("clsql")
		c.ConvertedSQL = Convert(c.RawSQL)
	} else {
		// Add default
		c.RawSQL = defaultRawSQL
	}

	rend.HTML(rw, http.StatusOK, "index", c)
}
示例#3
0
文件: context.go 项目: kiwih/heyfyi
func (c *Context) DoBeginPasswordResetRequestHandler(rw web.ResponseWriter, req *web.Request) {
	req.ParseForm()

	var p PasswordResetRequestForm

	if err := decoder.Decode(&p, req.PostForm); err != nil {
		c.SetErrorMessage(rw, req, "Decoding error: "+err.Error())
		http.Redirect(rw, req.Request, ResetPasswordUrl.Make(), http.StatusSeeOther)
		return
	}

	account.DoPasswordResetRequestIfPossible(c.Storage, p.Email)

	c.SetNotificationMessage(rw, req, "Password reset requested.")
	http.Redirect(rw, req.Request, HomeUrl.Make(), http.StatusFound)

}
示例#4
0
文件: context.go 项目: kiwih/heyfyi
func (c *Context) DoSignUpHandler(rw web.ResponseWriter, req *web.Request) {

	req.ParseForm()

	var u CreateAccount

	if err := decoder.Decode(&u, req.PostForm); err != nil {
		c.SetErrorMessage(rw, req, "Decoding error: "+err.Error())
		http.Redirect(rw, req.Request, SignUpUrl.Make(), http.StatusSeeOther)
		return
	}

	if u.Password != u.ConfirmPassword {
		c.SetFailedRequestObject(rw, req, u)
		c.SetErrorMessage(rw, req, "Your passwords don't match!")
		http.Redirect(rw, req.Request, SignUpUrl.Make(), http.StatusSeeOther)
		return
	}

	if u.TermsCB != true {
		c.SetFailedRequestObject(rw, req, u)
		c.SetErrorMessage(rw, req, "You must accept the terms and conditions!")
		http.Redirect(rw, req.Request, SignUpUrl.Make(), http.StatusSeeOther)
		return
	}

	if err := account.CheckAndCreateAccount(c.Storage, u.Email, u.Password, u.Nickname); err != nil {
		c.SetFailedRequestObject(rw, req, u)
		c.SetErrorMessage(rw, req, err.Error())
		http.Redirect(rw, req.Request, SignUpUrl.Make(), http.StatusSeeOther)
		return
	}

	c.SetNotificationMessage(rw, req, "Your account has been created. Please wait for your verification email, verify, and then you can sign in!")
	http.Redirect(rw, req.Request, HomeUrl.Make(), http.StatusFound)
}
示例#5
0
文件: context.go 项目: kiwih/heyfyi
func (c *Context) DoSignInRequestHandler(rw web.ResponseWriter, req *web.Request) {
	req.ParseForm()

	var prop LoginRequestForm
	if err := decoder.Decode(&prop, req.PostForm); err != nil {
		c.SetErrorMessage(rw, req, "Decoding error: "+err.Error())
		http.Redirect(rw, req.Request, SignUpUrl.Make(), http.StatusSeeOther)
		return
	}

	propUser, err := account.AttemptLogin(c.Storage, prop.Email, prop.Password, prop.Remember)

	if propUser != nil {
		//they have passed the login check. Save them to the session and redirect to management portal
		session, _ := c.Store.Get(req.Request, "session-security")
		session.Values["sessionId"] = propUser.CurrentSession.String
		c.SetNotificationMessage(rw, req, "Hi, "+propUser.Nickname+".")
		session.Save(req.Request, rw)
		http.Redirect(rw, req.Request, HomeUrl.Make(), http.StatusFound)
		return
	}
	c.SetErrorMessage(rw, req, err.Error())
	http.Redirect(rw, req.Request, HomeUrl.Make(), http.StatusSeeOther)
}
示例#6
0
func (c *Context) DoCreateFactHandler(rw web.ResponseWriter, req *web.Request) {

	req.ParseForm()

	var f fact.Fact

	if err := decoder.Decode(&f, req.PostForm); err != nil {
		c.SetErrorMessage(rw, req, "Decoding error: "+err.Error())
		http.Redirect(rw, req.Request, CreateFactUrl.Make(), http.StatusSeeOther)
		return
	}

	f.AccountId = c.Account.Id

	if err := fact.CreateFact(c.Storage, &f); err != nil {
		c.SetFailedRequestObject(rw, req, f)
		c.SetErrorMessage(rw, req, err.Error())
		http.Redirect(rw, req.Request, CreateFactUrl.Make(), http.StatusSeeOther)
		return
	}

	c.SetNotificationMessage(rw, req, "Fact submitted successfully!")
	http.Redirect(rw, req.Request, ViewFactUrl.Make("factId", strconv.FormatInt(f.Id, 10)), http.StatusFound)
}