summaryrefslogtreecommitdiffstats
path: root/models/user.go
diff options
context:
space:
mode:
authorderSuessmann <derSuessmann@users.noreply.github.com>2017-01-08 04:12:03 +0100
committerLunny Xiao <xiaolunwen@gmail.com>2017-01-08 11:12:03 +0800
commit51d578ff3321e173b0dae4c80d3031fb0492656d (patch)
tree8297ce73af221f98bff148c1d7cfa7c82a0580a6 /models/user.go
parent6072b032918006824f260e79f96372dd94fbb17f (diff)
downloadgitea-51d578ff3321e173b0dae4c80d3031fb0492656d.tar.gz
gitea-51d578ff3321e173b0dae4c80d3031fb0492656d.zip
Add Keep email private (see issue #571). (#571)
- Add site-wide option DEFAULT_KEEP_EMAIL_PRIVATE. - Add the new option to the install and admin/config pages. - Add the new option to app.ini in the service section. - Add the new option to the settings struct. - Add English text strings to i18n. - Add field KeepEmailPrivate to user struct. - Add field KeepEmailPrivate to user form. - Add option to UI. - Add using noreply email address if user has "Keep Email Private". An email address <LowerName>@<NO_REPLY_ADDRESS> is now used in commit messages (and hopefully all other git log relevant places). The change relies on the fact that git commands should use user.NetGitSig(). - Add hiding of email address in UI, if user has set "Keep Email Private". - Add condition to show email address only on explore/users and user pages, if user has not set "Keep Email Private". - Add noreply email in API if set "Keep Email Private". - Add a new service setting NO_REPLY_ADDRESS. The value of this setting is used as the domain part for the user's email address in git log, iff he decides to keep his email address private. If the user decides to keep his email address private and this option is not set 'noreply.example.org' is used, which no MTA should send email to. Add NO_REPLY_ADDRESS to conf/app.ini.
Diffstat (limited to 'models/user.go')
-rw-r--r--models/user.go42
1 files changed, 27 insertions, 15 deletions
diff --git a/models/user.go b/models/user.go
index 201d8c48fa..e6ba2fa6f3 100644
--- a/models/user.go
+++ b/models/user.go
@@ -75,19 +75,20 @@ type User struct {
Name string `xorm:"UNIQUE NOT NULL"`
FullName string
// Email is the primary email address (to be used for communication)
- Email string `xorm:"NOT NULL"`
- Passwd string `xorm:"NOT NULL"`
- LoginType LoginType
- LoginSource int64 `xorm:"NOT NULL DEFAULT 0"`
- LoginName string
- Type UserType
- OwnedOrgs []*User `xorm:"-"`
- Orgs []*User `xorm:"-"`
- Repos []*Repository `xorm:"-"`
- Location string
- Website string
- Rands string `xorm:"VARCHAR(10)"`
- Salt string `xorm:"VARCHAR(10)"`
+ Email string `xorm:"NOT NULL"`
+ KeepEmailPrivate bool
+ Passwd string `xorm:"NOT NULL"`
+ LoginType LoginType
+ LoginSource int64 `xorm:"NOT NULL DEFAULT 0"`
+ LoginName string
+ Type UserType
+ OwnedOrgs []*User `xorm:"-"`
+ Orgs []*User `xorm:"-"`
+ Repos []*Repository `xorm:"-"`
+ Location string
+ Website string
+ Rands string `xorm:"VARCHAR(10)"`
+ Salt string `xorm:"VARCHAR(10)"`
Created time.Time `xorm:"-"`
CreatedUnix int64 `xorm:"INDEX"`
@@ -170,13 +171,22 @@ func (u *User) AfterSet(colName string, _ xorm.Cell) {
}
}
+// getEmail returns an noreply email, if the user has set to keep his
+// email address private, otherwise the primary email address.
+func (u *User) getEmail() string {
+ if u.KeepEmailPrivate {
+ return fmt.Sprintf("%s@%s", u.LowerName, setting.Service.NoReplyAddress)
+ }
+ return u.Email
+}
+
// APIFormat converts a User to api.User
func (u *User) APIFormat() *api.User {
return &api.User{
ID: u.ID,
UserName: u.Name,
FullName: u.FullName,
- Email: u.Email,
+ Email: u.getEmail(),
AvatarURL: u.AvatarLink(),
}
}
@@ -361,7 +371,7 @@ func (u *User) GetFollowing(page int) ([]*User, error) {
func (u *User) NewGitSig() *git.Signature {
return &git.Signature{
Name: u.DisplayName(),
- Email: u.Email,
+ Email: u.getEmail(),
When: time.Now(),
}
}
@@ -616,6 +626,8 @@ func CreateUser(u *User) (err error) {
return ErrEmailAlreadyUsed{u.Email}
}
+ u.KeepEmailPrivate = setting.Service.DefaultKeepEmailPrivate
+
u.LowerName = strings.ToLower(u.Name)
u.AvatarEmail = u.Email
u.Avatar = base.HashEmail(u.AvatarEmail)