Updated user profile UI

allow users to change their automatically assigned
openid identifier

Change-Id: Ia6d03967fe3174a73e4a7b3cffae5f19c3ab1399
This commit is contained in:
Sebastian Marcet 2018-09-20 14:38:36 -03:00
parent 865aefeaf1
commit 51702c2d7b
6 changed files with 70 additions and 22 deletions

View File

@ -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)

View File

@ -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);
});
}
/**

View File

@ -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;
});

View File

@ -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);
}

View File

@ -207,4 +207,8 @@ textarea {
.privacy-policy{
padding-top: 5px;
}
.alert{
margin-top: 5px;
}

View File

@ -22,23 +22,34 @@
{!! Form::open(array('url' => URL::action('UserController@postUserProfileOptions'), 'method' => 'post')) !!}
<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>
<div class="checkbox">
<label class="checkbox">
{!! Form::checkbox('show_full_name', '1', $show_full_name) !!}Show Full Name
</label>
</div>
<span class="glyphicon glyphicon-info-sign pointable" aria-hidden="true" title="this is your openid identifier"></span>
{!! Form::label('identifier', 'OpenId Identifier') !!}
{!! Form::text('identifier', $identifier) !!}
@if ($errors->has('identifier'))
<div class="alert alert-warning alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<strong>Warning!</strong> {{ $errors->first('identifier') }}
</div>
@endif
</div>
<div class="checkbox">
<label class="checkbox">
{!! Form::checkbox('show_email', '1', $show_email) !!}Show Email
{!! Form::checkbox('show_full_name', '1', $show_full_name) !!}Show Full Name
</label>
</div>
</div>
<div class="checkbox">
<label class="checkbox">
{!! Form::checkbox('show_pic', '1', $show_pic) !!}Show Photo
{!! Form::checkbox('show_email', '1', $show_email) !!}Show Email
</label>
</div>
<div class="pull-right">
{!! Form::submit('Save',array('id'=>'save','class'=>'btn btn-default btn-md active')) !!}
</div>
</div>
<div class="checkbox">
<label class="checkbox">
{!! Form::checkbox('show_pic', '1', $show_pic) !!}Show Photo
</label>
</div>
<div class="pull-right">
{!! Form::submit('Save',array('id'=>'save','class'=>'btn btn-default btn-md active')) !!}
</div>
{!! Form::close() !!}
</div>