当前位置: 首页>>代码示例>>Golang>>正文


Golang models.User类代码示例

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


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

示例1: checkUserFollowing

func checkUserFollowing(ctx *context.APIContext, u *models.User, followID int64) {
	if u.IsFollowing(followID) {
		ctx.Status(204)
	} else {
		ctx.Status(404)
	}
}
开发者ID:CarloQ,项目名称:gogs,代码行数:7,代码来源:follower.go

示例2: SendIssueMentionMail

// SendIssueMentionMail sends mail notification for who are mentioned in issue.
func SendIssueMentionMail(r macaron.Render, u, owner *models.User,
	repo *models.Repository, issue *models.Issue, tos []string) error {

	if len(tos) == 0 {
		return nil
	}

	subject := fmt.Sprintf("[%s] %s (#%d)", repo.Name, issue.Name, issue.Index)

	data := ComposeTplData(nil)
	data["IssueLink"] = fmt.Sprintf("%s/%s/issues/%d", owner.Name, repo.Name, issue.Index)
	data["Subject"] = subject
	data["ActUserName"] = u.DisplayName()
	data["Content"] = string(base.RenderSpecialLink([]byte(issue.Content), owner.Name+"/"+repo.Name, repo.ComposeMetas()))

	body, err := r.HTMLString(string(NOTIFY_MENTION), data)
	if err != nil {
		return fmt.Errorf("HTMLString: %v", err)
	}

	msg := NewMessage(tos, subject, body)
	msg.Info = fmt.Sprintf("Subject: %s, issue mention", subject)

	SendAsync(msg)
	return nil
}
开发者ID:cuteluo1983,项目名称:gogs,代码行数:27,代码来源:mail.go

示例3: UpdateAvatarSetting

// FIXME: limit size.
func UpdateAvatarSetting(ctx *middleware.Context, form auth.UploadAvatarForm, ctxUser *models.User) error {
	ctxUser.UseCustomAvatar = form.Enable

	if form.Avatar != nil {
		fr, err := form.Avatar.Open()
		if err != nil {
			return fmt.Errorf("Avatar.Open: %v", err)
		}

		data, err := ioutil.ReadAll(fr)
		if err != nil {
			return fmt.Errorf("ReadAll: %v", err)
		}
		if _, ok := base.IsImageFile(data); !ok {
			return errors.New(ctx.Tr("settings.uploaded_avatar_not_a_image"))
		}
		if err = ctxUser.UploadAvatar(data); err != nil {
			return fmt.Errorf("UploadAvatar: %v", err)
		}
	} else {
		// In case no avatar at all.
		if form.Enable && !com.IsFile(ctx.User.CustomAvatarPath()) {
			return errors.New(ctx.Tr("settings.no_custom_avatar_available"))
		}
	}

	if err := models.UpdateUser(ctxUser); err != nil {
		return fmt.Errorf("UpdateUser: %v", err)
	}

	return nil
}
开发者ID:kiliit,项目名称:gogs,代码行数:33,代码来源:setting.go

示例4: Delete

func Delete(ctx *middleware.Context) {
	ctx.Data["Title"] = "Delete Account"
	ctx.Data["PageIsUserSetting"] = true
	ctx.Data["IsUserPageSettingDelete"] = true

	if ctx.Req.Method == "GET" {
		ctx.HTML(200, "user/delete")
		return
	}

	tmpUser := models.User{Passwd: ctx.Query("password")}
	tmpUser.EncodePasswd()
	if len(tmpUser.Passwd) == 0 || tmpUser.Passwd != ctx.User.Passwd {
		ctx.Data["HasError"] = true
		ctx.Data["ErrorMsg"] = "Password is not correct. Make sure you are owner of this account."
	} else {
		if err := models.DeleteUser(ctx.User); err != nil {
			ctx.Data["HasError"] = true
			switch err {
			case models.ErrUserOwnRepos:
				ctx.Data["ErrorMsg"] = "Your account still have ownership of repository, you have to delete or transfer them first."
			default:
				ctx.Handle(200, "user.Delete", err)
				return
			}
		} else {
			ctx.Redirect("/")
			return
		}
	}

	ctx.HTML(200, "user/delete")
}
开发者ID:JREAMLU,项目名称:gogs,代码行数:33,代码来源:user.go

示例5: ToApiUser

// ToApiUser converts user to API format.
func ToApiUser(u *models.User) *api.User {
	return &api.User{
		Id:        u.Id,
		UserName:  u.Name,
		AvatarUrl: string(setting.Protocol) + u.AvatarLink(),
	}
}
开发者ID:wxiangbo,项目名称:gogs,代码行数:8,代码来源:user.go

示例6: DeletePost

func DeletePost(ctx *middleware.Context) {
	ctx.Data["Title"] = "Delete Account"
	ctx.Data["PageIsUserSetting"] = true
	ctx.Data["IsUserPageSettingDelete"] = true

	tmpUser := models.User{
		Passwd: ctx.Query("password"),
		Salt:   ctx.User.Salt,
	}
	tmpUser.EncodePasswd()
	if tmpUser.Passwd != ctx.User.Passwd {
		ctx.Flash.Error("Password is not correct. Make sure you are owner of this account.")
	} else {
		if err := models.DeleteUser(ctx.User); err != nil {
			switch err {
			case models.ErrUserOwnRepos:
				ctx.Flash.Error("Your account still have ownership of repository, you have to delete or transfer them first.")
			default:
				ctx.Handle(500, "user.Delete", err)
				return
			}
		} else {
			ctx.Redirect("/")
			return
		}
	}

	ctx.Redirect("/user/delete")
}
开发者ID:jbeduya,项目名称:gogs,代码行数:29,代码来源:user.go

