Browse Source

[api] return email for authenticated user

cgars 7 years ago
parent
commit
af11eb06e3
2 changed files with 11 additions and 10 deletions
  1. 8 6
      models/user.go
  2. 3 4
      routes/api/v1/user/user.go

+ 8 - 6
models/user.go

@@ -39,7 +39,7 @@ import (
 type UserType int
 
 const (
-	USER_TYPE_INDIVIDUAL UserType = iota // Historic reason to make it starts at 0.
+	USER_TYPE_INDIVIDUAL   UserType = iota // Historic reason to make it starts at 0.
 	USER_TYPE_ORGANIZATION
 )
 
@@ -50,10 +50,10 @@ 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"`
+	Email       string        `xorm:"NOT NULL"`
+	Passwd      string        `xorm:"NOT NULL"`
 	LoginType   LoginType
-	LoginSource int64 `xorm:"NOT NULL DEFAULT 0"`
+	LoginSource int64         `xorm:"NOT NULL DEFAULT 0"`
 	LoginName   string
 	Type        UserType
 	OwnedOrgs   []*User       `xorm:"-"`
@@ -61,8 +61,8 @@ type User struct {
 	Repos       []*Repository `xorm:"-"`
 	Location    string
 	Website     string
-	Rands       string `xorm:"VARCHAR(10)"`
-	Salt        string `xorm:"VARCHAR(10)"`
+	Rands       string        `xorm:"VARCHAR(10)"`
+	Salt        string        `xorm:"VARCHAR(10)"`
 
 	Created     time.Time `xorm:"-"`
 	CreatedUnix int64
@@ -127,6 +127,7 @@ func (u *User) APIFormat() *api.User {
 		UserName:  u.Name,
 		FullName:  u.FullName,
 		AvatarUrl: u.AvatarLink(),
+		Email:     u.Email,
 	}
 }
 
@@ -321,6 +322,7 @@ func (u *User) OldGinVerifyPassword(plain string) bool {
 	err := bcrypt.CompareHashAndPassword([]byte(u.Passwd), []byte(plain))
 	return err == nil
 }
+
 // ValidatePassword checks if given password matches the one belongs to the user.
 func (u *User) ValidatePassword(passwd string) bool {
 	if u.OldGinVerifyPassword(passwd) {

+ 3 - 4
routes/api/v1/user/user.go

@@ -63,10 +63,9 @@ func GetInfo(c *context.APIContext) {
 		return
 	}
 
-	// Hide user e-mail when API caller isn't signed in.
-	if !c.IsLogged {
-		u.Email = ""
-	}
+	// Hide user e-mail
+	u.Email = ""
+
 	c.JSON(200, u.APIFormat())
 }