You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2017/06/12 18:31:11 UTC

airavata-php-gateway git commit: AIRAVATA-2408 User profile update email UIs

Repository: airavata-php-gateway
Updated Branches:
  refs/heads/keycloak-integration 3f99eb644 -> 789798870


AIRAVATA-2408 User profile update email UIs


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

Branch: refs/heads/keycloak-integration
Commit: 78979887006be5b64c7abc409a7a37416599fdbb
Parents: 3f99eb6
Author: Marcus Christie <ma...@iu.edu>
Authored: Mon Jun 12 14:30:09 2017 -0400
Committer: Marcus Christie <ma...@iu.edu>
Committed: Mon Jun 12 14:30:09 2017 -0400

----------------------------------------------------------------------
 app/config/email_templates.json                 | 18 ++++++
 app/controllers/UserSettingsController.php      | 58 +++++++++++++++++++
 app/libraries/EmailUtilities.php                | 29 ++++++++++
 app/routes.php                                  |  3 +
 .../account/user-profile-update-email.blade.php | 60 ++++++++++++++++++++
 app/views/account/user-profile.blade.php        | 56 +++++++++---------
 6 files changed, 198 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/78979887/app/config/email_templates.json
----------------------------------------------------------------------
diff --git a/app/config/email_templates.json b/app/config/email_templates.json
index b4e7f1f..f379ca0 100644
--- a/app/config/email_templates.json
+++ b/app/config/email_templates.json
@@ -19,6 +19,24 @@
     ]
   },
 
+  "email_update_verification" : {
+    "subject" : "Verify Your Email Account",
+    "body" : [
+      "<div>",
+          "<p>",
+              "Dear $firstName $lastName,<br/>",
+
+              "Please click on the following link to confirm your email address",
+              " and complete updating your email address<br/>",
+
+              "<a href=\"$url\">$url</a><br/>",
+
+              "This link will expire within $validTime minutes.<br/>",
+          "</p>",
+      "</div>"
+    ]
+  },
+
   "password_reset" : {
     "subject" : "Password Reset Request",
     "body" : [

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/78979887/app/controllers/UserSettingsController.php
----------------------------------------------------------------------
diff --git a/app/controllers/UserSettingsController.php b/app/controllers/UserSettingsController.php
index 0cd69ec..959c5dc 100644
--- a/app/controllers/UserSettingsController.php
+++ b/app/controllers/UserSettingsController.php
@@ -218,4 +218,62 @@ class UserSettingsController extends BaseController
         }
 
     }
+
+    public function showUpdateEmailView() {
+        $userProfile = UserProfileUtilities::get_user_profile(Session::get("username"));
+        return View::make("account/user-profile-update-email", array(
+            "email" => $userProfile->emails[0]
+        ));
+    }
+
+    public function submitUpdateEmail() {
+
+        try {
+            $username = Session::get("username");
+            $newEmail = Input::get("newEmail");
+            $user_profile = UserProfileUtilities::get_user_profile($username);
+            EmailUtilities::sendVerifyUpdatedEmailAccount($username, $user_profile->firstName, $user_profile->lastName, $newEmail);
+            Session::put("UserSettingsController_newEmail", $newEmail);
+            return Redirect::to("account/user-profile")->with("message",
+                "Confirmation email has been sent to " . htmlspecialchars($newEmail)
+                . ". Please click on the confirmation link in the email once you receive it.");
+        } catch (Exception $e) {
+            return View::make("account/user-profile-update-email", array(
+                "email" => Input::get("newEmail"),
+                "errorMessage" => "An error occurred while trying to submit updated email address: " . $e->getMessage()
+            ));
+        }
+    }
+
+    public function confirmUpdateEmail() {
+
+        try {
+            $username = Input::get("username");
+            $code = Input::get("code");
+
+            $verified = EmailUtilities::verifyUpdatedEmailAccount($username, $code);
+            if ($verified) {
+                $newEmail = Session::get("UserSettingsController_newEmail");
+                if (empty($newEmail)) {
+                    throw new Exception("New email not found in session");
+                }
+                $user_profile = UserProfileUtilities::get_user_profile($username);
+                $user_profile->emails = array($newEmail);
+                $result = UserProfileUtilities::update_user_profile($user_profile);
+                if ($result) {
+                    return Redirect::to("account/user-profile")->with(
+                        "message", "Email address updated successfully");
+                } else {
+                    return Redirect::to("account/user-profile-update-email")->with(
+                        "errorMessage", "Failed to update email address, please try again.");
+                }
+            } else {
+                return Redirect::to("account/user-profile-update-email")->with(
+                    "errorMessage", "Failed to update email address, please try again. Reason: confirmation link was not verified successfully.");
+            }
+        } catch (Exception $e) {
+            return Redirect::to("account/user-profile-update-email")->with(
+                "errorMessage", "Failed to update email address, please try again. Reason: " . $e->message);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/78979887/app/libraries/EmailUtilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/EmailUtilities.php b/app/libraries/EmailUtilities.php
index 541d9f2..7f55afc 100644
--- a/app/libraries/EmailUtilities.php
+++ b/app/libraries/EmailUtilities.php
@@ -32,6 +32,35 @@ class EmailUtilities
         }
     }
 
