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


Golang session.User函數代碼示例

本文整理匯總了Golang中github.com/drone/drone/router/middleware/session.User函數的典型用法代碼示例。如果您正苦於以下問題:Golang User函數的具體用法?Golang User怎麽用?Golang User使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: PatchUser

func PatchUser(c *gin.Context) {
	me := session.User(c)
	in := &model.User{}
	err := c.Bind(in)
	if err != nil {
		c.AbortWithStatus(http.StatusBadRequest)
		return
	}

	user, err := store.GetUserLogin(c, c.Param("login"))
	if err != nil {
		c.AbortWithStatus(http.StatusNotFound)
		return
	}
	user.Admin = in.Admin
	user.Active = in.Active

	// cannot update self
	if me.ID == user.ID {
		c.AbortWithStatus(http.StatusForbidden)
		return
	}

	err = store.UpdateUser(c, user)
	if err != nil {
		c.AbortWithStatus(http.StatusConflict)
		return
	}

	c.IndentedJSON(http.StatusOK, user)
}
開發者ID:fclairamb,項目名稱:drone,代碼行數:31,代碼來源:users.go

示例2: ShowRepo

func ShowRepo(c *gin.Context) {
	user := session.User(c)
	repo := session.Repo(c)

	builds, _ := store.GetBuildList(c, repo)
	groups := []*model.BuildGroup{}

	var curr *model.BuildGroup
	for _, build := range builds {
		date := time.Unix(build.Created, 0).Format("Jan 2 2006")
		if curr == nil || curr.Date != date {
			curr = &model.BuildGroup{}
			curr.Date = date
			groups = append(groups, curr)
		}
		curr.Builds = append(curr.Builds, build)
	}

	httputil.SetCookie(c.Writer, c.Request, "user_last", repo.FullName)

	c.HTML(200, "repo.html", gin.H{
		"User":   user,
		"Repo":   repo,
		"Builds": builds,
		"Groups": groups,
	})

}
開發者ID:defconcepts,項目名稱:drone,代碼行數:28,代碼來源:pages.go

示例3: GetRepos

func GetRepos(c *gin.Context) {
	user := session.User(c)
	remote := remote.FromContext(c)
	var repos []*model.RepoLite

	// get the repository list from the cache
	reposv, ok := c.Get("repos")
	if ok {
		repos = reposv.([]*model.RepoLite)
	} else {
		var err error
		repos, err = remote.Repos(user)
		if err != nil {
			c.AbortWithStatus(http.StatusInternalServerError)
			return
		}
	}

	// for each repository in the remote system we get
	// the intersection of those repostiories in Drone
	repos_, err := store.GetRepoListOf(c, repos)
	if err != nil {
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}

	c.Set("repos", repos)
	c.IndentedJSON(http.StatusOK, repos_)
}
開發者ID:fclairamb,項目名稱:drone,代碼行數:29,代碼來源:user.go

示例4: ShowIndex

func ShowIndex(c *gin.Context) {
	user := session.User(c)
	if user == nil {
		c.Redirect(http.StatusSeeOther, "/login")
		return
	}

	// get the repository list from the cache
	repos, err := cache.GetRepos(c, user)
	if err != nil {
		c.String(400, err.Error())
		return
	}

	// filter to only show the currently active ones
	activeRepos, err := store.GetRepoListOf(c, repos)
	if err != nil {
		c.String(400, err.Error())
		return
	}

	c.HTML(200, "index.html", gin.H{
		"User":  user,
		"Repos": activeRepos,
	})
}
開發者ID:tnaoto,項目名稱:drone,代碼行數:26,代碼來源:pages.go

示例5: GetFeed

func GetFeed(c *gin.Context) {
	user := session.User(c)
	remote := remote.FromContext(c)
	var repos []*model.RepoLite

	// get the repository list from the cache
	reposv, ok := c.Get("repos")
	if ok {
		repos = reposv.([]*model.RepoLite)
	} else {
		var err error
		repos, err = remote.Repos(user)
		if err != nil {
			c.String(400, err.Error())
			return
		}
	}

	feed, err := store.GetUserFeed(c, repos)
	if err != nil {
		c.String(400, err.Error())
		return
	}
	c.JSON(200, feed)
}
開發者ID:fclairamb,項目名稱:drone,代碼行數:25,代碼來源:user.go

示例6: GetRemoteRepos

func GetRemoteRepos(c *gin.Context) {
	repos, err := cache.GetRepos(c, session.User(c))
	if err != nil {
		c.String(500, "Error fetching repository list. %s", err)
		return
	}
	c.JSON(http.StatusOK, repos)
}
開發者ID:tnaoto,項目名稱:drone,代碼行數:8,代碼來源:user.go

示例7: ShowRepoBadges

