You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by nd...@apache.org on 2016/01/29 21:29:30 UTC

airavata-php-gateway git commit: Password validation while adding a gateway made stricter.

Repository: airavata-php-gateway
Updated Branches:
  refs/heads/develop 6ce392462 -> 30f9d7ff7


Password validation while adding a gateway made stricter.


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/30f9d7ff
Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/30f9d7ff
Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/30f9d7ff

Branch: refs/heads/develop
Commit: 30f9d7ff77ff4c9030cebf6711f60805f013465b
Parents: 6ce3924
Author: Nipurn Doshi <ni...@gmail.com>
Authored: Fri Jan 29 15:28:56 2016 -0500
Committer: Nipurn Doshi <ni...@gmail.com>
Committed: Fri Jan 29 15:28:56 2016 -0500

----------------------------------------------------------------------
 app/controllers/AdminController.php      | 115 ++++++++++++++++----------
 app/views/admin/manage-gateway.blade.php |  27 ++++--
 2 files changed, 89 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/30f9d7ff/app/controllers/AdminController.php
----------------------------------------------------------------------
diff --git a/app/controllers/AdminController.php b/app/controllers/AdminController.php
index 54b92e1..a78c3ad 100644
--- a/app/controllers/AdminController.php
+++ b/app/controllers/AdminController.php
@@ -163,23 +163,6 @@ class AdminController extends BaseController {
 			return WSIS::updateUserRoles(Input::get("username"), array("new"=> array(), "deleted" => Input::get("roles") ) );
 	}
 
