Merge remote-tracking branch 'origin/develop' into develop
diff --git a/app/config/pga_config_default_template.php b/app/config/pga_config_default_template.php
deleted file mode 100644
index 9d6be07..0000000
--- a/app/config/pga_config_default_template.php
+++ /dev/null
@@ -1,243 +0,0 @@
-<?php
-return array(
-    /**
-     * *****************************************************************
-     *  These are WSO2 Identity Server Related Configurations
-     * *****************************************************************
-     */
-
-    'wsis' => [
-
-        /**
-         * Admin Role Name
-         */
-        'admin-role-name' => 'admin',
-
-        /**
-         * Read only Admin Role Name
-         */
-        'read-only-admin-role-name' => 'admin-read-only',
-
-        /**
-         * Gateway user role
-         */
-        'user-role-name' => 'airavata-user',
-
-        /**
-         * Tenant Domain
-         */
-        'tenant-domain' => '',
-
-        /**
-         * Tenant admin's username
-         */
-        'admin-username' => 'scigap_admin',
-
-        /**
-         * Tenant admin's password
-         */
-        'admin-password' => 'sci9067@min',
-
-        /**
-         * OAuth client key
-         */
-        'oauth-client-key' => 'fI0fo8luZYsDMPqfIYH8fN6wtfMa',
-
-        /**
-         * OAuth client secret
-         */
-        'oauth-client-secret' => 'cRKUjG8jPUgWj7NxUNT5Tf5621Aa',
-
-        /**
-         * Identity server domain
-         */
-        'server' => 'idp.scigap.org',
-
-        /**
-         * Identity server url
-         */
-        'service-url' => 'https://idp.scigap.org:9443/',
-
-        /**
-         * Enable HTTPS server verification
-         */
-        'verify-peer' => true,
-
-        /**
-         * Path to the server certificate file
-         */
-        'cafile-path' => app_path() . '/resources/security/idp_scigap_org.pem',
-
-        /**
-         * Allow self signed server certificates
-         */
-        'allow-self-signed-cert' => false
-    ],
-
-
-    /**
-     * *****************************************************************
-     *  These are Airavata Related Configurations
-     * *****************************************************************
-     */
-    'airavata' => [
-
-        /**
-         * Airavata API server location. Use tls:// as the protocol to
-         * connect TLS enabled Airavata
-         */
-        'airavata-server' => 'gw56.iu.xsede.org',
-
-        /**
-         * Airavata API server port
-         */
-        'airavata-port' => '8930',
-
-        /**
-         * Airavata API server thrift communication timeout
-         */
-        'airavata-timeout' => '1000000',
-
-        /**
-         * PGA Gateway ID
-         */
-        'gateway-id' => 'scigap',
-
-        /**
-         * Maximum size of a file which is allowed to upload to the server
-         */
-        'server-allowed-file-size' => 64,
-
-        /**
-         * directory in the web server where experiment data is staged. (relative to the PGA documents root)
-         */
-        'experiment-data-dir' => '/../experimentData',
-
-        /**
-         * absolute path of the data dir
-         */
-        'experiment-data-absolute-path' => 'C:\wamp\www\experimentData',
-
-       /**
-         * username for the user for accessing the experiment data over ssh
-         */
-        'ssh-user' => 'root',
-
-        /**
-         * Advanced experiments options
-         */
-        'advanced-experiment-options' => '',
-
-        /**
-         * Default queue name
-         */
-        'queue-name' => 'long',
-
-        /**
-         * Default node count
-         */
-        'node-count' => '1',
-
-        /**
-         * Default total core count
-         */
-        'total-cpu-count' => '16',
-
-        /**
-         * Default wall time limit
-         */
-        'wall-time-limit' => '30',
-
-        /**
-         * Enable app-catalog cache
-         */
-        'enable-app-catalog-cache' => true,
-
-        /**
-         * Life time of app catalog data cache in minutes
-         */
-        'app-catalog-cache-duration' => 5
-    ],
-
-    /**
-     * *****************************************************************
-     *  Portal Related Configurations
-     * *****************************************************************
-     */
-    'portal' => [
-    /**
-         * Whether this portal is the SciGaP admin portal
-         */
-        'super-admin-portal' => true,
-
-        /**
-         * Set the name of theme in use here
-         */
-        'theme' => 'base',
-
-        /**
-         * Portal title
-         */
-        'portal-title' => 'SciGaP Admin Portal',
-
-        /**
-         * Email address of the portal admin. Portal admin well get email notifications for events
-         * such as new user creation
-         */
-        'admin-emails' => ['sgg@iu.edu','eroma.abeysinghe@gmail.com','supun.nakandala@gmail.com'],
-
-        /**
-         * Email account that the portal should login to send emails
-         */
-        'portal-email-username' => 'pga.airavata@gmail.com',
-
-        /**
-         * Password for the portal's email account
-         */
-        'portal-email-password' => 'airavata12',
-
-        /**
-         * SMTP server on which the portal should connect
-         */
-        'portal-smtp-server-host' => 'smtp.gmail.com',
-
-        /**
-         * SMTP server port on which the portal should connect
-         */
-        'portal-smtp-server-port' => '587',
-
-        /**
-         * Set JIRA Issue Collector scripts here.
-         */
-        'jira-help' => 
-        [
-            /**
-             * Report Issue Script issued for your app by Atlassian JIRA
-             */
-            'report-issue-script' => '',
-            /**
-             * Collector id at the end of the above script
-             */
-            'report-issue-collector-id' => '',
-            /**
-             * Create Report Script issued for your app by Atlassian JIRA
-             */
-            'request-feature-script' => '',
-            /**
-             * Collector id at the end of the above script
-             */
-            'request-feature-collector-id' => ''
-        ],
-
-        /**
-         * Set Google Analytics Id here. ID format that generates from  
-         * creating tracker object should be 
-         *
-         * UA-XXXXX-Y 
-         *
-         * for it to be working correctly. Currently it is only set for 
-         * sending pageviews.
-         */
-        'google-analytics-id' => ''
-    ]
-);
\ No newline at end of file
diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php
index b042b7a..32ae4b0 100644
--- a/app/controllers/AccountController.php
+++ b/app/controllers/AccountController.php
@@ -78,7 +78,7 @@
                 if(! in_array( "gateway-provider", $allRoles)){
                     WSIS::addRole( "gateway-provider");
                 }