func ShowRepoBadges(c *gin.Context) {
	user := session.User(c)
	repo := session.Repo(c)

	c.HTML(200, "repo_badge.html", gin.H{
		"User": user,
		"Repo": repo,
		"Link": httputil.GetURL(c.Request),
	})
}
開發者ID:defconcepts,項目名稱:drone,代碼行數:10,代碼來源:pages.go

示例8: PostToken

func PostToken(c *gin.Context) {
	user := session.User(c)

	token := token.New(token.UserToken, user.Login)
	tokenstr, err := token.Sign(user.Hash)
	if err != nil {
		c.AbortWithError(http.StatusInternalServerError, err)
	} else {
		c.String(http.StatusOK, tokenstr)
	}
}
開發者ID:fclairamb,項目名稱:drone,代碼行數:11,代碼來源:user.go

示例9: GetRemoteRepos

func GetRemoteRepos(c *gin.Context) {
	user := session.User(c)

	repos, err := cache.GetRepos(c, user)
	if err != nil {
		c.AbortWithStatus(http.StatusInternalServerError)
		return
	}

	c.IndentedJSON(http.StatusOK, repos)
}
開發者ID:clanstyles,項目名稱:drone,代碼行數:11,代碼來源:user.go

示例10: ChownRepo

func ChownRepo(c *gin.Context) {
	repo := session.Repo(c)
	user := session.User(c)
	repo.UserID = user.ID

	err := store.UpdateRepo(c, repo)
	if err != nil {
		c.AbortWithError(http.StatusInternalServerError, err)
		return
	}
	c.JSON(http.StatusOK, repo)
}
開發者ID:Ablu,項目名稱:drone,代碼行數:12,代碼來源:repo.go

示例11: ShowUser

func ShowUser(c *gin.Context) {
	user := session.User(c)
	token, _ := token.New(
		token.CsrfToken,
		user.Login,
	).Sign(user.Hash)

	c.HTML(200, "user.html", gin.H{
		"User": user,
		"Csrf": token,
	})
}
開發者ID:defconcepts,項目名稱:drone,代碼行數:12,代碼來源:pages.go

示例12: GetRepos

func GetRepos(c *gin.Context) {
	var (
		user     = session.User(c)
		all, _   = strconv.ParseBool(c.Query("all"))
		flush, _ = strconv.ParseBool(c.Query("flush"))
	)

	if flush {
		log.Debugf("Evicting repository cache for user %s.", user.Login)
		cache.DeleteRepos(c, user)
	}

	remote, err := cache.GetRepos(c, user)
	if err != nil {
		c.String(500, "Error fetching repository list. %s", err)
		return
	}

	repos, err := store.GetRepoListOf(c, remote)
	if err != nil {
		c.String(500, "Error fetching repository list. %s", err)
		return
	}

	if !all {
		c.JSON(http.StatusOK, repos)
		return
	}

	// below we combine the two lists to include both active and inactive
	// repositories. This is displayed on the settings screen to enable
	// toggling on / off repository settings.

	repom := map[string]bool{}
	for _, repo := range repos {
		repom[repo.FullName] = true
	}

	for _, repo := range remote {
		if repom[repo.FullName] {
			continue
		}
		repos = append(repos, &model.Repo{
			Avatar:   repo.Avatar,
			FullName: repo.FullName,
			Owner:    repo.Owner,
			Name:     repo.Name,
		})
	}
	c.JSON(http.StatusOK, repos)
}
開發者ID:Ablu,項目名稱:drone,代碼行數:51,代碼來源:user.go

示例13: DeleteRepo

func DeleteRepo(c *gin.Context) {
	remote := remote.FromContext(c)
	repo := session.Repo(c)
	user := session.User(c)

	err := store.DeleteRepo(c, repo)
	if err != nil {
		c.AbortWithError(http.StatusInternalServerError, err)
		return
	}

	remote.Deactivate(user, repo, httputil.GetURL(c.Request))
	c.Writer.WriteHeader(http.StatusOK)
}
開發者ID:tnaoto,項目名稱:drone,代碼行數:14,代碼來源:repo.go

示例14: GetFeed

func GetFeed(c *gin.Context) {
	repos, err := cache.GetRepos(c, session.User(c))
	if err != nil {
		c.String(500, "Error fetching repository list. %s", err)
		return
	}

	feed, err := store.GetUserFeed(c, repos)
	if err != nil {
		c.String(500, "Error fetching feed. %s", err)
		return
	}
	c.JSON(200, feed)
}
開發者ID:tnaoto,項目名稱:drone,代碼行數:14,代碼來源:user.go

示例15: ShowRepoEncrypt

func ShowRepoEncrypt(c *gin.Context) {
	user := session.User(c)
	repo := session.Repo(c)

	token, _ := token.New(
		token.CsrfToken,
		user.Login,
	).Sign(user.Hash)

	c.HTML(200, "repo_secret.html", gin.H{
		"User": user,
		"Repo": repo,
		"Csrf": token,
	})
}
開發者ID:defconcepts,項目名稱:drone,代碼行數:15,代碼來源:pages.go


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