You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by da...@apache.org on 2018/10/26 23:50:58 UTC

[trafficcontrol] 05/05: Removed ConfirmLocalPasswd from 1.4 api

This is an automated email from the ASF dual-hosted git repository.

dangogh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit e4ecb5bbb3b155fde070b8861d2213b6a5538fb9
Author: moltzaum <ma...@moltzau.net>
AuthorDate: Thu Oct 25 12:09:13 2018 -0600

    Removed ConfirmLocalPasswd from 1.4 api
---
 docs/source/api/v14/user.rst                | 27 ++++++++++-----------------
 lib/go-tc/users.go                          |  7 +++----
 traffic_ops/traffic_ops_golang/user/user.go | 27 ++++-----------------------
 3 files changed, 17 insertions(+), 44 deletions(-)

diff --git a/docs/source/api/v14/user.rst b/docs/source/api/v14/user.rst
index 0a0492f..2bd2a68 100644
--- a/docs/source/api/v14/user.rst
+++ b/docs/source/api/v14/user.rst
@@ -246,8 +246,6 @@ Users
   +--------------------------+--------+----------+-------------------------------------------------+
   | ``city``                 | string | no       |                                                 |
   +--------------------------+--------+----------+-------------------------------------------------+
-  | ``confirmLocalPasswd``   | string | yes      |                                                 |
-  +--------------------------+--------+----------+-------------------------------------------------+
   | ``company``              | string | no       |                                                 |
   +--------------------------+--------+----------+-------------------------------------------------+
   | ``country``              | string | no       |                                                 |
@@ -278,13 +276,12 @@ Users
   **Request Example** ::
   
     {   
-        "username": "tsimpson"
+        "username": "tsimpson",
         "tenantId": 1,
-        "fullName": "Tom Simpson"
-        "email": "email1@email.com"
-        "role": 6
+        "fullName": "Tom Simpson",
+        "email": "email1@email.com",
+        "role": 6,
         "localPasswd": "pa$$word"
-        "confirmLocalPasswd": "pa$$word"
     }
 
 |
@@ -387,8 +384,6 @@ Users
   +--------------------------+--------+----------+-------------------------------------------------+
   | ``city``                 | string | no       |                                                 |
   +--------------------------+--------+----------+-------------------------------------------------+
-  | ``confirmLocalPasswd``   | string | yes      |                                                 |
-  +--------------------------+--------+----------+-------------------------------------------------+
   | ``company``              | string | no       |                                                 |
   +--------------------------+--------+----------+-------------------------------------------------+
   | ``country``              | string | no       |                                                 |
@@ -419,13 +414,12 @@ Users
   **Request Example** ::
   
     {   
-        "username": "tsimpson"
+        "username": "tsimpson",
         "tenantId": 1,
-        "fullName": "Tom Simpson"
-        "email": "email1@email.com"
-        "role": 6
+        "fullName": "Tom Simpson",
+        "email": "email1@email.com",
+        "role": 6,
         "localPasswd": "pa$$word"
-        "confirmLocalPasswd": "pa$$word"
     }
 
 |
@@ -535,7 +529,7 @@ Users
   **Request Example** ::
 
     {
-        "email": "foo@bar.com"
+        "email": "foo@bar.com",
         "role": 1,
         "tenantId": 1
     }
@@ -956,8 +950,7 @@ Users
             "addressLine1": null,
             "postalCode": null,
             "tenant": "root",
-            "tenantId": 1,
-
+            "tenantId": 1
         }
     }
 
