github.com/decred/politeia@v1.4.0/politeiawww/cmd/shared/users.go (about)

     1  // Copyright (c) 2017-2019 The Decred developers
     2  // Use of this source code is governed by an ISC
     3  // license that can be found in the LICENSE file.
     4  
     5  package shared
     6  
     7  import v1 "github.com/decred/politeia/politeiawww/api/www/v1"
     8  
     9  // UsersCmd retreives a list of users that have been filtered using the
    10  // specified filtering params.
    11  type UsersCmd struct {
    12  	Email     string `long:"email"`    // Email filter
    13  	Username  string `long:"username"` // Username filter
    14  	PublicKey string `long:"pubkey"`   // Public key filter
    15  }
    16  
    17  // Execute executes the users command.
    18  func (cmd *UsersCmd) Execute(args []string) error {
    19  	u := v1.Users{
    20  		Email:     cmd.Email,
    21  		Username:  cmd.Username,
    22  		PublicKey: cmd.PublicKey,
    23  	}
    24  
    25  	ur, err := client.Users(&u)
    26  	if err != nil {
    27  		return err
    28  	}
    29  	return PrintJSON(ur)
    30  }
    31  
    32  // UsersHelpMsg is the output of the help command when 'users' is specified.
    33  const UsersHelpMsg = `users [flags]
    34  
    35  Fetch a list of users. If logged in as admin, users returns a list 
    36  of all users, optionally filtering by username, email or public key. Partial 
    37  matches are returned. If not logged in (or logged in as non admin) users 
    38  returns a list of users filtered by username or public key, with only exact
    39  matches returned. 
    40  
    41  Arguments: None
    42  
    43  Flags:
    44    --email       (string, optional)   Email filter
    45    --username    (string, optional)   Username filter
    46    --pubkey      (string, optional)   Public Key
    47  
    48  
    49  Example (Admin):
    50  users --email=user@example.com --username=user --pubkey=0b2283a91f6bf95f2c121
    51  14c7c1259c1396756bea4f64be43fe0f73b383bdf92`