func (handler AuthHandler) signUpCreateHandler(w http.ResponseWriter, r *http.Request) { email := r.FormValue("email") password := r.FormValue("password") user := gu.New(email, password) err := handler.UserStore.Save(*user) if err != nil { fmt.Fprintf(w, "Had trouble creating %s. Error: %v\n", email, err) return } handler.createUserSession(r, w, user) http.Redirect(w, r, handler.AfterSignupPath, http.StatusFound) }
func createAndSignInUser(ts *httptest.Server, authHandler goth.AuthHandler, client http.Client) { user := user.New("*****@*****.**", "password") authHandler.UserStore.Save(*user) resp, err := client.PostForm(ts.URL+"/auth/sign_in", url.Values{"email": {"*****@*****.**"}, "password": {"password"}}) if err != nil { panic(err) } contents, _ := ioutil.ReadAll(resp.Body) defer resp.Body.Close() if !strings.Contains(string(contents), "*****@*****.**") { panic(fmt.Sprintf("Expected response to contain [email protected]: %s", contents)) } }
func TestSigninPostLogsInAndRedirects(t *testing.T) { ts, authHandler := setup() defer cleanup(ts) client := &http.Client{} client.Jar, _ = cookiejar.New(nil) user := user.New("*****@*****.**", "password") authHandler.UserStore.Save(*user) resp, err := client.PostForm(ts.URL+"/auth/sign_in", url.Values{"email": {"*****@*****.**"}, "password": {"password"}}) if err != nil { t.Errorf("Error posting to sign in route: %v", err) return } contents, _ := ioutil.ReadAll(resp.Body) defer resp.Body.Close() if !strings.Contains(string(contents), "*****@*****.**") { t.Errorf("Expected response to contain [email protected]: %s", contents) return } }
func TestHasPassword(t *testing.T) { user := user.New("*****@*****.**", "password") if err := user.HasPassword("password"); err != nil { t.Errorf("Failed to recognize valid password for user, %v.\n", err) } }
func TestSetsPasswordHash(t *testing.T) { user := user.New("*****@*****.**", "password") if user.PasswordHash == nil { t.Errorf("No PasswordHash was created.") } }