本文整理汇总了Golang中github.com/kidstuff/auth/authmodel.Manager.GetUser方法的典型用法代码示例。如果您正苦于以下问题:Golang Manager.GetUser方法的具体用法?Golang Manager.GetUser怎么用?Golang Manager.GetUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/kidstuff/auth/authmodel.Manager
的用法示例。
在下文中一共展示了Manager.GetUser方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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")
}
}