示例7: checkUserFollowing

func checkUserFollowing(ctx *middleware.Context, u *models.User, followID int64) {
	if u.IsFollowing(followID) {
		ctx.Status(204)
	} else {
		ctx.Error(404)
	}
}
开发者ID:cuteluo1983,项目名称:gogs,代码行数:7,代码来源:followers.go

示例8: listUserFollowing

func listUserFollowing(ctx *context.APIContext, u *models.User) {
	users, err := u.GetFollowing(ctx.QueryInt("page"))
	if err != nil {
		ctx.Error(500, "GetFollowing", err)
		return
	}
	responseApiUsers(ctx, users)
}
开发者ID:CarloQ,项目名称:gogs,代码行数:8,代码来源:follower.go

示例9: listUserFollowers

func listUserFollowers(ctx *middleware.Context, u *models.User) {
	users, err := u.GetFollowers(ctx.QueryInt("page"))
	if err != nil {
		ctx.APIError(500, "GetUserFollowers", err)
		return
	}
	responseApiUsers(ctx, users)
}
开发者ID:cuteluo1983,项目名称:gogs,代码行数:8,代码来源:followers.go

示例10: ToApiUser

// ToApiUser converts user to API format.
func ToApiUser(u *models.User) *api.User {
	return &api.User{
		ID:        u.Id,
		UserName:  u.Name,
		FullName:  u.FullName,
		Email:     u.Email,
		AvatarUrl: u.AvatarLink(),
	}
}
开发者ID:nafrente,项目名称:gogs,代码行数:10,代码来源:user.go

示例11: ToOrganization

func ToOrganization(org *models.User) *api.Organization {
	return &api.Organization{
		ID:          org.ID,
		AvatarUrl:   org.AvatarLink(),
		UserName:    org.Name,
		FullName:    org.FullName,
		Description: org.Description,
		Website:     org.Website,
		Location:    org.Location,
	}
}
开发者ID:yweber,项目名称:gogs,代码行数:11,代码来源:convert.go

示例12: listUserOrgs

func listUserOrgs(ctx *context.APIContext, u *models.User, all bool) {
	if err := u.GetOrganizations(all); err != nil {
		ctx.Error(500, "GetOrganizations", err)
		return
	}

	apiOrgs := make([]*api.Organization, len(u.Orgs))
	for i := range u.Orgs {
		apiOrgs[i] = convert.ToOrganization(u.Orgs[i])
	}
	ctx.JSON(200, &apiOrgs)
}
开发者ID:VoyTechnology,项目名称:gogs,代码行数:12,代码来源:org.go

示例13: ToUser

func ToUser(u *models.User) *api.User {
	if u == nil {
		return nil
	}

	return &api.User{
		ID:        u.ID,
		UserName:  u.Name,
		FullName:  u.FullName,
		Email:     u.Email,
		AvatarUrl: u.AvatarLink(),
	}
}
开发者ID:yweber,项目名称:gogs,代码行数:13,代码来源:convert.go

示例14: SendActivateEmailMail

// SendActivateAccountMail sends confirmation e-mail.
func SendActivateEmailMail(c *macaron.Context, u *models.User, email *models.EmailAddress) {
	data := ComposeTplData(u)
	data["Code"] = u.GenerateEmailActivateCode(email.Email)
	data["Email"] = email.Email
	body, err := c.HTMLString(string(AUTH_ACTIVATE_EMAIL), data)
	if err != nil {
		log.Error(4, "HTMLString: %v", err)
		return
	}

	msg := NewMessage([]string{email.Email}, c.Tr("mail.activate_email"), body)
	msg.Info = fmt.Sprintf("UID: %d, activate email", u.Id)

	SendAsync(msg)
}
开发者ID:cuteluo1983,项目名称:gogs,代码行数:16,代码来源:mail.go

示例15: handleCreateError

func handleCreateError(ctx *middleware.Context, owner *models.User, err error, name string, tpl base.TplName, form interface{}) {
	switch {
	case models.IsErrReachLimitOfRepo(err):
		ctx.RenderWithErr(ctx.Tr("repo.form.reach_limit_of_creation", owner.RepoCreationNum()), tpl, form)
	case models.IsErrRepoAlreadyExist(err):
		ctx.Data["Err_RepoName"] = true
		ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), tpl, form)
	case models.IsErrNameReserved(err):
		ctx.Data["Err_RepoName"] = true
		ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), tpl, form)
	case models.IsErrNamePatternNotAllowed(err):
		ctx.Data["Err_RepoName"] = true
		ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tpl, form)
	default:
		ctx.Handle(500, name, err)
	}
}
开发者ID:rothgar,项目名称:gogs,代码行数:17,代码来源:repo.go


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