Example #1
0
//Post - Form Authentication
func AuthenticateUser(rw http.ResponseWriter, r *http.Request, enc encoding.Encoder) string {
	var err error
	user := customer.CustomerUser{
		Email:    r.FormValue("email"),
		Password: r.FormValue("password"),
	}

	if err = user.AuthenticateUser(); err != nil {
		apierror.GenerateError("Trouble authenticating customer user", err, rw, r)
		return ""
	}

	if err = user.GetLocation(); err != nil {
		apierror.GenerateError("Trouble getting customer user location", err, rw, r)
		return ""
	}

	if err = user.GetKeys(); err != nil {
		apierror.GenerateError("Trouble getting customer user API keys", err, rw, r)
		return ""
	}

	user.GetComnetAccounts()

	var key string
	if len(user.Keys) != 0 {
		key = user.Keys[0].Key
	}

	cust, err := user.GetCustomer(key)
	if err != nil {
		apierror.GenerateError("Trouble getting customer user", err, rw, r)
		return ""
	}

	return encoding.Must(enc.Encode(cust))
}