diff --git a/lib/go-tc/users.go b/lib/go-tc/users.go
index 1a5391d..55202c8 100644
--- a/lib/go-tc/users.go
+++ b/lib/go-tc/users.go
@@ -79,10 +79,9 @@ type commonUserFields struct {
 
 // User fields in v14 have been updated to be nullable. omitempty is used to protect password data
 type User struct {
-	Username             *string    `json:"username" db:"username"`
-	RegistrationSent     *TimeNoMod `json:"registrationSent" db:"registration_sent"`
-	ConfirmLocalPassword *string    `json:"confirmLocalPasswd,omitempty" db:"confirm_local_passwd"`
-	LocalPassword        *string    `json:"localPasswd,omitempty" db:"local_passwd"`
+	Username         *string    `json:"username" db:"username"`
+	RegistrationSent *TimeNoMod `json:"registrationSent" db:"registration_sent"`
+	LocalPassword    *string    `json:"localPasswd,omitempty" db:"local_passwd"`
 	commonUserFields
 }
 
diff --git a/traffic_ops/traffic_ops_golang/user/user.go b/traffic_ops/traffic_ops_golang/user/user.go
index a85d703..471f474 100644
--- a/traffic_ops/traffic_ops_golang/user/user.go
+++ b/traffic_ops/traffic_ops_golang/user/user.go
@@ -21,7 +21,6 @@ package user
 
 import (
 	"database/sql"
-	"errors"
 	"fmt"
 	"net/http"
 	"strconv"
@@ -110,13 +109,8 @@ func (user *TOUser) Validate() error {
 		"tenantID": validation.Validate(user.TenantID, validation.Required),
 	}
 
-	// Passwords are not required for update
-	if user.LocalPassword != nil && user.ConfirmLocalPassword != nil {
-
-		if *user.LocalPassword != *user.ConfirmLocalPassword {
-			return errors.New("Passwords should match.")
-		}
-
+	// Password is not required for update
+	if user.LocalPassword != nil {
 		_, err := auth.IsGoodLoginPair(*user.Username, *user.LocalPassword)
 		if err != nil {
 			return err
@@ -128,8 +122,7 @@ func (user *TOUser) Validate() error {
 
 func (user *TOUser) postValidate() error {
 	validateErrs := validation.Errors{
-		"localPasswd":        validation.Validate(user.LocalPassword, validation.Required),
-		"confirmLocalPasswd": validation.Validate(user.ConfirmLocalPassword, validation.Required),
+		"localPasswd": validation.Validate(user.LocalPassword, validation.Required),
 	}
 	return util.JoinErrs(tovalidate.ToErrors(validateErrs))
 }
@@ -148,10 +141,6 @@ func (user *TOUser) Create() (error, error, int) {
 	if err != nil {
 		return err, nil, http.StatusBadRequest
 	}
-	*user.ConfirmLocalPassword, err = auth.DerivePassword(*user.ConfirmLocalPassword)
-	if err != nil {
-		return err, nil, http.StatusBadRequest
-	}
 
 	resultRows, err := user.ReqInfo.Tx.NamedQuery(user.InsertQuery(), user)
 	if err != nil {
@@ -183,7 +172,6 @@ func (user *TOUser) Create() (error, error, int) {
 	user.Tenant = &tenant
 	user.RoleName = &rolename
 	user.LocalPassword = nil
-	user.ConfirmLocalPassword = nil
 
 	return nil, nil, http.StatusOK
 }
@@ -241,18 +229,12 @@ func (user *TOUser) Update() (error, error, int) {
 		return fmt.Errorf("users cannot update their own role"), nil, http.StatusBadRequest
 	}
 
-	if user.LocalPassword != nil && user.ConfirmLocalPassword != nil {
-
+	if user.LocalPassword != nil {
 		var err error
 		*user.LocalPassword, err = auth.DerivePassword(*user.LocalPassword)
 		if err != nil {
 			return nil, err, http.StatusInternalServerError
 		}
-
-		*user.ConfirmLocalPassword, err = auth.DerivePassword(*user.ConfirmLocalPassword)
-		if err != nil {
-			return nil, err, http.StatusInternalServerError
-		}
 	}
 
 	resultRows, err := user.ReqInfo.Tx.NamedQuery(user.UpdateQuery(), user)
@@ -276,7 +258,6 @@ func (user *TOUser) Update() (error, error, int) {
 	user.Tenant = &tenant
 	user.RoleName = &rolename
 	user.LocalPassword = nil
-	user.ConfirmLocalPassword = nil
 
 	if rowsAffected != 1 {
 		if rowsAffected < 1 {