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

Golang account.User类代码示例

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

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



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

示例1: TestAppInfoNotMember

func (s *S) TestAppInfoNotMember(c *C) {
	alice := account.User{Name: "alice", Email: "[email protected]", Password: "secret"}
	alice.Create()
	t := account.Team{Name: "example"}
	t.Create(alice)
	app.Create(alice, t)

	defer func() {
		ap, _ := s.store.FindAppByClientId(app.ClientId)
		s.store.DeleteApp(ap)
		s.store.DeleteTeamByAlias(t.Alias)
		alice.Delete()
	}()

	headers, code, body, _ := httpClient.MakeRequest(requests.Args{
		AcceptableCode: http.StatusForbidden,
		Method:         "GET",
		Path:           fmt.Sprintf("/api/apps/%s", app.ClientId),
		Headers:        http.Header{"Authorization": {s.authHeader}},
	})

	c.Assert(code, Equals, http.StatusForbidden)
	c.Assert(headers.Get("Content-Type"), Equals, "application/json")
	c.Assert(string(body), Equals, `{"error":"access_denied","error_description":"You do not belong to this team!"}`)
}
开发者ID:sinzone,项目名称:apihub,代码行数:25,代码来源:apps_test.go


示例2: TestUpdateServiceNotMember

func (s *S) TestUpdateServiceNotMember(c *C) {
	alice := account.User{Name: "alice", Email: "[email protected]", Password: "secret"}
	alice.Create()
	t := account.Team{Name: "example"}
	t.Create(alice)
	service.Create(alice, t)
	defer func() {
		serv, _ := s.store.FindServiceBySubdomain(service.Subdomain)
		s.store.DeleteService(serv)
		s.store.DeleteTeamByAlias(t.Alias)
		alice.Delete()
	}()

	headers, code, body, _ := httpClient.MakeRequest(requests.Args{
		AcceptableCode: http.StatusOK,
		Method:         "PUT",
		Path:           fmt.Sprintf("/api/services/%s", service.Subdomain),
		Body:           `{}`,
		Headers:        http.Header{"Authorization": {s.authHeader}},
	})

	c.Assert(code, Equals, http.StatusForbidden)
	c.Assert(headers.Get("Content-Type"), Equals, "application/json")
	c.Assert(string(body), Equals, `{"error":"access_denied","error_description":"You do not belong to this team!"}`)
}
开发者ID:sinzone,项目名称:apihub,代码行数:25,代码来源:services_test.go


示例3: TestAuthenticateWithInvalidCredentials

func (s *AuthenticatableSuite) TestAuthenticateWithInvalidCredentials(c *C) {
	user := account.User{Name: "Alice", Email: "[email protected]", Password: "123"}
	user.Create()
	defer user.Delete()

	_, ok := s.Auth.Authenticate(user.Email, "invalid-password")
	c.Assert(ok, Equals, false)
}
开发者ID:sinzone,项目名称:apihub,代码行数:8,代码来源:suite.go


示例4: userSignup

func (api *Api) userSignup(rw http.ResponseWriter, r *http.Request) {
	user := account.User{}
	if err := json.NewDecoder(r.Body).Decode(&user); err != nil {
		handleError(rw, errors.ErrBadRequest)
		return
	}

	if err := user.Create(); err != nil {
		handleError(rw, err)
		return
	}
	// Remove hashed-password from response.
	user.Password = ""

	Created(rw, user)
}
开发者ID:sinzone,项目名称:apihub,代码行数:16,代码来源:users.go


示例5: TestDeleteAppWithoutPermission

