示例#1
0
文件: handlers.go 项目: jroes/goth
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)
}
示例#2
0
文件: goth_test.go 项目: jroes/goth
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))
	}
}
示例#3
0
文件: goth_test.go 项目: jroes/goth
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
	}
}
示例#4
0
文件: user_test.go 项目: jroes/goth
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)
	}
}
示例#5
0
文件: user_test.go 项目: jroes/goth
func TestSetsPasswordHash(t *testing.T) {
	user := user.New("*****@*****.**", "password")
	if user.PasswordHash == nil {
		t.Errorf("No PasswordHash was created.")
	}
}