Browse Source

Updated user profile UI

allow users to change their automatically assigned
openid identifier

Change-Id: Ia6d03967fe3174a73e4a7b3cffae5f19c3ab1399
Sebastian Marcet 8 months ago
parent
commit
51702c2d7b

+ 19
- 3
app/Http/Controllers/UserController.php View File

@@ -35,6 +35,7 @@ use OAuth2\Services\ISecurityContextService;
35 35
 use OAuth2\Services\ITokenService;
36 36
 use OpenId\Services\IMementoOpenIdSerializerService;
37 37
 use OpenId\Services\ITrustedSitesService;
38
+use Services\Exceptions\ValidationException;
38 39
 use Services\IUserActionService;
39 40
 use Strategies\DefaultLoginStrategy;
40 41
 use Strategies\IConsentStrategy;
@@ -434,6 +435,7 @@ final class UserController extends OpenIdController
434 435
             "openid_url"           => $this->server_configuration_service->getUserIdentityEndpointURL($user->getIdentifier()),
435 436
             "identifier "          => $user->getIdentifier(),
436 437
             "sites"                => $sites,
438
+            'identifier'           => $user->getIdentifier(),
437 439
             "show_pic"             => $user->getShowProfilePic(),
438 440
             "show_full_name"       => $user->getShowProfileFullName(),
439 441
             "show_email"           => $user->getShowProfileEmail(),
@@ -443,14 +445,28 @@ final class UserController extends OpenIdController
443 445
 
444 446
     public function postUserProfileOptions()
445 447
     {
448
+        $values = Input::all();
446 449
         $show_full_name = intval(Input::get("show_full_name", 0));
447 450
         $show_email     = intval(Input::get("show_email", 0));
448 451
         $show_pic       = intval(Input::get("show_pic", 0));
452
+        $identifier     = Input::get("identifier", null);
449 453
 
450
-        $user = $this->auth_service->getCurrentUser();
451
-        $this->user_service->saveProfileInfo($user->getId(), $show_pic, $show_full_name, $show_email);
454
+        $validator = Validator::make($values, ['identifier' => 'required|openid.identifier']);
452 455
 
453
-        return Redirect::action("UserController@getProfile");
456
+        if ($validator->fails()) {
457
+            return Redirect::back()->withErrors($validator);
458
+        }
459
+
460
+        try {
461
+            $user = $this->auth_service->getCurrentUser();
462
+            $this->user_service->saveProfileInfo($user->getId(), $show_pic, $show_full_name, $show_email, $identifier);
463
+
464
+            return Redirect::action("UserController@getProfile");
465
+        }
466
+        catch(ValidationException $ex1){
467
+            $validator->errors()->add('identifier', $ex1->getMessage());
468
+            return Redirect::back()->withErrors($validator);
469
+        }
454 470
     }
455 471
 
456 472
     public function deleteTrustedSite($id)

+ 9
- 0
app/Providers/AppServiceProvider.php View File

@@ -56,6 +56,15 @@ class AppServiceProvider extends ServiceProvider
56 56
         {
57 57
             return new CustomValidator($translator, $data, $rules, $messages);
58 58
         });
59
+
60
+        Validator::extend('openid.identifier', function($attribute, $value, $parameters, $validator)
61
+        {
62
+            $validator->addReplacer('openid.identifier', function($message, $attribute, $rule, $parameters) use ($validator) {
63
+                return sprintf("%s should be a valid openid identifier", $attribute);
64
+            });
65
+
66
+            return preg_match('/^(\w|\.)+$/', $value);
67
+        });
59 68
     }
60 69
 
61 70
     /**

+ 12
- 6
app/Services/OpenId/UserService.php View File

@@ -11,20 +11,18 @@
11 11
  * See the License for the specific language governing permissions and
12 12
  * limitations under the License.
13 13
  **/
14
-
15 14
 use Auth\IUserNameGeneratorService;
16 15
 use Auth\Repositories\IUserRepository;
17 16
 use Auth\User;
18 17
 use Models\Member;
19 18
 use OpenId\Models\IOpenIdUser;
20 19
 use OpenId\Services\IUserService;
21
-use Services\Exceptions\ValidationException;
22 20
 use Utils\Db\ITransactionService;
23 21
 use Utils\Exceptions\EntityNotFoundException;
24 22
 use Utils\Services\ILogService;
25 23
 use Illuminate\Support\Facades\Mail;
26 24
 use Utils\Services\IServerConfigurationService;
27
-
25
+use Services\Exceptions\ValidationException;
28 26
 /**
29 27
  * Class UserService
30 28
  * @package Services\OpenId
@@ -189,20 +187,28 @@ final class UserService implements IUserService
189 187
      * @param bool $show_pic
190 188
      * @param bool $show_full_name
191 189
      * @param bool $show_email
190
+     * @param string $identifier
192 191
      * @return bool
193 192
      * @throws EntityNotFoundException
193
+     * @throws ValidationException
194 194
      */
