當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Manager.AddUserDetail方法代碼示例

本文整理匯總了Golang中github.com/kidstuff/auth/authmodel.Manager.AddUserDetail方法的典型用法代碼示例。如果您正苦於以下問題:Golang Manager.AddUserDetail方法的具體用法?Golang Manager.AddUserDetail怎麽用?Golang Manager.AddUserDetail使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/kidstuff/auth/authmodel.Manager的用法示例。


在下文中一共展示了Manager.AddUserDetail方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: testManagerAddUserDetail

// testManagerAddUserDetail check if add user operation work
func testManagerAddUserDetail(t *testing.T, mngr authmodel.Manager, gid string) string {
	code := map[string]string{"tested": "notyet"}
	u, err := mngr.AddUserDetail("[email protected]", "test123edc", true, []string{"testing"}, code, nil, []string{gid})
	if err != nil {
		t.Fatal("cannot update user detail:", err)
	}

	u, err = mngr.FindUser(*u.Id)
	if err != nil {
		t.Fatal("Cannot find user:", err)
	}

	if *u.Approved != true {
		t.Fatal("update user approved failed")
	}

	if len(u.Privileges) != 1 {
		t.Fatal("update user privileges failed")
	}

	if u.Privileges[0] != "testing" {
		t.Fatal("update user privileges failed")
	}

	if u.ConfirmCodes["tested"] != "notyet" {
		t.Fatal("update user confirm code failed")
	}

	if len(u.Groups) != 1 {
		t.Fatal("update user group failed")
	}

	if *u.Groups[0].Id != gid {
		t.Fatal("update user group failed")
	}

	return *u.Id
}
開發者ID:kidstuff,項目名稱:auth-mongo-mngr,代碼行數:39,代碼來源:mngr_test.go

示例2: testManagerFindAllUser

// testManagerFindAllUser add 10 users the do test about partial and projection select
func testManagerFindAllUser(t *testing.T, mngr authmodel.Manager, gid string) {
	users := make([]*authmodel.User, 10)
	var err error
	users[0], err = mngr.AddUser("[email protected]", "testing123edc", true)
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	users[1], err = mngr.AddUser("[email protected]", "testing123edc", true)
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	users[2], err = mngr.AddUser("[email protected]", "testing123edc", true)
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	users[3], err = mngr.AddUser("[email protected]", "testing123edc", true)
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	users[4], err = mngr.AddUser("[email protected]", "testing123edc", true)
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	users[5], err = mngr.AddUser("[email protected]", "testing123edc", true)
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	users[6], err = mngr.AddUser("[email protected]", "testing123edc", true)
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	users[7], err = mngr.AddUser("[email protected]", "testing123edc", true)
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	users[8], err = mngr.AddUserDetail("[email protected]", "testing123edc", true, nil, nil, nil, []string{gid})
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	users[9], err = mngr.AddUserDetail("[email protected]", "testing123edc", true, nil, nil, nil, []string{gid})
	if err != nil {
		t.Fatal("cannot add user", err)
	}

	// get all user at the same time
	// should return the full list of 10 users
	userList, err := mngr.FindAllUser(-1, "", nil, nil)
	if n := len(userList); n != 10 {
		t.Fatal("get all user failed, expect 10 users, found", n)
	}

	// get all user belong to gid
	userList, err = mngr.FindAllUser(-1, "", nil, []string{gid})
	if n := len(userList); n != 2 {
		t.Fatal("get all user with groups id failed, expect 2 users, found", n)
	}

	// get a single user with specific feilds.
	userList, err = mngr.FindAllUser(1, "", []string{"Id", "Approved"}, nil)
	if n := len(userList); n != 1 {
		t.Fatal("get all user failed, expect 1 users, found", n)
	}

	if userList[0].Id == nil || userList[0].Approved == nil {
		t.Fatal("get all user failed retrieve specifiec fields")
	}

	if u := userList[0]; u.Email != nil || u.Pwd != nil || u.LastActivity != nil {
		t.Fatal("get all user failed not retrieved unspecific fields")
	}

	// get a part of user list
	userList1, err := mngr.FindAllUser(5, "", nil, nil)
	if n := len(userList1); n != 5 {
		t.Fatal("get all user failed, expect 5 but got", n)
	}

	// get the other part
	userList2, err := mngr.FindAllUser(5, *userList1[4].Id, nil, nil)
	if n := len(userList2); n != 5 {
		t.Fatal("get all user with offset id failed, expect 5 but got", n)
	}

	// and check if they are "paging" right
	for _, u1 := range userList1 {
		for _, u2 := range userList2 {
			if *u1.Id == *u2.Id {
				t.Fatal("get all user failed with limit and offset")
			}
		}
//.........這裏部分代碼省略.........
開發者ID:kidstuff,項目名稱:auth-mongo-mngr,代碼行數:101,代碼來源:mngr_test.go


注:本文中的github.com/kidstuff/auth/authmodel.Manager.AddUserDetail方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。