+    public static function sendVerifyUpdatedEmailAccount($username, $firstName, $lastName, $email){
+        $portalConfig = Config::get('pga_config.portal');
+        $validTime = isset($portalConfig['mail-verify-code-valid-time']) ? $portalConfig['mail-verify-code-valid-time'] : 30;
+        $code = uniqid();
+        Cache::put('PGA-VERIFY-UPDATED-EMAIL-' . $username, $code, $validTime);
+
+        $emailTemplates = json_decode(File::get(app_path() . '/config/email_templates.json'));
+        $subject = $emailTemplates->email_update_verification->subject;
+        $body = trim(implode($emailTemplates->email_update_verification->body));
+
+        $body = str_replace("\$url", URL::to('/') . '/user-profile-confirm-email?username=' . $username . '&code=' . $code, $body);
+        $body = str_replace("\$firstName", $firstName, $body);
+        $body = str_replace("\$lastName", $lastName, $body);
+        $body = str_replace("\$validTime", $validTime, $body);
+
+        EmailUtilities::sendEmail($subject, [$email], $body);
+    }
+
+    public static function verifyUpdatedEmailAccount($username, $code){
+        if(Cache::has('PGA-VERIFY-UPDATED-EMAIL-' . $username)){
+            $storedCode = Cache::get('PGA-VERIFY-UPDATED-EMAIL-' . $username);
+            Cache::forget('PGA-VERIFY-UPDATED-EMAIL-' . $username);
+            return $storedCode == $code;
+        }else{
+            return false;
+        }
+    }
+
+
     public static function sendPasswordResetEmail($username, $firstName, $lastName, $email){
         $portalConfig = Config::get('pga_config.portal');
         $validTime = isset($portalConfig['mail-verify-code-valid-time']) ? $portalConfig['mail-verify-code-valid-time'] : 30;

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/78979887/app/routes.php
----------------------------------------------------------------------
diff --git a/app/routes.php b/app/routes.php
index 1486751..8ab72fc 100755
--- a/app/routes.php
+++ b/app/routes.php
@@ -66,6 +66,9 @@ Route::post("account/delete-user-srp", "UserSettingsController@deleteUserStorage
 
 Route::get("account/user-profile", "UserSettingsController@getUserProfile");
 Route::post("account/user-profile", "UserSettingsController@updateUserProfile");
+Route::get("account/user-profile-update-email", "UserSettingsController@showUpdateEmailView");
+Route::post("account/user-profile-update-email", "UserSettingsController@submitUpdateEmail");
+Route::get("user-profile-confirm-email", "UserSettingsController@confirmUpdateEmail");
 
 /*
  * The following routes will not work without logging in.

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/78979887/app/views/account/user-profile-update-email.blade.php
----------------------------------------------------------------------
diff --git a/app/views/account/user-profile-update-email.blade.php b/app/views/account/user-profile-update-email.blade.php
new file mode 100644
index 0000000..ea05bfb
--- /dev/null
+++ b/app/views/account/user-profile-update-email.blade.php
@@ -0,0 +1,60 @@
+
+@extends('layout.basic')
+
+@section('page-header')
+@parent
+{{ HTML::style('css/user-settings.css')}}
+@stop
+
+@section('content')
+<div class="container">
+    <ol class="breadcrumb">
+        <li><a href="{{ URL::to('account/settings') }}">User Settings</a></li>
+        <li><a href="{{ URL::to('account/user-profile') }}">Your Profile</a></li>
+        <li class="active">Update Email</li>
+    </ol>
+
+    @if( Session::has("message") )
+        <div class="alert alert-success alert-dismissible" role="alert">
+            <button type="button" class="close" data-dismiss="alert"><span
+                    aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
+            {{{ Session::get("message") }}}
+        </div>
+    @endif
+
+    @if( isset($errorMessage) )
+        <div class="alert alert-danger" role="alert">
+            {{{ $errorMessage }}}
+        </div>
+    @endif
+
+    <div class="row">
+        <div class="col-md-6 col-md-offset-3">
+            <h1>Email address update for {{ Session::get("username") }}</h1>
+        </div>
+    </div>
+
+    <div class="row">
+        <div class="col-md-6 col-md-offset-3">
+            <p>
+                Once you submit the following updated email address we'll send
+                you an email to confirm the email address.
+            </p>
+
+            <form action="{{ URL::to("account/user-profile-update-email") }}" method="post" role="form">
+
+                <div class="form-group required">
+                    <label class="control-label">Email</label>
+                    <div><input class="form-control" id="newEmail" maxlength="50" name="newEmail"
+                                placeholder="Email address" type="text"
+                                value="{{{ $email }}}"/></div>
+                </div>
+
+                <input name="update" type="submit" class="btn btn-primary btn-block" value="Submit">
+            </form>
+        </div>
+    </div>
+
+</div>
+
+@stop

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/78979887/app/views/account/user-profile.blade.php
----------------------------------------------------------------------
diff --git a/app/views/account/user-profile.blade.php b/app/views/account/user-profile.blade.php
index 09bea45..e7d9e3b 100644
--- a/app/views/account/user-profile.blade.php
+++ b/app/views/account/user-profile.blade.php
@@ -35,34 +35,38 @@
 
     <div class="row">
         <div class="col-md-6 col-md-offset-3">
-    <form action="{{ URL::to("account/user-profile") }}" method="post" role="form">
+            <form action="{{ URL::to("account/user-profile") }}" method="post" role="form">
 
-        <div class="form-group">
-            <label class="control-label">E-mail</label>
-            <p class="form-control-static">{{{ $userProfile->emails[0] }}}</p>
-        </div>
-        <div class="form-group required">
-            <label class="control-label">First Name</label>
-            <div><input class="form-control" id="firstName" maxlength="50" name="firstName"
-                        placeholder="Name" type="text"
-                        value="{{{ $userProfile->firstName }}}"/></div>
-        </div>
-        <div class="form-group required">
-            <label class="control-label">Last Name</label>
-            <div><input class="form-control" id="lastName" maxlength="50" name="lastName"
-                        placeholder="Name" type="text"
-                        value="{{{ $userProfile->lastName }}}"/></div>
-        </div>
-        <div class="form-group">
-            <label class="control-label">Organization</label>
-            <div><input class="form-control" id="homeOrganization" name="homeOrganization"
-                        placeholder="Organization" type="text"
-                        value="{{{ $userProfile->homeOrganization }}}"/>
-            </div>
-        </div>
+                <div class="form-group">
+                    <label class="control-label">Email</label>
+                    <p class="form-control-static">{{{ $userProfile->emails[0] }}}
+                        <a href="{{ URL::to("account/user-profile-update-email") }}" role="button" class="btn btn-primary btn-sm">Update Email</a>
+                    </p>
+                </div>
+                <div class="form-group required">
+                    <label class="control-label">First Name</label>
+                    <div><input class="form-control" id="firstName" maxlength="50" name="firstName"
+                                placeholder="Name" type="text"
+                                value="{{{ $userProfile->firstName }}}"/></div>
+                </div>
+                <div class="form-group required">
+                    <label class="control-label">Last Name</label>
+                    <div><input class="form-control" id="lastName" maxlength="50" name="lastName"
+                                placeholder="Name" type="text"
+                                value="{{{ $userProfile->lastName }}}"/></div>
+                </div>
+                <div class="form-group">
+                    <label class="control-label">Organization</label>
+                    <div><input class="form-control" id="homeOrganization" name="homeOrganization"
+                                placeholder="Organization" type="text"
+                                value="{{{ $userProfile->homeOrganization }}}"/>
+                    </div>
+                </div>
 
-        <input name="update" type="submit" class="btn btn-primary btn-block" value="Update">
-    </form>
+                <input name="update" type="submit" class="btn btn-primary btn-block" value="Update">
+            </form>
+        </div>
+    </div>
 
 </div>