github.com/decred/politeia@v1.4.0/politeiawww/cmd/pictl/useremailverify.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 main
     6  
     7  import (
     8  	"encoding/hex"
     9  
    10  	v1 "github.com/decred/politeia/politeiawww/api/www/v1"
    11  	"github.com/decred/politeia/politeiawww/cmd/shared"
    12  )
    13  
    14  // userEmailVerifyCmd is used to verify a user's email address.
    15  type userEmailVerifyCmd struct {
    16  	Args struct {
    17  		Username string `positional-arg-name:"username"` // Username
    18  		Email    string `positional-arg-name:"email"`    // User email address
    19  		Token    string `positional-arg-name:"token"`    // Verification token
    20  	} `positional-args:"true" required:"true"`
    21  }
    22  
    23  // Execute executes the userEmailVerifyCmd command.
    24  //
    25  // This function satisfies the go-flags Commander interface.
    26  func (cmd *userEmailVerifyCmd) Execute(args []string) error {
    27  	// Load user identity
    28  	id, err := cfg.LoadIdentity(cmd.Args.Username)
    29  	if err != nil {
    30  		return err
    31  	}
    32  
    33  	// Verify user's email address
    34  	sig := id.SignMessage([]byte(cmd.Args.Token))
    35  	vnur, err := client.VerifyNewUser(
    36  		&v1.VerifyNewUser{
    37  			Email:             cmd.Args.Email,
    38  			VerificationToken: cmd.Args.Token,
    39  			Signature:         hex.EncodeToString(sig[:]),
    40  		})
    41  	if err != nil {
    42  		return err
    43  	}
    44  
    45  	// Print response details
    46  	return shared.PrintJSON(vnur)
    47  }
    48  
    49  // userEmailVerifyHelpMsg is the output for the help command when
    50  // 'useremailverify' is specified.
    51  var userEmailVerifyHelpMsg = `useremailverify "email" "token"
    52  
    53  Verify user's email address.
    54  
    55  Arguments:
    56  1. email       (string, optional)   Email of user
    57  2. token       (string, optional)   Verification token`