-
-	/* ---- Super Admin Functions ------- */
-
-	public function addGateway(){
-		$inputs = Input::all();
-
-        $gateway = AdminUtilities::add_gateway(Input::all());
-
-		$tm = WSIS::createTenant(1, $inputs["admin-username"] . "@" . $inputs["domain"], $inputs["admin-password"],
-			$inputs["admin-email"], $inputs["admin-firstname"], $inputs["admin-lastname"], $inputs["domain"]);
-
-		Session::put("message", "Gateway " . $inputs["gatewayName"] . " has been added.");
-		return Response::json( $tm);
-		//return Redirect::to("admin/dashboard/gateway")->with("message", "Gateway has been successfully added.");
-	}
-
-
     public function experimentStatistics()
     {
         if (Request::ajax()) {
@@ -204,6 +187,76 @@ class AdminController extends BaseController {
         }
     }
 
+	public function createSSH(){
+		$newToken = AdminUtilities::create_ssh_token();
+		$pubkey = AdminUtilities::get_pubkey_from_token( $newToken);
+		return Response::json( array( "token" => $newToken, "pubkey" => $pubkey));
+
+	}
+
+	public function removeSSH(){
+		$removeToken = Input::get("token");
+		if( AdminUtilities::remove_ssh_token( $removeToken) )
+			return 1;
+		else
+			return 0;
+
+	}
+
+	public function getUsersWithRole( $role){
+			$users = WSIS::getUserlistOfRole( $role);
+			if( isset( $users->return))
+		    	$users = $users->return;
+		    else
+		    	$users = array();
+
+		    return $users;
+	}
+
+
+	/* ---- Super Admin Functions ------- */
+
+	public function addGateway(){
+		$inputs = Input::all();
+
+		$rules = array(
+            "username" => "required|min:6",
+            "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 - !@#$%&*',
+        );
+
+        $checkValidation = array();
+        $checkValidation["username"] = $inputs["admin-username"];
+        $checkValidation["password"] = $inputs["admin-password"];
+        $checkValidation["confirm_password"] = $inputs["admin-password-confirm"];
+        $checkValidation["email"] = $inputs["admin-email"];
+
+        $validator = Validator::make( $checkValidation, $rules, $messages);
+        if ($validator->fails()) {
+            return Response::json( $validator->messages() );
+        }
+        else{
+	        $gateway = AdminUtilities::add_gateway(Input::all());
+
+			$tm = WSIS::createTenant(1, $inputs["admin-username"] . "@" . $inputs["domain"], $inputs["admin-password"],
+				$inputs["admin-email"], $inputs["admin-firstname"], $inputs["admin-lastname"], $inputs["domain"]);
+
+			Session::put("message", "Gateway " . $inputs["gatewayName"] . " has been added.");
+			
+			return Response::json( array( "gateway" =>$gateway, "tm" => $tm ) ); 
+			if( $gateway ==  $inputs["gatewayName"] && is_object( $tm ) )
+				return Response::json( array( "gateway" =>$gateway, "tm" => $tm ) ); 
+			else
+				return 0;
+			//return Redirect::to("admin/dashboard/gateway")->with("message", "Gateway has been successfully added.");
+		}
+	}
+
     public function enableComputeResource(){
         $resourceId = Input::get("resourceId");
         $computeResource = CRUtilities::get_compute_resource($resourceId);
@@ -231,32 +284,4 @@ class AdminController extends BaseController {
         $storageResource->enabled = false;
         SRUtilities::register_or_update_storage_resource($storageResource, true);
     }
-
-
-	public function createSSH(){
-		$newToken = AdminUtilities::create_ssh_token();
-		$pubkey = AdminUtilities::get_pubkey_from_token( $newToken);
-		return Response::json( array( "token" => $newToken, "pubkey" => $pubkey));
-
-	}
-
-	public function removeSSH(){
-		$removeToken = Input::get("token");
-		if( AdminUtilities::remove_ssh_token( $removeToken) )
-			return 1;
-		else
-			return 0;
-
-	}
-
-	public function getUsersWithRole( $role){
-			$users = WSIS::getUserlistOfRole( $role);
-			if( isset( $users->return))
-		    	$users = $users->return;
-		    else
-		    	$users = array();
-
-		    return $users;
-	}
-
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/30f9d7ff/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 7e99d3f..e776797 100644
--- a/app/views/admin/manage-gateway.blade.php
+++ b/app/views/admin/manage-gateway.blade.php
@@ -38,7 +38,6 @@
                 <div class="col-md-6">
                     <h3>Other Gateway Preferences</h3>
                 </div>
-                @if( Session::has("super-admin"))
                 <div class="col-md-6" style="margin-top:2%">
                     <input type="text" class="col-md-12 filterinput" placeholder="Search by Gateway Name"/>
                 </div>
@@ -55,7 +54,7 @@
                         </div>
                         <div class="form-group required">
                             <label class="control-label">Enter Desired Gateway Name</label>
-                            <input type="text" name="gatewayName" class="form-control" required="required"/>
+                            <input type="text" name="gatewayName" class="form-control gatewayName" required="required"/>
                         </div>
                         <div class="form-group required">
                             <label class="control-label">Enter Admin Email Address</label>
@@ -89,7 +88,6 @@
                     <div class="col-md-6 alert alert-danger gateway-error hide"></div>
                     <div class="col-md-6 alert alert-success gateway-success hide"></div>
                 </form>
-                 @endif
             </div>
 
             <div class="panel-group" id="accordion1">
@@ -100,7 +98,6 @@
                     @endforeach
                 </div>
             </div>
-
             @endif
 
         </div>
@@ -284,10 +281,24 @@
             data: formData,
             url: '{{ URL::to("/") }}/admin/add-gateway',
             success: function (data) {
-                $(".gateway-success").html("Gateway has been added. The page will be reloaded in a moment.").removeClass("hide");
-                setTimeout( function(){
-                    location.reload();
-                }, 2000);
+                if( data.gateway == $(".gatewayName").val() ){
+                    $(".gateway-success").html("Gateway has been added. The page will be reloaded in a moment.").removeClass("hide");
+                    setTimeout( function(){
+                        location.reload();
+                    }, 2000);
+                }
+                else if( data == 0){
+                    $(".gateway-error").html( "An unknown error occurred while trying to create the gateway.")
+                                        .removeClass("hide");
+                }
+                else{
+                    errors = data;
+                    $(".gateway-error").html("").removeClass("hide");
+                    for( input in data)
+                    {
+                        $(".gateway-error").append(" -- " + input + " : " + data[input] + "<br/><br/>");
+                    }
+                }
             },
             error: function( data){
                 var error = $.parseJSON( data.responseText);