-                $userRoles["new"] = array("gateway-provider");
+                $userRoles["new"] = array("gateway-provider", "admin");
             }
             $userRoles["deleted"] = array();
             WSIS::updateUserRoles( $username, $userRoles);
@@ -292,24 +292,30 @@
     }
 
     public function dashboard(){
-        //if( Session::has("gateway-provider")){
+
+        $userProfile = Session::get("user-profile");
+
+        if( in_array( "gateway-provider", $userProfile["roles"]) ){
             $gatewayOfUser = "";
-            //var_dump( Session::get("authz-token")->accessToken); exit;
-            $userProfile = Session::get("user-profile");
             $gatewaysInfo = CRUtilities::getAllGateways();
             foreach( $gatewaysInfo as $index => $gateway){
                 if( $gateway->emailAddress == $userProfile["email"]){
                     Session::set("gateway_id", $gateway->gatewayId);
                     $gatewayOfUser = $gateway->gatewayId;
+                    Session::forget("super-admin");
                     break;
                 }
             }
             if( $gatewayOfUser == ""){
-                Session::put("new-gateway-provider");
+                $userInfo["username"] = $userProfile["username"];
+                $userInfo["email"] = $userProfile["email"];
+                Session::put("new-gateway-provider", true);
             }
-       // }
 
-        return View::make("account/dashboard");
+        $errors = array();
+        if( Session::has("errors"))
+            $errors = Session::get("errors");
+        return View::make("account/dashboard",array("message"=> implode( "," , $errors)));
     }
 
     public function resetPassword()
diff --git a/app/controllers/GatewayController.php b/app/controllers/GatewayController.php
new file mode 100644
index 0000000..4f13c57
--- /dev/null
+++ b/app/controllers/GatewayController.php
@@ -0,0 +1,45 @@
+<?php
+
+class GatewayController extends BaseController {
+
+	public function requestGateway(){
+		$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 Redirect::to("account/dashboard", array( "errors"=>$validator->messages() );
+        }
+        else{
+	        $gateway = AdminUtilities::request_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", "Your request for Gateway " . $inputs["gatewayName"] . " has been created.");
+			
+			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;
+		}
+	}
+
+
+}
diff --git a/app/libraries/AdminUtilities.php b/app/libraries/AdminUtilities.php
index edb095f..16fca27 100644
--- a/app/libraries/AdminUtilities.php
+++ b/app/libraries/AdminUtilities.php
@@ -22,6 +22,26 @@
         return Airavata::addGateway(Session::get('authz-token'), $gateway);
     }
 
