• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang authmodel.Manager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/kidstuff/auth/authmodel.Manager的典型用法代码示例。如果您正苦于以下问题:Golang Manager类的具体用法?Golang Manager怎么用?Golang Manager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Manager类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: testManagerDeleteUser

// testManagerDeleteUser check if delete user operation work.
func testManagerDeleteUser(t *testing.T, mngr authmodel.Manager, uid string) {
	err := mngr.DeleteUser(uid)
	if err != nil {
		t.Fatal("delete user failed:", err)
	}

	_, err = mngr.FindUser(uid)
	if err != authmodel.ErrNotFound {
		t.Fatal("delete user not work")
	}
}
开发者ID:kidstuff,项目名称:auth-mongo-mngr,代码行数:12,代码来源:mngr_test.go


示例2: testManagerDeleteGroup

// testManagerDeleteGroup recieve a group id and a user id who belong to that group.
// After group delettion, check if the group infomation of in user account removed or not.
func testManagerDeleteGroup(t *testing.T, mngr authmodel.Manager, gid, uid string) {
	err := mngr.DeleteGroup(gid)
	if err != nil {
		t.Fatal("delete group failed:", err)
	}

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

	if len(u.Groups) > 0 {
		t.Fatal("delete group must remove group info in user")
	}
}
开发者ID:kidstuff,项目名称:auth-mongo-mngr,代码行数:17,代码来源:mngr_test.go


示例3: testManagerAddGroupDetail

// testManagerAddGroupDetail simply check if the create group operation work.
func testManagerAddGroupDetail(t *testing.T, mngr authmodel.Manager) string {
	info := authmodel.GroupInfo{}
	desc := "testing privelege"
	info.Description = &desc
	g1, err := mngr.AddGroupDetail("staff", []string{"testing"}, &info)
	if err != nil {
		t.Fatal("cannot create new group:", err)
	}

	_, err = mngr.AddGroupDetail("staff", nil, nil)
	if err == nil {
		t.Fatal("must check for duplicated group name")
	}

	g1, err = mngr.FindGroup(*g1.Id)
	if err != nil {
		t.Fatal("cannot created group:", err)
	}

	if len(g1.Privileges) != 1 {
		t.Fatal("add group privilege failed")
	}

	if g1.Privileges[0] != "testing" {
		t.Fatal("add group privilege failed")
	}

	if g1.Info == nil || g1.Info.Description == nil || *g1.Info.Description != desc {
		t.Fatal("add group info failed")
	}

	return *g1.Id
}
开发者ID:kidstuff,项目名称:auth-mongo-mngr,代码行数:34,代码来源:mngr_test.go


示例4: 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


示例5: testManagerUpdateUserDetail

// testManagerUpdateUserDetail test update user operation and check the password hash function.
func testManagerUpdateUserDetail(t *testing.T, mngr authmodel.Manager, uid, gid string) {
	ps := "testing12345"
	app := false
	code := map[string]string{"tested": "notyet"}
	err := mngr.UpdateUserDetail(uid, &ps, &app, []string{"testing"}, code, nil, []string{gid})
	if err != nil {
		t.Fatal("cannot update user detail:", err)
	}

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

	if *u.Approved != app {
		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")
	}

	err = mngr.ComparePassword(ps, u.Pwd)
	if err != nil {
		t.Fatal("password hash error:", err)
	}
}
开发者ID:kidstuff,项目名称:auth-mongo-mngr,代码行数:44,代码来源:mngr_test.go


示例6: testManagerAddUser

// testManagerAddUser check if add user work
func testManagerAddUser(t *testing.T, mngr authmodel.Manager) string {
	ps := "zaq123456"
	u1, err := mngr.AddUser("[email protected]", ps, true)
	if err != nil {
		t.Fatal("cannot create new user:", err)
	}

	if u1.LastActivity != u1.Profile.JoinDay || u1.LastActivity == nil {
		t.Fatal("must initial the LastActivity and JoinDay")
	}

	_, err = mngr.AddUser("[email protected]", ps, true)
	if err != authmodel.ErrDuplicateEmail {
		t.Fatal("must check for duplicate email:", err)
	}

	err = mngr.ComparePassword(ps, u1.Pwd)
	if err != nil {
		t.Fatal("password hash error:", err)
	}

	return *u1.Id
}
开发者ID:kidstuff,项目名称:auth-mongo-mngr,代码行数:24,代码来源:mngr_test.go


示例7: testManagerLogin

// testManagerLogin login the same user by uid 3 times to get 3 different tokens.
// Then use them to test the Logout method.
func testManagerLogin(t *testing.T, mngr authmodel.Manager, uid string) {
	token, err := mngr.Login(uid, time.Minute)
	if err != nil {
		t.Fatal("cannot login:", err)
	}

	u, err := mngr.GetUser(token)
	if err != nil {
		t.Fatal("cannot get logged user:", err)
	}

	if *u.Id != uid {
		t.Fatal("loged user and user returned not the same")
	}

	token2, err := mngr.Login(uid, time.Minute)
	if err != nil {
		t.Fatal("cannot login:", err)
	}

	u, err = mngr.GetUser(token2)
	if err != nil {
		t.Fatal("cannot get logged user:", err)
	}

	if *u.Id != uid {
		t.Fatal("loged user and user returned not the same")
	}

	token3, err := mngr.Login(uid, time.Minute)
	if err != nil {
		t.Fatal("cannot login:", err)
	}

	u, err = mngr.GetUser(token3)
	if err != nil {
		t.Fatal("cannot get logged user:", err)
	}

	if *u.Id != uid {
		t.Fatal("loged user and user returned not the same")
	}

	if token == token2 || token2 == token3 || token == token3 {
		t.Fatal("token must not be the same")
	}

	err = mngr.Logout(token, false)
	if err != nil {
		t.Fatal("cannot logout user:", err)
	}

	u, err = mngr.GetUser(token)
	if err == nil || u != nil {
		t.Fatal("logout don't work")
	}

	err = mngr.Logout(token2, true)
	if err != nil {
		t.Fatal("cannot logout user:", err)
	}

	u, err = mngr.GetUser(token2)
	if err == nil || u != nil {
		t.Fatal("logout didn't work")
	}

	u, err = mngr.GetUser(token3)
	if err == nil || u != nil {
		t.Fatal("logout all user's session didn't work")
	}
}
开发者ID:kidstuff,项目名称:auth-mongo-mngr,代码行数:74,代码来源:mngr_test.go


示例8: 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类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang sound.Context类代码示例发布时间:2022-05-23
下一篇:
Golang embd.NewI2CBus函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap