Esempio n. 1
0
func ResetPassword(rw http.ResponseWriter, r *http.Request, enc encoding.Encoder) string {
	var err error

	email := r.FormValue("email")
	custID := r.FormValue("customerID")
	site := r.FormValue("site")

	if email == "" {
		err = errors.New("No email address provided")
		apierror.GenerateError("No email address provided", err, rw, r)
		return ""
	}
	if custID == "" {
		err = errors.New("Customer ID cannot be blank")
		apierror.GenerateError("Customer ID cannot be blank", err, rw, r)
		return ""
	}

	var user customer.CustomerUser
	user.Email = email
	user.CustID, err = strconv.Atoi(custID)
	if err != nil {
		apierror.GenerateError("Trouble parsing cust ID", err, rw, r)
		return ""
	}

	resp, err := user.ResetPass()
	if err != nil || resp == "" {
		apierror.GenerateError("Trouble resetting user password", err, rw, r)
		return ""
	}

	//email
	subject := "Your Password Has Been Reset"
	body := `<p>Here is your new password for the ` + site + ` site.</p> 
	<p>Password: ` + resp + `</p><p> If you did not request this password, please contact <a href="mailto:[email protected]">Web Support</a></p>
	<p>Thanks, </p>
	<p>The Ecommerce Developer Team</P>`
	err = emailHelper.Send([]string{email}, subject, body, true)
	if err != nil {
		apierror.GenerateError("Trouble emailing new user password", err, rw, r)
		return ""
	}

	return encoding.Must(enc.Encode("success"))
}