airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject airavata-php-gateway git commit: AIRAVATA-2430 External ID providers on Create Account page
Date Sat, 24 Jun 2017 17:57:21 GMT
Repository: airavata-php-gateway
Updated Branches:
  refs/heads/develop 6882604f0 -> b5cc85089


AIRAVATA-2430 External ID providers on Create Account page


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

Branch: refs/heads/develop
Commit: b5cc850891abdede59258b2ab99592bc59e0ee0b
Parents: 6882604
Author: Marcus Christie <machrist@iu.edu>
Authored: Sat Jun 24 13:56:22 2017 -0400
Committer: Marcus Christie <machrist@iu.edu>
Committed: Sat Jun 24 13:56:22 2017 -0400

----------------------------------------------------------------------
 app/controllers/AccountController.php       | 27 +++++++---------
 app/libraries/CommonUtilities.php           | 40 ++++++++++++++++++++++--
 app/views/account/create.blade.php          | 14 +++++++--
 app/views/account/login.blade.php           |  6 ++--
 app/views/partials/login-external.blade.php |  4 +++
 5 files changed, 68 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/b5cc8508/app/controllers/AccountController.php
----------------------------------------------------------------------
diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php
index ddec450..5f2fafe 100644
--- a/app/controllers/AccountController.php
+++ b/app/controllers/AccountController.php
@@ -12,7 +12,15 @@ class AccountController extends BaseController
 
     public function createAccountView()
     {
-        return View::make('account/create');
+        $auth_options = Config::get('pga_config.wsis')['auth-options'];
+        $auth_password_option = CommonUtilities::getAuthPasswordOption();
+        if ($auth_password_option == null) {
+            return Redirect::to("login");
+        }
+        $auth_code_options = CommonUtilities::getAuthCodeOptions();
+        return View::make('account/create', array(
+            "auth_password_option" => $auth_password_option,
+            "auth_code_options" => $auth_code_options));
     }
 
     public function createAccountSubmit()
@@ -67,23 +75,10 @@ class AccountController extends BaseController
             return Redirect::to("home");
         }
 
-        $auth_options = Config::get('pga_config.wsis')['auth-options'];
         // Only support for one password option
-        $auth_password_option = null;
+        $auth_password_option = CommonUtilities::getAuthPasswordOption();
         // Support for many external identity providers (authorization code auth flow)
-        $auth_code_options = array();
-        foreach ($auth_options as $auth_option) {
-            if ($auth_option["oauth-grant-type"] == "password") {
-                $auth_password_option = $auth_option;
-            } else if ($auth_option["oauth-grant-type"] == "authorization_code") {
-                $extra_params = isset($auth_option["oauth-authorize-url-extra-params"]) ?
$auth_option["oauth-authorize-url-extra-params"] : null;
-                $auth_url = Keycloak::getOAuthRequestCodeUrl($extra_params);
-                $auth_option["auth_url"] = $auth_url;
-                $auth_code_options[] = $auth_option;
-            } else {
-                throw new Exception("Unrecognized oauth-grant-type: " . $auth_option["oauth-grant-type"]);
-            }
-        }
+        $auth_code_options = CommonUtilities::getAuthCodeOptions();
 
         // If no username/password option and only one external identity
         // provider, just redirect immediately

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/b5cc8508/app/libraries/CommonUtilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/CommonUtilities.php b/app/libraries/CommonUtilities.php
index 53f790e..c90765c 100644
--- a/app/libraries/CommonUtilities.php
+++ b/app/libraries/CommonUtilities.php
@@ -249,8 +249,10 @@ class CommonUtilities
             $navbar .= '</ul></li>';
         } else {
 
-                    $navbar .= '<li><a href="' . URL::to('/') . '/create"><span
class="glyphicon glyphicon-user"></span> Create account</a></li>';
-                    $navbar .= '<li><a href="' . URL::to('/') . '/login"><span
class="glyphicon glyphicon-log-in"></span> Log in</a></li>';
+            if( CommonUtilities::hasAuthPasswordOption() ){
+                $navbar .= '<li><a href="' . URL::to('/') . '/create"><span
class="glyphicon glyphicon-user"></span> Create account</a></li>';
+            }
+            $navbar .= '<li><a href="' . URL::to('/') . '/login"><span class="glyphicon
glyphicon-log-in"></span> Log in</a></li>';
         }
 
         $navbar .= '</ul></div></div></nav>';