+    public static function request_gateway( $inputs)
+    {
+        $gateway = new Gateway( $input);
+        $gateway->gatewayId = $input["gateway-name"];
+        $gateway->GatewayApprovalStatus = GatewayApprovalStatus::REQUESTED;
+        $gateway->domain = $input["domain"];
+        $gateway->gatewayName = $input["gateway-name"];
+        $gateway->emailAddress = $input["admin-email"];
+        $gateway->gatewayAcronym = $input["gateway-acronym"];
+        $gateway->gatewayURL = $input["gateway-url"];
+        $gateway->gatewayAdminFirstName = $input["admin-firstname"];
+        $gateway->gatewayAdminLastName = $input["admin-lastname"];
+        $gateway->identityServerUserName = $input["admin-username"];
+        $gateway->identityServerPasswordToken  = $input["admin-password"];
+        $gateway->reviewProposalDescription = $input["project-details"];
+        $gateway->gatewayPublicAbstract - $input["public-project-description"];
+
+        return Airavata::addGateway(Session::get('authz-token'), $gateway);
+    }
+
     /**
      * Method to get experiment execution statistics object
      * @param $fromTime
diff --git a/app/libraries/Airavata/Model/Workspace/Types.php b/app/libraries/Airavata/Model/Workspace/Types.php
index b16d03c..1b516d8 100644
--- a/app/libraries/Airavata/Model/Workspace/Types.php
+++ b/app/libraries/Airavata/Model/Workspace/Types.php
@@ -569,6 +569,26 @@
    * @var string
    */
   public $reviewProposalDescription = null;
+  /**
+   * @var string
+   */
+  public $gatewayAdminFirstName = null;
+  /**
+   * @var string
+   */
+  public $gatewayAdminLastName = null;
+  /**
+   * @var string
+   */
+  public $gatewayAdminEmail = null;
+  /**
+   * @var string
+   */
+  public $identityServerUserName = null;
+  /**
+   * @var string
+   */
+  public $identityServerPasswordToken = null;
 
   public function __construct($vals=null) {
     if (!isset(self::$_TSPEC)) {
@@ -609,6 +629,26 @@
           'var' => 'reviewProposalDescription',
           'type' => TType::STRING,
           ),
+        10 => array(
+          'var' => 'gatewayAdminFirstName',
+          'type' => TType::STRING,
+          ),
+        11 => array(
+          'var' => 'gatewayAdminLastName',
+          'type' => TType::STRING,
+          ),
+        12 => array(
+          'var' => 'gatewayAdminEmail',
+          'type' => TType::STRING,
+          ),
+        13 => array(
+          'var' => 'identityServerUserName',
+          'type' => TType::STRING,
+          ),
+        14 => array(
+          'var' => 'identityServerPasswordToken',
+          'type' => TType::STRING,
+          ),
         );
     }
     if (is_array($vals)) {
@@ -639,6 +679,21 @@
       if (isset($vals['reviewProposalDescription'])) {
         $this->reviewProposalDescription = $vals['reviewProposalDescription'];
       }
+      if (isset($vals['gatewayAdminFirstName'])) {
+        $this->gatewayAdminFirstName = $vals['gatewayAdminFirstName'];
+      }
+      if (isset($vals['gatewayAdminLastName'])) {
+        $this->gatewayAdminLastName = $vals['gatewayAdminLastName'];
+      }
+      if (isset($vals['gatewayAdminEmail'])) {
+        $this->gatewayAdminEmail = $vals['gatewayAdminEmail'];
+      }
+      if (isset($vals['identityServerUserName'])) {
+        $this->identityServerUserName = $vals['identityServerUserName'];
+      }
+      if (isset($vals['identityServerPasswordToken'])) {
+        $this->identityServerPasswordToken = $vals['identityServerPasswordToken'];
+      }
     }
   }
 
