diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 810d3e11..575dc81b 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -35,6 +35,7 @@ use OAuth2\Services\ISecurityContextService; use OAuth2\Services\ITokenService; use OpenId\Services\IMementoOpenIdSerializerService; use OpenId\Services\ITrustedSitesService; +use Services\Exceptions\ValidationException; use Services\IUserActionService; use Strategies\DefaultLoginStrategy; use Strategies\IConsentStrategy; @@ -434,6 +435,7 @@ final class UserController extends OpenIdController "openid_url" => $this->server_configuration_service->getUserIdentityEndpointURL($user->getIdentifier()), "identifier " => $user->getIdentifier(), "sites" => $sites, + 'identifier' => $user->getIdentifier(), "show_pic" => $user->getShowProfilePic(), "show_full_name" => $user->getShowProfileFullName(), "show_email" => $user->getShowProfileEmail(), @@ -443,14 +445,28 @@ final class UserController extends OpenIdController public function postUserProfileOptions() { + $values = Input::all(); $show_full_name = intval(Input::get("show_full_name", 0)); $show_email = intval(Input::get("show_email", 0)); $show_pic = intval(Input::get("show_pic", 0)); + $identifier = Input::get("identifier", null); - $user = $this->auth_service->getCurrentUser(); - $this->user_service->saveProfileInfo($user->getId(), $show_pic, $show_full_name, $show_email); + $validator = Validator::make($values, ['identifier' => 'required|openid.identifier']); - return Redirect::action("UserController@getProfile"); + if ($validator->fails()) { + return Redirect::back()->withErrors($validator); + } + + try { + $user = $this->auth_service->getCurrentUser(); + $this->user_service->saveProfileInfo($user->getId(), $show_pic, $show_full_name, $show_email, $identifier); + + return Redirect::action("UserController@getProfile"); + } + catch(ValidationException $ex1){ + $validator->errors()->add('identifier', $ex1->getMessage()); + return Redirect::back()->withErrors($validator); + } } public function deleteTrustedSite($id) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index dc234d4a..61d1e318 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -56,6 +56,15 @@ class AppServiceProvider extends ServiceProvider { return new CustomValidator($translator, $data, $rules, $messages); }); + + Validator::extend('openid.identifier', function($attribute, $value, $parameters, $validator) + { + $validator->addReplacer('openid.identifier', function($message, $attribute, $rule, $parameters) use ($validator) { + return sprintf("%s should be a valid openid identifier", $attribute); + }); + + return preg_match('/^(\w|\.)+$/', $value); + }); } /** diff --git a/app/Services/OpenId/UserService.php b/app/Services/OpenId/UserService.php index 592fbf3f..969e2222 100644 --- a/app/Services/OpenId/UserService.php +++ b/app/Services/OpenId/UserService.php @@ -11,20 +11,18 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ - use Auth\IUserNameGeneratorService; use Auth\Repositories\IUserRepository; use Auth\User; use Models\Member; use OpenId\Models\IOpenIdUser; use OpenId\Services\IUserService; -use Services\Exceptions\ValidationException; use Utils\Db\ITransactionService; use Utils\Exceptions\EntityNotFoundException; use Utils\Services\ILogService; use Illuminate\Support\Facades\Mail; use Utils\Services\IServerConfigurationService; - +use Services\Exceptions\ValidationException; /** * Class UserService * @package Services\OpenId @@ -189,20 +187,28 @@ final class UserService implements IUserService * @param bool $show_pic * @param bool $show_full_name * @param bool $show_email + * @param string $identifier * @return bool * @throws EntityNotFoundException + * @throws ValidationException */ - public function saveProfileInfo($user_id, $show_pic, $show_full_name, $show_email) + public function saveProfileInfo($user_id, $show_pic, $show_full_name, $show_email, $identifier) { - return $this->tx_service->transaction(function() use($user_id, $show_pic, $show_full_name, $show_email){ + return $this->tx_service->transaction(function() use($user_id, $show_pic, $show_full_name, $show_email, $identifier){ $user = $this->repository->get($user_id); if(is_null($user)) throw new EntityNotFoundException(); + $former_user = $this->repository->getByIdentifier($identifier); + + if(!is_null($former_user) && $former_user->id != $user_id){ + throw new ValidationException("there is already another user with that openid identifier"); + } + $user->public_profile_show_photo = $show_pic; $user->public_profile_show_fullname = $show_full_name; $user->public_profile_show_email = $show_email; - + $user->identifier = $identifier; $this->repository->update($user); return true; }); diff --git a/app/libs/OpenId/Services/IUserService.php b/app/libs/OpenId/Services/IUserService.php index 21fe1ffb..1106fa7d 100644 --- a/app/libs/OpenId/Services/IUserService.php +++ b/app/libs/OpenId/Services/IUserService.php @@ -14,7 +14,7 @@ use OpenId\Models\IOpenIdUser; use Models\Member; use Utils\Exceptions\EntityNotFoundException; - +use Services\Exceptions\ValidationException; /** * Interface IUserService * @package OpenId\Services @@ -75,9 +75,11 @@ interface IUserService * @param bool $show_pic * @param bool $show_full_name * @param bool $show_email + * @param string $identifier * @return bool * @throws EntityNotFoundException + * @throws ValidationException */ - public function saveProfileInfo($user_id, $show_pic, $show_full_name, $show_email); + public function saveProfileInfo($user_id, $show_pic, $show_full_name, $show_email, $identifier); } \ No newline at end of file diff --git a/public/assets/css/main.css b/public/assets/css/main.css index 81453eb3..6315acae 100644 --- a/public/assets/css/main.css +++ b/public/assets/css/main.css @@ -207,4 +207,8 @@ textarea { .privacy-policy{ padding-top: 5px; +} + +.alert{ + margin-top: 5px; } \ No newline at end of file diff --git a/resources/views/profile.blade.php b/resources/views/profile.blade.php index 2fc7756f..6c322cf0 100644 --- a/resources/views/profile.blade.php +++ b/resources/views/profile.blade.php @@ -22,23 +22,34 @@ {!! Form::open(array('url' => URL::action('UserController@postUserProfileOptions'), 'method' => 'post')) !!}  OpenStack ID Account Settings:
- -
+ + {!! Form::label('identifier', 'OpenId Identifier') !!} + {!! Form::text('identifier', $identifier) !!} + @if ($errors->has('identifier')) + + @endif +
-
+
-
-
- {!! Form::submit('Save',array('id'=>'save','class'=>'btn btn-default btn-md active')) !!} -
+ +
+ +
+
+ {!! Form::submit('Save',array('id'=>'save','class'=>'btn btn-default btn-md active')) !!} +
{!! Form::close() !!}