airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject [1/2] airavata-php-gateway git commit: AIRAVATA-2508 Admin sets gateway password
Date Thu, 28 Sep 2017 21:21:57 GMT
Repository: airavata-php-gateway
Updated Branches:
  refs/heads/develop fdaa72c96 -> 9069b814b


AIRAVATA-2508 Admin sets gateway password


Project: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/commit/02fde3ee
Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/02fde3ee
Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/02fde3ee

Branch: refs/heads/develop
Commit: 02fde3eeb3e92b7e11940771160dd5f72993d792
Parents: fa310a1
Author: Marcus Christie <machrist@iu.edu>
Authored: Thu Sep 28 13:15:43 2017 -0400
Committer: Marcus Christie <machrist@iu.edu>
Committed: Thu Sep 28 13:42:36 2017 -0400

----------------------------------------------------------------------
 app/controllers/AdminController.php             | 28 ++++++++++++-
 .../GatewayRequestUpdateController.php          | 14 ++-----
 app/libraries/AdminUtilities.php                | 35 ++++++++++------
 app/views/account/update.blade.php              | 34 ----------------
 app/views/admin/manage-gateway.blade.php        | 42 ++++++++++++++++----
 5 files changed, 86 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/02fde3ee/app/controllers/AdminController.php
----------------------------------------------------------------------
diff --git a/app/controllers/AdminController.php b/app/controllers/AdminController.php
index 28eb9a5..6c11dfb 100644
--- a/app/controllers/AdminController.php
+++ b/app/controllers/AdminController.php
@@ -173,6 +173,30 @@ class AdminController extends BaseController {
 
 	public function updateGateway(){
 
+        $rules = array(
+            "password" => "min:6|max:48|regex:/^.*(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[@!$#*]).*$/",
+            "confirm_password" => "same:password",
+            "email" => "email",
+        );
+        $messages = array(
+            'password.regex' => 'Password needs to contain at least (a) One lower case
letter (b) One Upper case letter and (c) One number (d) One of the following special characters
- !@#$&*',
+        );
+		$inputs = Input::all();
+        $checkValidation = array();
+        $checkValidation["password"] = $inputs["gatewayAdminPassword"];
+        $checkValidation["confirm_password"] = $inputs["gatewayAdminPasswordConfirm"];
+        $checkValidation["email"] = $inputs["gatewayAdminEmail"];
+
+        $validator = Validator::make( $checkValidation, $rules, $messages);
+        if ($validator->fails()) {
+            if(Request::ajax()){
+                return json_encode(array("errors" => true, "validationMessages" =>
$validator->messages()));
+            } else {
+                Session::put("message", "An error has occurred while updating the Gateway:
" + $validator->messages());
+                return Redirect::back();
+            }
+        }
+
 	    $gateway = TenantProfileService::getGateway( Session::get('authz-token'), Input::get("internal_gateway_id"));
 		$returnVal = AdminUtilities::update_gateway( Input::get("internal_gateway_id"), Input::except("oauthClientId","oauthClientSecret"));
 		if( Request::ajax()){
@@ -184,10 +208,10 @@ class AdminController extends BaseController {
                     Session::put("successMessages", "Tenant has been created successfully!");
                 else
                     Session::put("successMessages", "Gateway has been updated successfully!");
-                return json_encode(AdminUtilities::get_gateway(Input::get("internal_gateway_id")));
+                return json_encode(array("errors" => false, "gateway" => AdminUtilities::get_gateway(Input::get("internal_gateway_id"))));
             }
 			else {
-                return $returnVal; // anything other than positive update result
+                return json_encode(array("errors" => true)); // anything other than positive
update result
             }
 		}
 		else{

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/02fde3ee/app/controllers/GatewayRequestUpdateController.php
----------------------------------------------------------------------
diff --git a/app/controllers/GatewayRequestUpdateController.php b/app/controllers/GatewayRequestUpdateController.php
index 2ff33a5..f75019e 100644
--- a/app/controllers/GatewayRequestUpdateController.php
+++ b/app/controllers/GatewayRequestUpdateController.php
@@ -27,26 +27,18 @@ class GatewayRequestUpdateController extends BaseController
 
         $inputs = Input::all();
         $rules = array(
-            "password" => "required|min:6|max:48|regex:/^.*(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[@!$#*]).*$/",
-            "confirm_password" => "required|same:password",
             "email" => "required|email",
         );
 
-        $messages = array(
-            'password.regex' => 'Password needs to contain at least (a) One lower case
letter (b) One Upper case letter and (c) One number (d) One of the following special characters
- !@#$&*',
-        );
+        $messages = array();
 
         $checkValidation = array();
-        $checkValidation["password"] = $inputs["admin-password"];
-        $checkValidation["confirm_password"] = $inputs["admin-password-confirm"];
-        $checkValidation["email"] = $inputs["admin-email"];
+        $checkValidation["email"] = $inputs["email-address"];
 
         $validator = Validator::make( $checkValidation, $rules, $messages);
         if ($validator->fails()) {
             Session::put("validationMessages", $validator->messages() );
-            return Redirect::back()
-                ->withInput(Input::except('password', 'password_confirm'))
-                ->withErrors($validator);
+            return Redirect::back()->withErrors($validator);
         }
         else {
             $returnVal = AdminUtilities::user_update_gateway(Input::get("internal-gateway-id"),
Input::all());

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/02fde3ee/app/libraries/AdminUtilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/AdminUtilities.php b/app/libraries/AdminUtilities.php
index 7f17408..b66ab4c 100644
--- a/app/libraries/AdminUtilities.php
+++ b/app/libraries/AdminUtilities.php
@@ -127,16 +127,6 @@ class AdminUtilities
         $gateway->gatewayApprovalStatus = GatewayApprovalStatus::APPROVED;
         $gateway->emailAddress = $gatewayData["email-address"];
         $gateway->gatewayURL = $gatewayData["gateway-url"];
-        $gateway->identityServerUserName = $gatewayData["admin-username"];
-        $token = AdminUtilities::create_pwd_token([
-            "username" => $gatewayData["admin-username"],
-            "password" => $gatewayData["admin-password"],
-            "description" => "Admin user password for Gateway " . $gatewayId
-        ]);
-        $gateway->identityServerPasswordToken  = $token;
-        $gateway->gatewayAdminFirstName = $gatewayData["admin-firstname"];
-        $gateway->gatewayAdminLastName = $gatewayData["admin-lastname"];
-        $gateway->gatewayAdminEmail = $gatewayData["admin-email"];
         $gateway->reviewProposalDescription = $gatewayData["project-details"];
         $gateway->gatewayPublicAbstract = $gatewayData["public-project-description"];
         if( TenantProfileService::updateGateway( Session::get('authz-token'), $gateway) ){
@@ -163,10 +153,15 @@ class AdminUtilities
             $gatewayData["declinedReason"] = " ";
             if ($gateway->identityServerPasswordToken == null)
             {
-                Session::put("errorMessages", "Error: Please ask the Gateway Provider to
submit a password.");
+                Session::flash("errorMessages", "Error: Please provide an admin password.");
                 return -1;
             }
-            foreach ($gatewayData as $data) {
+            foreach ($gatewayData as $key => $data) {
+                // Don't check these fields, see related check above
+                // where we make sure that password is provided
+                if ($key == "gatewayAdminPassword" || $key == "gatewayAdminPasswordConfirm")
{
+                    continue;
+                }
                 if ($data == null) {
                     return -1;
                 }
@@ -181,6 +176,14 @@ class AdminUtilities
             $gateway->gatewayAdminLastName = $gatewayData["gatewayAdminLastName"];
             $gateway->gatewayAdminEmail = $gatewayData["gatewayAdminEmail"];
             $gateway->identityServerUserName = $gatewayData["identityServerUserName"];
+            if (!empty($gatewayData["gatewayAdminPassword"])) {
+                $token = AdminUtilities::create_pwd_token([
+                    "username" => $gatewayData["identityServerUserName"],
+                    "password" => $gatewayData["gatewayAdminPassword"],
+                    "description" => "Admin user password for Gateway " . $gateway->gatewayName
+                ]);
+                $gateway->identityServerPasswordToken = $token;
+            }
             $gateway->reviewProposalDescription = $gatewayData["reviewProposalDescription"];
             $gateway->gatewayPublicAbstract = $gatewayData["gatewayPublicAbstract"];
             $gateway->gatewayApprovalStatus = GatewayApprovalStatus::APPROVED;
@@ -195,6 +198,14 @@ class AdminUtilities
             $gateway->gatewayAdminLastName = $gatewayData["gatewayAdminLastName"];
             $gateway->gatewayAdminEmail = $gatewayData["gatewayAdminEmail"];
             $gateway->identityServerUserName = $gatewayData["identityServerUserName"];
+            if (!empty($gatewayData["gatewayAdminPassword"])) {
+                $token = AdminUtilities::create_pwd_token([
+                    "username" => $gatewayData["identityServerUserName"],
+                    "password" => $gatewayData["gatewayAdminPassword"],
+                    "description" => "Admin user password for Gateway " . $gateway->gatewayName
+                ]);
+                $gateway->identityServerPasswordToken = $token;
+            }
             $gateway->reviewProposalDescription = $gatewayData["reviewProposalDescription"];
             $gateway->gatewayPublicAbstract = $gatewayData["gatewayPublicAbstract"];
             $gateway->gatewayApprovalStatus = GatewayApprovalStatus::APPROVED;

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/02fde3ee/app/views/account/update.blade.php
----------------------------------------------------------------------
diff --git a/app/views/account/update.blade.php b/app/views/account/update.blade.php
index e2e905c..e5b2f37 100644
--- a/app/views/account/update.blade.php
+++ b/app/views/account/update.blade.php
@@ -65,36 +65,6 @@
                         </div>
 
                         <div class="form-group required">
-                            <label class="control-label">Gateway Admin Username</label>
-                            <input type="text" name="admin-username" value="{{ $gatewayData["adminUsername"]
}}" class="form-control" required="required" />
-                        </div>
-
-                        <div class="form-group required">
-                            <label class="control-label">Gateway Admin Password</label>
-                            <input type="password" id="password" name="admin-password"
class="form-control" required="required" title="" type="password" data-container="body" data-toggle="popover"
data-placement="left" data-content="Password needs to contain at least (a) One lower case
letter (b) One Upper case letter and (c) One number (d) One of the following special characters
- !@#$*"/>
-                        </div>
-
-                        <div class="form-group required">
-                            <label class="control-label">Admin Password Confirmation</label>
-                            <input type="password" name="admin-password-confirm" class="form-control"
required="required"/>
-                        </div>
-
-                        <div class="form-group required">
-                            <label class="control-label">Admin First Name</label>
-                            <input type="text" name="admin-firstname" class="form-control"
required="required" value="{{ $gatewayData["adminFirstName"] }}"/>
-                        </div>
-
-                        <div class="form-group required">
-                            <label class="control-label">Admin Last Name</label>
-                            <input type="text" name="admin-lastname" class="form-control"
required="required" value="{{ $gatewayData["adminLastName"] }}"/>
-                        </div>
-
-                        <div class="form-group required">
-                            <label class="control-label">Admin Email ID</label>
-                            <input type="text" name="admin-email" class="form-control"
required="required" value="{{ $gatewayData["adminEmail"] }}"/>
-                        </div>
-
-                        <div class="form-group required">
                             <label class="control-label">Project Details</label>
                             <textarea type="text" name="project-details" maxlength="250"
id="project-details" class="form-control" required="required"  data-container="body" data-toggle="popover"
data-placement="left" data-content="This information will help us to understand and identify
your gateway requirements, such as local or remote resources, user management, field of science
and communities supported, applications and interfaces, license handling, allocation management,
data management, etc... It will help us in serving you and providing you with the best option
for you and your research community.">{{ $gatewayData["projectDetails"] }}</textarea>
                         </div>
@@ -118,10 +88,6 @@
 @parent
 <script>
 
-    $("#password").popover({
-    'trigger':'focus'
-    });
-
     $("#gateway-url").popover({
     'trigger':'focus'
     });

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/02fde3ee/app/views/admin/manage-gateway.blade.php
----------------------------------------------------------------------
diff --git a/app/views/admin/manage-gateway.blade.php b/app/views/admin/manage-gateway.blade.php
index 5e72642..df4a997 100644
--- a/app/views/admin/manage-gateway.blade.php
+++ b/app/views/admin/manage-gateway.blade.php
@@ -275,6 +275,14 @@
                         <input type="text" name="identityServerUserName" id="identityServerUserName"
class="form-control identityServerUserName"/>
                     </div>
                     <div class="form-group">
+                        <label class="control-label">Gateway Admin Password</label>
+                        <input type="password" id="password" name="gatewayAdminPassword"
class="form-control identityServerPasswordToken" title="" type="password" data-container="body"
data-toggle="popover" data-placement="left" data-content="Password needs to contain at least
(a) One lower case letter (b) One Upper case letter and (c) One number (d) One of the following
special characters - !@#$*"/>
+                    </div>
+                    <div class="form-group">
+                        <label class="control-label">Admin Password Confirmation</label>
+                        <input type="password" name="gatewayAdminPasswordConfirm" class="form-control"/>
+                    </div>
+                    <div class="form-group">
                         <label>Gateway Admin First Name</label>
                         <input type="text" name="gatewayAdminFirstName" id="gatewayAdminFirstName"
class="form-control gatewayAdminFirstName"/>
                     </div>
@@ -613,6 +621,9 @@
         $(".reviewProposalDescription").val( gatewayObject.reviewProposalDescription);
         $(".gatewayAdminFirstName").val( gatewayObject.gatewayAdminFirstName);
         $(".gatewayAdminLastName").val( gatewayObject.gatewayAdminLastName);
+        if (gatewayObject.identityServerPasswordToken) {
+            $(".identityServerPasswordToken").attr("placeholder", "Current token: " + gatewayObject.identityServerPasswordToken);
+        }
         $(".emailAddress").val( gatewayObject.emailAddress);
         $(".identityServerUserName").val( gatewayObject.identityServerUserName);
         $(".oauthClientId").val( gatewayObject.oauthClientId);
@@ -668,6 +679,8 @@
                     $(thisButton).addClass("hide");
                 }
             });
+            // Disallow creating tenant until password is set
+            $("button[value=createTenant]").prop("disabled", !gatewayObject.identityServerPasswordToken);
             $(".approvedGateway").removeClass("hide"); {
                 $('#emailAddress').attr('readonly', false);
                 $('#gatewayURL').attr('readonly', false);
@@ -772,16 +785,29 @@
         $.ajax({
             url: "{{URL::to('/')}}/admin/update-gateway-request",
             method: "GET",
-            data: updateGatewayData
+            data: updateGatewayData,
+            dataType: 'json'
         }).done( function( data){
             $(".loading-gif").remove();
-            if( data == -1 ){
-                //errors only with -1
+            if( data.errors ){
+                var messages = data.validationMessages;
+                var errorMessages = [];
+                for (var field in data.validationMessages) {
+                    Array.prototype.push.apply(errorMessages, data.validationMessages[field]);
+                }
+                var errorMessagesList = $("<ul></ul>");
+                errorMessages.forEach((errorMessage) => {
+                    $("<li></li>").text(errorMessage).appendTo(errorMessagesList);
+                });
                 if( updateVal == "createTenant"){
-                $(".submit-actions").before("<div class='alert alert-danger fail-alert'>All
fields are required to create the gateway! Please make sure you've first updated all the Gateway
details accurately and try again. Ask the Gateway Provider to set a Password token if they
haven't set it yet.");
+                    $(".submit-actions")
+                        .before("<div class='alert alert-danger fail-alert'>All fields
are required to create the gateway! Please make sure you've first updated all the Gateway
details accurately and try again.</div>")
+                        .append(errorMessagesList);
                 }
                 else{
-                    $(".submit-actions").before("<div class='alert alert-danger fail-alert'>Error
updating Gateway. Please try again.");
+                    $("<div class='alert alert-danger fail-alert'>Error updating Gateway.</div>")
+                        .insertBefore(".submit-actions")
+                        .append(errorMessagesList);
                 }
             }
             else{
@@ -799,7 +825,7 @@
 
                 //refresh data next time if same popup is opened.
                 var gatewayIdWithoutSpaces = dataObj['gateway_id'].replace(/\s+/g, '-');
-                $("#view-" +  gatewayIdWithoutSpaces).data("gatewayobject", data);
+                $("#view-" +  gatewayIdWithoutSpaces).data("gatewayobject", data.gateway);
                 $("#view-" + gatewayIdWithoutSpaces ).parent().parent().find(".form-gatewayName").html(
dataObj['gatewayName']);
                 $("#view-" + gatewayIdWithoutSpaces ).parent().parent().find(".form-gatewayURL").html(
dataObj['gatewayURL']);
             }
@@ -860,8 +886,8 @@
     });
 
 
-    $(".qualityOfService").popover({
-        'trigger':'focus'
+    $("[data-toggle=popover]").popover({
+        'trigger': 'focus'
     });
 
     function editableInputs( elem, yes){


Mime
View raw message