code.gitea.io/gitea@v1.19.3/modules/structs/user.go (about)

     1  // Copyright 2014 The Gogs Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package structs
     5  
     6  import (
     7  	"time"
     8  
     9  	"code.gitea.io/gitea/modules/json"
    10  )
    11  
    12  // User represents a user
    13  // swagger:model
    14  type User struct {
    15  	// the user's id
    16  	ID int64 `json:"id"`
    17  	// the user's username
    18  	UserName string `json:"login"`
    19  	// the user's authentication sign-in name.
    20  	// default: empty
    21  	LoginName string `json:"login_name"`
    22  	// the user's full name
    23  	FullName string `json:"full_name"`
    24  	// swagger:strfmt email
    25  	Email string `json:"email"`
    26  	// URL to the user's avatar
    27  	AvatarURL string `json:"avatar_url"`
    28  	// User locale
    29  	Language string `json:"language"`
    30  	// Is the user an administrator
    31  	IsAdmin bool `json:"is_admin"`
    32  	// swagger:strfmt date-time
    33  	LastLogin time.Time `json:"last_login,omitempty"`
    34  	// swagger:strfmt date-time
    35  	Created time.Time `json:"created,omitempty"`
    36  	// Is user restricted
    37  	Restricted bool `json:"restricted"`
    38  	// Is user active
    39  	IsActive bool `json:"active"`
    40  	// Is user login prohibited
    41  	ProhibitLogin bool `json:"prohibit_login"`
    42  	// the user's location
    43  	Location string `json:"location"`
    44  	// the user's website
    45  	Website string `json:"website"`
    46  	// the user's description
    47  	Description string `json:"description"`
    48  	// User visibility level option: public, limited, private
    49  	Visibility string `json:"visibility"`
    50  
    51  	// user counts
    52  	Followers    int `json:"followers_count"`
    53  	Following    int `json:"following_count"`
    54  	StarredRepos int `json:"starred_repos_count"`
    55  }
    56  
    57  // MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility
    58  func (u User) MarshalJSON() ([]byte, error) {
    59  	// Re-declaring User to avoid recursion
    60  	type shadow User
    61  	return json.Marshal(struct {
    62  		shadow
    63  		CompatUserName string `json:"username"`
    64  	}{shadow(u), u.UserName})
    65  }
    66  
    67  // UserSettings represents user settings
    68  // swagger:model
    69  type UserSettings struct {
    70  	FullName      string `json:"full_name"`
    71  	Website       string `json:"website"`
    72  	Description   string `json:"description"`
    73  	Location      string `json:"location"`
    74  	Language      string `json:"language"`
    75  	Theme         string `json:"theme"`
    76  	DiffViewStyle string `json:"diff_view_style"`
    77  	// Privacy
    78  	HideEmail    bool `json:"hide_email"`
    79  	HideActivity bool `json:"hide_activity"`
    80  }
    81  
    82  // UserSettingsOptions represents options to change user settings
    83  // swagger:model
    84  type UserSettingsOptions struct {
    85  	FullName      *string `json:"full_name" binding:"MaxSize(100)"`
    86  	Website       *string `json:"website" binding:"OmitEmpty;ValidUrl;MaxSize(255)"`
    87  	Description   *string `json:"description" binding:"MaxSize(255)"`
    88  	Location      *string `json:"location" binding:"MaxSize(50)"`
    89  	Language      *string `json:"language"`
    90  	Theme         *string `json:"theme"`
    91  	DiffViewStyle *string `json:"diff_view_style"`
    92  	// Privacy
    93  	HideEmail    *bool `json:"hide_email"`
    94  	HideActivity *bool `json:"hide_activity"`
    95  }