@@ -724,6 +779,41 @@
             $xfer += $input->skip($ftype);
           }
           break;
+        case 10:
+          if ($ftype == TType::STRING) {
+            $xfer += $input->readString($this->gatewayAdminFirstName);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        case 11:
+          if ($ftype == TType::STRING) {
+            $xfer += $input->readString($this->gatewayAdminLastName);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        case 12:
+          if ($ftype == TType::STRING) {
+            $xfer += $input->readString($this->gatewayAdminEmail);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        case 13:
+          if ($ftype == TType::STRING) {
+            $xfer += $input->readString($this->identityServerUserName);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
+        case 14:
+          if ($ftype == TType::STRING) {
+            $xfer += $input->readString($this->identityServerPasswordToken);
+          } else {
+            $xfer += $input->skip($ftype);
+          }
+          break;
         default:
           $xfer += $input->skip($ftype);
           break;
@@ -782,6 +872,31 @@
       $xfer += $output->writeString($this->reviewProposalDescription);
       $xfer += $output->writeFieldEnd();
     }
+    if ($this->gatewayAdminFirstName !== null) {
+      $xfer += $output->writeFieldBegin('gatewayAdminFirstName', TType::STRING, 10);
+      $xfer += $output->writeString($this->gatewayAdminFirstName);
+      $xfer += $output->writeFieldEnd();
+    }
+    if ($this->gatewayAdminLastName !== null) {
+      $xfer += $output->writeFieldBegin('gatewayAdminLastName', TType::STRING, 11);
+      $xfer += $output->writeString($this->gatewayAdminLastName);
+      $xfer += $output->writeFieldEnd();
+    }
+    if ($this->gatewayAdminEmail !== null) {
+      $xfer += $output->writeFieldBegin('gatewayAdminEmail', TType::STRING, 12);
+      $xfer += $output->writeString($this->gatewayAdminEmail);
+      $xfer += $output->writeFieldEnd();
+    }
+    if ($this->identityServerUserName !== null) {
+      $xfer += $output->writeFieldBegin('identityServerUserName', TType::STRING, 13);
+      $xfer += $output->writeString($this->identityServerUserName);
+      $xfer += $output->writeFieldEnd();
+    }
+    if ($this->identityServerPasswordToken !== null) {
+      $xfer += $output->writeFieldBegin('identityServerPasswordToken', TType::STRING, 14);
+      $xfer += $output->writeString($this->identityServerPasswordToken);
+      $xfer += $output->writeFieldEnd();
+    }
     $xfer += $output->writeFieldStop();
     $xfer += $output->writeStructEnd();
     return $xfer;
diff --git a/app/routes.php b/app/routes.php
index cd0b20f..f9e55d6 100644
--- a/app/routes.php
+++ b/app/routes.php
@@ -312,6 +312,8 @@
 
 Route::post("admin/remove-pwd-token", "AdminController@removePWD");
 
+//GatewayProviders
+Route::post("provider/request-gateway", "GatewayController@requestGateway");
 
 //notices
 Route::get("admin/dashboard/notices", "AdminController@noticesView");
diff --git a/app/views/account/dashboard.blade.php b/app/views/account/dashboard.blade.php
index 58c2d69..c7a9340 100644
--- a/app/views/account/dashboard.blade.php
+++ b/app/views/account/dashboard.blade.php
@@ -22,14 +22,40 @@
         @if( Session::has('new-gateway-provider') )
         <div class="row">
             <div class="col-md-offset-2 col-md-8">
-                <form id="add-tenant-form" action="{{ URL::to("/") }}/provider/add-gateway">
+                <form id="add-tenant-form" action="{{ URL::to('/') }}/provider/request-gateway">
                     <div class="col-md-12 text-center" style="margin-top:50px;">
-                        <h3>Register your gateway now!</h3>
-                        <button type="button" class="btn btn-default toggle-add-tenant"><span
-                                class="glyphicon glyphicon-plus"></span>Add a new gateway
-                        </button>
+                        <h3>Request your gateway now!</h3>
                     </div>
-                    @include('partials/add-gateway-block', $userInfo)
+                    <div class="form-group required">
+                        <label class="control-label">Gateway Name</label>
+                        <input type="text" name="gateway-name" class="form-control" required="required"/>
+                    </div>
+                    <div class="form-group required">
+                        <label class="control-label">Gateway Acronym <i>(optional)</i></label>
+                        <input type="text" name="gateway-acronym" class="form-control"/>
+                    </div>
+                    <div class="form-group required">
+                        <label class="control-label">Gateway Admin Username</label>
+                        <input type="text" name="admin-username" class="form-control" required="required"/>
+                    </div>
+                    <div class="form-group required">
+                        <label class="control-label">Gateway Admin Password</label>
+                        <input type="text" name="admin-password" class="form-control" required="required"/>
+                    </div>
+                    <div class="form-group required">
+                        <label class="control-label">Gateway Email</label>
+                        <input type="text" name="email-address" class="form-control" required="required"/>
+                    </div>
+                    <div class="form-group required">
+                        <label class="control-label">Project Details</label>
+                        <textarea type="text" name="project-details" class="form-control" required="required"></textarea>
+                    </div>
+                    <div class="form-group required">
+                        <label class="control-label">Public Project Description</label>
+                        <textarea type="text" name="public-project-description" class="form-control" required="required"></textarea>
+                    </div>
+                    <input type="submit" value="Send Request" class="btn btn-primary"/>
+                    <input type="reset" value="Reset" class="btn">
                 </form>
             </div>
         </div>
diff --git a/app/views/admin/manage-gateway.blade.php b/app/views/admin/manage-gateway.blade.php
index 3fb69da..28b7a79 100644
--- a/app/views/admin/manage-gateway.blade.php
+++ b/app/views/admin/manage-gateway.blade.php
@@ -62,6 +62,28 @@
                     @include('partials/add-gateway-block')
                 </form>
             </div>
+            <div class="row">
+                <div class="col-md-12">
+                    <h3>Gateway Requests</h3>
+                    <table class="table table-striped table-bordered">
+                        <th>
+                            <tr>
+                                <td>Gateway Name</td>
+                                <td>Admin Name</td>
+                                <td>Gateway URL</td>
+                                <td>Project Details</td>
+                                <td>Status</td>
+                            </tr>
+                        </th>
+                        <tbody>
+                        <!-- foreach code -->
+                            <tr>
+                            </tr>
+                        <!-- foreach code ends -->
+                        </tbody>
+                    </table>
+                </div>
+            </div>
 
             <div class="panel-group super-admin-gateways-view" id="accordion1">
                 @foreach( $gateways as $indexGP => $gp )