Repository: airavata-php-gateway Updated Branches: refs/heads/master cf050d52b -> d7e5b727e
User email verification when creating a user account 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/42e8876b Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/42e8876b Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/42e8876b Branch: refs/heads/master Commit: 42e8876bac60f262695ddac443697ddd6dc938f8 Parents: c0780d5 Author: scnakandala <[email protected]> Authored: Mon Oct 12 23:17:57 2015 -0400 Committer: scnakandala <[email protected]> Committed: Mon Oct 12 23:17:57 2015 -0400 ---------------------------------------------------------------------- app/config/pga_config.php.template | 5 ++ app/controllers/AccountController.php | 57 +++++++++++++----- app/filters.php | 4 ++ .../Stubs/UserInformationRecoveryManager.php | 63 ++++++++++++++++++++ app/libraries/Wsis/Stubs/UserStoreManager.php | 4 +- app/libraries/Wsis/Wsis.php | 52 +++++++++++++++- app/routes.php | 2 + app/views/account/create.blade.php | 2 + 8 files changed, 169 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/42e8876b/app/config/pga_config.php.template ---------------------------------------------------------------------- diff --git a/app/config/pga_config.php.template b/app/config/pga_config.php.template index 292ecc2..535fdea 100644 --- a/app/config/pga_config.php.template +++ b/app/config/pga_config.php.template @@ -24,6 +24,11 @@ return array( 'user-role-name' => 'airavata-user', /** + * Tenant Domain + */ + 'tenant-domain' => 'master.airavata', + + /** * Tenant admin's username */ 'admin-username' => '[email protected]', http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/42e8876b/app/controllers/AccountController.php ---------------------------------------------------------------------- diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index eac2f0b..afe7bd3 100755 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -12,7 +12,7 @@ class AccountController extends BaseController { $rules = array( "username" => "required|min:6", - "password" => "required|min:6", + "password" => "required|min:6|(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*\W).{6,16})", "confirm_password" => "required|same:password", "email" => "required|email", ); @@ -54,20 +54,24 @@ class AccountController extends BaseController ->withInput(Input::except('password', 'password_confirm')) ->with("username_exists", true); } else { - WSIS::addUser($username, $password, $first_name, $last_name, $email, $organization, - $address, $country, $telephone, $mobile, $im, $url); - - //update user profile - WSIS::updateUserProfile($username, $email, $first_name, $last_name); - - CommonUtilities::print_success_message('New user created!'); - - if(Config::get('pga_config.wsis')['auth-mode']=="oauth"){ - return View::make('home'); - }else{ - return View::make('account/login'); - } - +// WSIS::addUser($username, $password); +// +// //update user profile +// WSIS::updateUserProfile($username, $email, $first_name, $last_name); +// +// CommonUtilities::print_success_message('New user created!'); +// +// if(Config::get('pga_config.wsis')['auth-mode']=="oauth"){ +// return View::make('home'); +// }else{ +// return View::make('account/login'); +// } + + WSIS::registerUserAccount($username, $password, $email, $first_name, $last_name, + Config::get('pga_config.wsis')['tenant-domain']); + + CommonUtilities::print_success_message('Account confirmation request was sent to your email account'); + return View::make('home'); } } @@ -237,7 +241,7 @@ class AccountController extends BaseController if(empty($username) || empty($confirmation)){ return View::make("home"); }else{ - $username = $username . "@" . explode("@",Config::get('pga_config.wsis')['admin-username'])[1]; + $username = $username . "@" . Config::get('pga_config.wsis')['tenant-domain']; try{ $key = WSIS::validateConfirmationCode($username, $confirmation); if(!empty($key)){ @@ -252,6 +256,27 @@ class AccountController extends BaseController } + public function confirmAccountCreation() + { + $confirmation = Input::get("confirmation"); + $username = Input::get("username"); + if(empty($username) || empty($confirmation)){ + return View::make("home"); + }else{ + try{ + $result = WSIS::confirmUserRegistration($username, $confirmation, Config::get('pga_config.wsis')['tenant-domain']); + if($result){ + return View::make("account/login"); + }else{ + return View::make("home"); + } + }catch (Exception $e){ + var_dump($e);exit; + return View::make("home"); + } + } + } + public function resetPasswordSubmit() { $rules = array( http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/42e8876b/app/filters.php ---------------------------------------------------------------------- diff --git a/app/filters.php b/app/filters.php index 1446331..aa022ac 100755 --- a/app/filters.php +++ b/app/filters.php @@ -11,6 +11,10 @@ | */ +// To invalidate the SOAP WSDL caches +// ini_set('soap.wsdl_cache_enabled',0); +// ini_set('soap.wsdl_cache_ttl',0); + App::before(function ($request) { //Check OAuth token has expired if(Config::get('pga_config.wsis')['auth-mode']=="oauth" && Session::has('authz-token')){ http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/42e8876b/app/libraries/Wsis/Stubs/UserInformationRecoveryManager.php ---------------------------------------------------------------------- diff --git a/app/libraries/Wsis/Stubs/UserInformationRecoveryManager.php b/app/libraries/Wsis/Stubs/UserInformationRecoveryManager.php index a9df7c6..e03788d 100755 --- a/app/libraries/Wsis/Stubs/UserInformationRecoveryManager.php +++ b/app/libraries/Wsis/Stubs/UserInformationRecoveryManager.php @@ -1,6 +1,7 @@ <?php namespace Wsis\Stubs; +use Illuminate\Support\Facades\Config; use Wsis\Stubs\UserInformationRecoveryStub; /** @@ -88,4 +89,66 @@ class UserInformationRecoveryManager { $result = $this->serviceStub->updatePassword($updatePassword); return $result->return->verified; } + + + /** + * Function to create a user account. This user account is not activate unless activated by the user + * via email + * @param $username + * @param $password + * @param $email + * @param $firstName + * @param $lastName + * @param $tenantDomain + * @return mixed + */ + public function registerAccount($username, $password, $email,$firstName, $lastName, $tenantDomain){ + + $registerUser = new registerUser(); + $registerUser->userName = $username; + $registerUser->password = $password; + $registerUser->profileName = "default"; + $registerUser->tenantDomain = $tenantDomain; + + $fieldValues = array(); + $usernameDTO = new UserIdentityClaimDTO(); + $usernameDTO->claimUri = "http://wso2.org/claims/username"; + $usernameDTO->claimValue = $username; + array_push($fieldValues, $usernameDTO); + + $emailDTO = new UserIdentityClaimDTO; + $emailDTO->claimUri = "http://wso2.org/claims/emailaddress"; + $emailDTO->claimValue = $email; + array_push($fieldValues, $emailDTO); + + $firstNameDTO = new UserIdentityClaimDTO(); + $firstNameDTO->claimUri = "http://wso2.org/claims/givenname"; + $firstNameDTO->claimValue = $firstName; + array_push($fieldValues, $firstNameDTO); + + $lastNameDTO = new UserIdentityClaimDTO(); + $lastNameDTO->claimUri = "http://wso2.org/claims/lastname"; + $lastNameDTO->claimValue = $lastName; + array_push($fieldValues, $lastNameDTO); + $registerUser->claims = $fieldValues; + + $result = $this->serviceStub->registerUser($registerUser); + return $result->return->verified; + } + + + /** + * Function to confirm user registration + * @param $userName + * @param $tenantDomain + */ + public function confirmUserRegistration($userName, $code, $tenantDomain){ + $confirmUserSelfRegistration = new confirmUserSelfRegistration(); + $confirmUserSelfRegistration->username = $userName; + $confirmUserSelfRegistration->code = $code; + $confirmUserSelfRegistration->tenantDomain = $tenantDomain; + $result = $this->serviceStub->confirmUserSelfRegistration($confirmUserSelfRegistration); + return $result->return->verified; + return $result->return->verified; + } } http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/42e8876b/app/libraries/Wsis/Stubs/UserStoreManager.php ---------------------------------------------------------------------- diff --git a/app/libraries/Wsis/Stubs/UserStoreManager.php b/app/libraries/Wsis/Stubs/UserStoreManager.php index 479b320..706f847 100755 --- a/app/libraries/Wsis/Stubs/UserStoreManager.php +++ b/app/libraries/Wsis/Stubs/UserStoreManager.php @@ -49,12 +49,12 @@ class UserStoreManager { * @param type $userName * @param type $password */ - public function addUser($userName, $password, $fullName){ + public function addUser($userName, $password){ $parameters = new AddUser(); $parameters->userName = $userName; $parameters->credential = $password; $parameters->claims = null; - $parameters->profileName = $fullName; + $parameters->profileName = "default"; $parameters->requirePasswordChange = false; $parameters->roleList = null; $this->serviceStub->addUser($parameters); http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/42e8876b/app/libraries/Wsis/Wsis.php ---------------------------------------------------------------------- diff --git a/app/libraries/Wsis/Wsis.php b/app/libraries/Wsis/Wsis.php index 221d943..b684887 100755 --- a/app/libraries/Wsis/Wsis.php +++ b/app/libraries/Wsis/Wsis.php @@ -111,14 +111,35 @@ class Wsis { * @return void * @throws Exception */ - public function addUser($userName, $password, $fullName) { + public function addUser($userName, $password) { try { - $this->userStoreManager->addUser($userName, $password, $fullName); + $this->userStoreManager->addUser($userName, $password); } catch (Exception $ex) { throw new Exception("Unable to add new user", 0, $ex); } } + + /** + * Function to create a new user account. This user account is not active unless activates by the user via + * his/her email + * + * @param $userName + * @param $password + * @param $email + * @param $firstName + * @param $lastName + * @param $tenantDomain + * @throws Exception + */ + public function registerAccount($userName, $password, $email, $firstName, $lastName, $tenantDomain){ + try { + $this->userInfoRecoveryManager->registerAccount($userName, $password, $email, $firstName, $lastName, $tenantDomain); + } catch (Exception $ex) { + throw new Exception("Unable to create a new user account", 0, $ex); + } + } + /** * Function to delete existing user * @@ -397,6 +418,33 @@ class Wsis { $this->userProfileManager->updateUserProfile($username, $email, $firstName, $lastName); } + + /** + * + * Function to create a user account. This user account has to be activated by the user via his + * email account + * @param $username + * @param $password + * @param $email + * @param $firstName + * @param $lastName + * @param $tenantDomain + */ + public function registerUserAccount($username, $password, $email, $firstName, $lastName, $tenantDomain) + { + $this->userInfoRecoveryManager->registerAccount($username, $password, $email, $firstName, + $lastName, $tenantDomain); + } + + /** + * Function to confirm user registration + * @param $userName + * @param $tenantDomain + */ + public function confirmUserRegistration($userName, $code, $tenantDomain){ + return $this->userInfoRecoveryManager->confirmUserRegistration($userName, $code, $tenantDomain); + } + /** * Function to get the user profile of a user * @param $username http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/42e8876b/app/routes.php ---------------------------------------------------------------------- diff --git a/app/routes.php b/app/routes.php index 7e1a83c..0aaef26 100755 --- a/app/routes.php +++ b/app/routes.php @@ -42,6 +42,8 @@ Route::post("reset-password", "AccountController@resetPasswordSubmit"); Route::post("forgot-password", "AccountController@forgotPasswordSubmit"); +Route::get("confirm-user-registration", "AccountController@confirmAccountCreation"); + Route::get("setUserTimezone", function () { Session::set("user_timezone", Input::get("timezone")); }); http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/42e8876b/app/views/account/create.blade.php ---------------------------------------------------------------------- diff --git a/app/views/account/create.blade.php b/app/views/account/create.blade.php index e7b3a32..ee4ca2b 100755 --- a/app/views/account/create.blade.php +++ b/app/views/account/create.blade.php @@ -40,6 +40,8 @@ <div><input class="form-control" id="password" minlength="6" name="password" placeholder="Password" required="required" title="" type="password"/></div> + <div><small>(Password should contain a digit[0-9], a lower case letter[a-z], an upper case letter[A-Z], + one of !@#$%&* characters)</small></div> </div> <div class="form-group required"><label class="control-label">Password (again)</label>