func (s *S) TestDeleteAppWithoutPermission(c *C) {
	alice := account.User{Name: "alice", Email: "[email protected]", Password: "secret"}
	alice.Create()
	defer alice.Delete()

	app.Create(alice, team)
	defer func() {
		ap, _ := s.store.FindAppByClientId(app.ClientId)
		s.store.DeleteApp(ap)
	}()

	headers, code, body, _ := httpClient.MakeRequest(requests.Args{
		AcceptableCode: http.StatusForbidden,
		Method:         "DELETE",
		Path:           fmt.Sprintf("/api/apps/%s", app.ClientId),
		Headers:        http.Header{"Authorization": {s.authHeader}},
	})

	c.Assert(code, Equals, http.StatusForbidden)
	c.Assert(headers.Get("Content-Type"), Equals, "application/json")
	c.Assert(string(body), Equals, `{"error":"access_denied","error_description":"Only the owner has permission to perform this operation."}`)
}
开发者ID:sinzone,项目名称:apihub,代码行数:22,代码来源:apps_test.go


示例6: TestTeamInfoWithoutPermission

func (s *S) TestTeamInfoWithoutPermission(c *C) {
	alice := account.User{Name: "alice", Email: "[email protected]", Password: "secret"}
	alice.Create()
	defer alice.Delete()

	team := account.Team{Name: "ApiHub Team", Alias: "apihub"}
	team.Create(alice)
	defer func() {
		s.store.DeleteTeamByAlias(team.Alias)
	}()

	headers, code, body, _ := httpClient.MakeRequest(requests.Args{
		AcceptableCode: http.StatusForbidden,
		Method:         "GET",
		Path:           fmt.Sprintf("/api/teams/%s", team.Alias),
		Headers:        http.Header{"Authorization": {s.authHeader}},
	})

	c.Assert(code, Equals, http.StatusForbidden)
	c.Assert(headers.Get("Content-Type"), Equals, "application/json")
	c.Assert(string(body), Equals, `{"error":"access_denied","error_description":"You do not belong to this team!"}`)
}
开发者ID:sinzone,项目名称:apihub,代码行数:22,代码来源:teams_test.go


示例7: TestRemoveUser

func (s *S) TestRemoveUser(c *C) {
	alice := account.User{Name: "alice", Email: "[email protected]", Password: "secret"}
	alice.Create()
	defer alice.Delete()

	team := account.Team{Name: "ApiHub Team", Alias: "apihub", Users: []string{alice.Email}}
	team.Create(user)
	defer func() {
		s.store.DeleteTeamByAlias(team.Alias)
	}()

	headers, code, body, _ := httpClient.MakeRequest(requests.Args{
		AcceptableCode: http.StatusOK,
		Method:         "DELETE",
		Path:           fmt.Sprintf("/api/teams/%s/users", team.Alias),
		Headers:        http.Header{"Authorization": {s.authHeader}},
		Body:           fmt.Sprintf(`{"users": ["%s"]}`, alice.Email),
	})

	c.Assert(code, Equals, http.StatusOK)
	c.Assert(headers.Get("Content-Type"), Equals, "application/json")
	c.Assert(string(body), Equals, `{"name":"ApiHub Team","alias":"apihub","users":["[email protected]"],"owner":"[email protected]"}`)
}
开发者ID:sinzone,项目名称:apihub,代码行数:23,代码来源:teams_test.go


示例8: TestCreateUserWithoutRequiredFields

func (s *S) TestCreateUserWithoutRequiredFields(c *C) {
	user := account.User{}
	err := user.Create()
	_, ok := err.(errors.ValidationError)
	c.Assert(ok, Equals, true)
}
开发者ID:sinzone,项目名称:apihub,代码行数:6,代码来源:user_test.go


示例9: teamList

func (api *Api) teamList(rw http.ResponseWriter, r *http.Request, user *account.User) {
	teams, _ := user.Teams()
	Ok(rw, CollectionSerializer{Items: teams, Count: len(teams)})
}
开发者ID:sinzone,项目名称:apihub,代码行数:4,代码来源:teams.go


示例10: serviceList

func (api *Api) serviceList(rw http.ResponseWriter, r *http.Request, user *account.User) {
	services, _ := user.Services()
	Ok(rw, CollectionSerializer{Items: services, Count: len(services)})
}
开发者ID:sinzone,项目名称:apihub,代码行数:4,代码来源:services.go



注:本文中的github.com/apihub/apihub/account.User类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang errors.NewNotFoundError函数代码示例发布时间:2022-05-24
下一篇:
Golang account.Team类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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