예제 #1
0
파일: auth.go 프로젝트: gaego/auth
// CreateAndLogin does the following:
//
//  - Search for an existing user - session -> Profile -> email address
//  - Saves the Profile to the datastore
//  - Creates a User or appends the AuthID to the Requesting user's account
//  - Logs in the User
//  - Adds the admin role to the User if they are an GAE Admin.
func CreateAndLogin(w http.ResponseWriter, r *http.Request,
	p *profile.Profile) (u *user.User, err error) {
	c := context.NewContext(r)
	if u, err = p.UpdateUser(w, r); err != nil {
		return
	}
	if err = user.CurrentUserSetID(w, r, p.UserID); err != nil {
		return
	}
	err = p.Put(c)
	return
}
예제 #2
0
파일: provider_test.go 프로젝트: gaego/auth
// Scenario #3:
// - Yes User session
// - No Email Saved
// - No Profile Saved
func TestAuthenticate_Scenario3(t *testing.T) {
	pro := setup()
	defer tearDown()

	var pf *profile.Profile
	var uRL string
	var err error
	var v url.Values
	var r *http.Request

	//c := context.NewContext(nil)
	w := httptest.NewRecorder()

	// Setup.
	v = url.Values{}
	v.Set("Email", "*****@*****.**")
	v.Set("Password.New", "secret1")
	v.Set("Name.GivenName", "Bob")
	r = createRequest(v)
	_ = user.CurrentUserSetID(w, r, "1001")

	// Check.
	if pf, uRL, err = pro.Authenticate(w, r); uRL != "" || err != nil {
		t.Errorf(`url: %v, want: ""`, uRL)
		t.Errorf(`err: %v, want: %v`, err, nil)
	}
	if x := pf.Person.Name.GivenName; x != "Bob" {
		t.Errorf(`pf.Person should be updated`)
	}
	if x := pf.UserID; x != "1001" {
		t.Errorf(`pf.UserID: %v, want %v`, x, "1001")
	}
	if pf.UserID != "1001" {
		t.Errorf(`pf.UserID: %v, want: %v`, pf.UserID, "1001")
	}
}