@@ -442,5 +444,39 @@ class CommonUtilities
     public static function getInitialRoleName() {
         return Config::get('pga_config.wsis.initial-role-name', 'user-pending');
     }
+
+    public static function hasAuthPasswordOption() {
+        return CommonUtilities::getAuthPasswordOption() != null;
+    }
+
+    public static function getAuthPasswordOption() {
+
+        $auth_options = Config::get('pga_config.wsis')['auth-options'];
+        $auth_password_option_array = array_filter($auth_options, function($auth_option)
{
+            return $auth_option["oauth-grant-type"] == "password";
+        });
+        return count($auth_password_option_array) > 0 ? $auth_password_option_array[0]
: null;
+    }
+
+    public static function getAuthCodeOptions() {
+
+        $auth_options = Config::get('pga_config.wsis')['auth-options'];
+        // Support for many external identity providers (authorization code auth flow)
+        $auth_code_options = array();
+        foreach ($auth_options as $auth_option) {
+            if ($auth_option["oauth-grant-type"] == "password") {
+                continue;
+            } else if ($auth_option["oauth-grant-type"] == "authorization_code") {
+                $extra_params = isset($auth_option["oauth-authorize-url-extra-params"]) ?
$auth_option["oauth-authorize-url-extra-params"] : null;
+                $auth_url = Keycloak::getOAuthRequestCodeUrl($extra_params);
+                $auth_option["auth_url"] = $auth_url;
+                $auth_code_options[] = $auth_option;
+            } else {
+                throw new Exception("Unrecognized oauth-grant-type: " . $auth_option["oauth-grant-type"]);
+            }
+        }
+        return $auth_code_options;
+    }
+
 }
 

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/b5cc8508/app/views/account/create.blade.php
----------------------------------------------------------------------
diff --git a/app/views/account/create.blade.php b/app/views/account/create.blade.php
index d13d72b..4304980 100644
--- a/app/views/account/create.blade.php
+++ b/app/views/account/create.blade.php
@@ -7,10 +7,11 @@
 @section('content')
 
 <div class="col-md-offset-4 col-md-4">
+    @if (!empty($auth_password_option))
     <div class="page-header">
-        <h3>Create New Account
+        <h3>Create New {{{ $auth_password_option["name"] }}} Account
             <small>
-                <small> (Already registered? <a href="login">Log in</a>)</small>
+                <small> (Already registered? <a href="login">Log in with {{{
$auth_password_option["name"] }}}</a>)</small>
             </small>
         </h3>
     </div>
@@ -72,6 +73,15 @@
         <input name="Submit" type="submit" class="btn btn-primary btn-block" value="Create">
     </form>
 
+        @if (!empty($auth_code_options))
+            <h4>OR</h4>
+        @endif
+    @endif {{-- @if (!empty($auth_password_option)) --}}
+
+    @if (!empty($auth_code_options))
+        @include('partials/login-external', array("auth_code_options" => $auth_code_options))
+    @endif
+
     <style media="screen" type="text/css">
         .form-group.required .control-label:after {
             content: " *";

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/b5cc8508/app/views/account/login.blade.php
----------------------------------------------------------------------
diff --git a/app/views/account/login.blade.php b/app/views/account/login.blade.php
index 5d79738..e04a3fb 100755
--- a/app/views/account/login.blade.php
+++ b/app/views/account/login.blade.php
@@ -14,9 +14,9 @@
             <h4>OR</h4>
         @endif
     @endif
-    @foreach ($auth_code_options as $auth_code_option)
-        <a href="{{ $auth_code_option["auth_url"] }}" class="btn btn-primary">Sign
in with {{{ $auth_code_option["name"] }}}</a>
-    @endforeach
+    @if (!empty($auth_code_options))
+        @include('partials/login-external', array("auth_code_options" => $auth_code_options))
+    @endif
 </div>
 
 @stop
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/b5cc8508/app/views/partials/login-external.blade.php
----------------------------------------------------------------------
diff --git a/app/views/partials/login-external.blade.php b/app/views/partials/login-external.blade.php
new file mode 100644
index 0000000..15e3f7c
--- /dev/null
+++ b/app/views/partials/login-external.blade.php
@@ -0,0 +1,4 @@
+
+@foreach ($auth_code_options as $auth_code_option)
+    <a href="{{ $auth_code_option["auth_url"] }}" class="btn btn-primary">Sign in with
{{{ $auth_code_option["name"] }}}</a>
+@endforeach


Mime
View raw message