195
-    public function saveProfileInfo($user_id, $show_pic, $show_full_name, $show_email)
195
+    public function saveProfileInfo($user_id, $show_pic, $show_full_name, $show_email, $identifier)
196 196
     {
197 197
 
198
-        return $this->tx_service->transaction(function() use($user_id, $show_pic, $show_full_name, $show_email){
198
+        return $this->tx_service->transaction(function() use($user_id, $show_pic, $show_full_name, $show_email, $identifier){
199 199
             $user = $this->repository->get($user_id);
200 200
             if(is_null($user)) throw new EntityNotFoundException();
201 201
 
202
+            $former_user = $this->repository->getByIdentifier($identifier);
203
+
204
+            if(!is_null($former_user) && $former_user->id != $user_id){
205
+                throw new ValidationException("there is already another user with that openid identifier");
206
+            }
207
+
202 208
             $user->public_profile_show_photo    = $show_pic;
203 209
             $user->public_profile_show_fullname = $show_full_name;
204 210
             $user->public_profile_show_email    = $show_email;
205
-
211
+            $user->identifier                   = $identifier;
206 212
             $this->repository->update($user);
207 213
             return true;
208 214
         });

+ 4
- 2
app/libs/OpenId/Services/IUserService.php View File

@@ -14,7 +14,7 @@
14 14
 use OpenId\Models\IOpenIdUser;
15 15
 use Models\Member;
16 16
 use Utils\Exceptions\EntityNotFoundException;
17
-
17
+use Services\Exceptions\ValidationException;
18 18
 /**
19 19
  * Interface IUserService
20 20
  * @package OpenId\Services
@@ -75,9 +75,11 @@ interface IUserService
75 75
      * @param bool $show_pic
76 76
      * @param bool $show_full_name
77 77
      * @param bool $show_email
78
+     * @param string $identifier
78 79
      * @return bool
79 80
      * @throws EntityNotFoundException
81
+     * @throws ValidationException
80 82
      */
81
-    public function saveProfileInfo($user_id, $show_pic, $show_full_name, $show_email);
83
+    public function saveProfileInfo($user_id, $show_pic, $show_full_name, $show_email, $identifier);
82 84
 
83 85
 }

+ 4
- 0
public/assets/css/main.css View File

@@ -207,4 +207,8 @@ textarea {
207 207
 
208 208
 .privacy-policy{
209 209
     padding-top: 5px;
210
+}
211
+
212
+.alert{
213
+    margin-top: 5px;
210 214
 }

+ 20
- 9
resources/views/profile.blade.php View File

@@ -21,24 +21,35 @@
21 21
                 <div class="col-md-12">
22 22
                     {!! Form::open(array('url' => URL::action('UserController@postUserProfileOptions'), 'method' => 'post')) !!}
23 23
                     <legend><span class="glyphicon glyphicon-info-sign pointable" aria-hidden="true" title="this information will be public on your profile page"></span>&nbsp;OpenStack ID Account Settings:</legend>
24
+                    <div class="checkbox">
25
+                        <span class="glyphicon glyphicon-info-sign pointable" aria-hidden="true" title="this is your openid identifier"></span>
26
+                        {!! Form::label('identifier', 'OpenId Identifier') !!}
27
+                        {!! Form::text('identifier', $identifier) !!}
28
+                        @if ($errors->has('identifier'))
29
+                            <div class="alert alert-warning alert-dismissible" role="alert">
30
+                                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
31
+                                <strong>Warning!</strong> {{ $errors->first('identifier') }}
32
+                            </div>
33
+                        @endif
34
+                    </div>
24 35
                     <div class="checkbox">
25 36
                         <label class="checkbox">
26
-                            {!! Form::checkbox('show_full_name', '1', $show_full_name) !!}Show Full Name
37
+                        {!! Form::checkbox('show_full_name', '1', $show_full_name) !!}Show Full Name
27 38
                         </label>
28
-                        </div>
39
+                    </div>
29 40
                     <div class="checkbox">
30 41
                         <label class="checkbox">
31
-                            {!! Form::checkbox('show_email', '1', $show_email) !!}Show Email
42
+                        {!! Form::checkbox('show_email', '1', $show_email) !!}Show Email
32 43
                         </label>
33
-                        </div>
44
+                    </div>
34 45
                     <div class="checkbox">
35 46
                         <label class="checkbox">
36
-                            {!! Form::checkbox('show_pic', '1', $show_pic) !!}Show Photo
47
+                        {!! Form::checkbox('show_pic', '1', $show_pic) !!}Show Photo
37 48
                         </label>
38
-                        </div>
39
-                        <div class="pull-right">
40
-                            {!! Form::submit('Save',array('id'=>'save','class'=>'btn btn-default btn-md active')) !!}
41
-                        </div>
49
+                    </div>
50
+                    <div class="pull-right">
51
+                        {!! Form::submit('Save',array('id'=>'save','class'=>'btn btn-default btn-md active')) !!}
52
+                    </div>
42 53
 
43 54
                     {!! Form::close() !!}
44 55
                 </div>

Loading…
Cancel
Save