From a9dc8cf544b831f48513073a9e7fa70ebe0ec4af Mon Sep 17 00:00:00 2001 From: "smarcet@gmail.com" Date: Mon, 20 Sep 2021 14:08:13 -0300 Subject: [PATCH] Updated user Profile Added public_profile_allow_chat_with_me Updated token introspection response Signed-off-by: smarcet@gmail.com Change-Id: Ib22b674605e469f52d582b5e6e62a0b42c00c6ae --- .../Factories/UserValidationRulesFactory.php | 2 + app/libs/Auth/Factories/UserFactory.php | 3 ++ app/libs/Auth/Models/User.php | 23 +++++++++ .../OAuth2AccessTokenValidationResponse.php | 47 ++++++++++-------- database/migrations/Version20210916210607.php | 49 +++++++++++++++++++ resources/views/profile.blade.php | 9 ++++ 6 files changed, 112 insertions(+), 21 deletions(-) create mode 100644 database/migrations/Version20210916210607.php diff --git a/app/Http/Controllers/Factories/UserValidationRulesFactory.php b/app/Http/Controllers/Factories/UserValidationRulesFactory.php index 36bb6de9..8a51e5ea 100644 --- a/app/Http/Controllers/Factories/UserValidationRulesFactory.php +++ b/app/Http/Controllers/Factories/UserValidationRulesFactory.php @@ -65,6 +65,7 @@ public static function build(array $data, $update = false, ?User $currentUser = 'public_profile_show_photo' => 'sometimes|boolean', 'public_profile_show_fullname' => 'sometimes|boolean', 'public_profile_show_email' => 'sometimes|boolean', + 'public_profile_allow_chat_with_me' => 'sometimes|boolean', ]; if(!is_null($currentUser) && !$currentUser->isAdmin() && $currentUser->hasPasswordSet()){ @@ -108,6 +109,7 @@ public static function build(array $data, $update = false, ?User $currentUser = 'public_profile_show_photo' => 'sometimes|boolean', 'public_profile_show_fullname' => 'sometimes|boolean', 'public_profile_show_email' => 'sometimes|boolean', + 'public_profile_allow_chat_with_me' => 'sometimes|boolean', ]; } } \ No newline at end of file diff --git a/app/libs/Auth/Factories/UserFactory.php b/app/libs/Auth/Factories/UserFactory.php index fd19d968..d8e14d5b 100644 --- a/app/libs/Auth/Factories/UserFactory.php +++ b/app/libs/Auth/Factories/UserFactory.php @@ -163,6 +163,9 @@ public static function populate(User $user, array $payload):User{ if(isset($payload['public_profile_show_email'])) $user->setPublicProfileShowEmail(boolval($payload['public_profile_show_email'])); + if(isset($payload['public_profile_allow_chat_with_me'])) + $user->setPublicProfileAllowChatWithMe(boolval($payload['public_profile_allow_chat_with_me'])); + if(isset($payload['email_verified']) && boolval($payload['email_verified']) === true && !$user->isEmailVerified()) { // we have this variable to bypass email UserEmailVerified $send_email_verified_notice = isset($payload['send_email_verified_notice']) ? boolval($payload['send_email_verified_notice']):true; diff --git a/app/libs/Auth/Models/User.php b/app/libs/Auth/Models/User.php index 227aa769..8e1c0837 100644 --- a/app/libs/Auth/Models/User.php +++ b/app/libs/Auth/Models/User.php @@ -92,6 +92,12 @@ class User extends BaseEntity */ private $public_profile_show_email; + /** + * @ORM\Column(name="public_profile_allow_chat_with_me", options={"default":0}, type="boolean") + * @var bool + */ + private $public_profile_allow_chat_with_me; + /** * @ORM\Column(name="last_login_date", type="datetime") * @var \DateTime @@ -417,6 +423,7 @@ public function __construct() $this->public_profile_show_photo = false; $this->public_profile_show_email = false; $this->public_profile_show_fullname = false; + $this->public_profile_allow_chat_with_me = false; $this->password = ""; $this->identifier = null; $this->gender_specify = ""; @@ -984,6 +991,22 @@ public function setPublicProfileShowEmail(bool $public_profile_show_email): void $this->public_profile_show_email = $public_profile_show_email; } + /** + * @return bool + */ + public function isPublicProfileAllowChatWithMe(): bool + { + return $this->public_profile_allow_chat_with_me; + } + + /** + * @param bool $public_profile_allow_chat_with_me + */ + public function setPublicProfileAllowChatWithMe(bool $public_profile_allow_chat_with_me): void + { + $this->public_profile_allow_chat_with_me = $public_profile_allow_chat_with_me; + } + /** * @return \DateTime|null */ diff --git a/app/libs/OAuth2/Responses/OAuth2AccessTokenValidationResponse.php b/app/libs/OAuth2/Responses/OAuth2AccessTokenValidationResponse.php index 7f5a00f6..ef070c89 100644 --- a/app/libs/OAuth2/Responses/OAuth2AccessTokenValidationResponse.php +++ b/app/libs/OAuth2/Responses/OAuth2AccessTokenValidationResponse.php @@ -17,11 +17,13 @@ use OAuth2\Models\IClient; use OAuth2\OAuth2Protocol; use Utils\Http\HttpContentType; + /** * Class OAuth2AccessTokenValidationResponse * @package OAuth2\Responses */ -class OAuth2AccessTokenValidationResponse extends OAuth2DirectResponse { +class OAuth2AccessTokenValidationResponse extends OAuth2DirectResponse +{ /** * @param array|int $access_token @@ -48,40 +50,43 @@ public function __construct // Successful Responses: A server receiving a valid request MUST send a // response with an HTTP status code of 200. parent::__construct(self::HttpOkResponse, HttpContentType::Json); - $this[OAuth2Protocol::OAuth2Protocol_AccessToken] = $access_token; - $this[OAuth2Protocol::OAuth2Protocol_ClientId] = $client->getClientId(); - $this['application_type'] = $client->getApplicationType(); - $this[OAuth2Protocol::OAuth2Protocol_TokenType] = 'Bearer'; - $this[OAuth2Protocol::OAuth2Protocol_Scope] = $scope; - $this[OAuth2Protocol::OAuth2Protocol_Audience] = $audience; + $this[OAuth2Protocol::OAuth2Protocol_AccessToken] = $access_token; + $this[OAuth2Protocol::OAuth2Protocol_ClientId] = $client->getClientId(); + $this['application_type'] = $client->getApplicationType(); + $this[OAuth2Protocol::OAuth2Protocol_TokenType] = 'Bearer'; + $this[OAuth2Protocol::OAuth2Protocol_Scope] = $scope; + $this[OAuth2Protocol::OAuth2Protocol_Audience] = $audience; $this[OAuth2Protocol::OAuth2Protocol_AccessToken_ExpiresIn] = $expires_in; - if(!is_null($user)) - { + if (!is_null($user)) { // user info if present $this[OAuth2Protocol::OAuth2Protocol_UserId] = $user->getId(); - $this['user_identifier'] = $user->getIdentifier(); - $this['user_email'] = $user->getEmail(); - $this['user_first_name'] = $user->getFirstName(); - $this['user_last_name'] = $user->getLastName(); - $this['user_language'] = $user->getLanguage(); - $this['user_country'] = $user->getCountry(); - $this['user_email_verified'] = $user->isEmailVerified(); - $this['user_pic'] = $user->getPic(); + $this['user_identifier'] = $user->getIdentifier(); + $this['user_email'] = $user->getEmail(); + $this['user_first_name'] = $user->getFirstName(); + $this['user_last_name'] = $user->getLastName(); + $this['user_language'] = $user->getLanguage(); + $this['user_country'] = $user->getCountry(); + $this['user_email_verified'] = $user->isEmailVerified(); + $this['user_pic'] = $user->getPic(); + $this["user_public_profile_show_fullname"] = $user->isPublicProfileShowFullname(); + $this['user_public_profile_show_email'] = $user->isPublicProfileShowEmail(); + $this['user_public_profile_show_photo'] = $user->isPublicProfileShowPhoto(); + $this['user_public_profile_allow_chat_with_me'] = $user->isPublicProfileAllowChatWithMe(); // default empty value - $user_groups = []; - foreach ($user->getGroups() as $group){ + $user_groups = []; + foreach ($user->getGroups() as $group) { $user_groups[] = SerializerRegistry::getInstance()->getSerializer($group)->serialize(); } $this['user_groups'] = $user_groups; } - if(count($allowed_urls)){ + if (count($allowed_urls)) { $this['allowed_return_uris'] = implode(' ', $allowed_urls); } - if(count($allowed_origins)){ + if (count($allowed_origins)) { $this['allowed_origins'] = implode(' ', $allowed_origins); } } diff --git a/database/migrations/Version20210916210607.php b/database/migrations/Version20210916210607.php new file mode 100644 index 00000000..e8ecb6ce --- /dev/null +++ b/database/migrations/Version20210916210607.php @@ -0,0 +1,49 @@ +hasTable("users") && !$builder->hasColumn("users","public_profile_allow_chat_with_me") ) { + $builder->table('users', function (Table $table) { + $table->boolean('public_profile_allow_chat_with_me')->setNotnull(false)->setDefault(false); + }); + } + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema): void + { + $builder = new Builder($schema); + if($schema->hasTable("users") && $builder->hasColumn("users","public_profile_allow_chat_with_me") ) { + $builder->table('users', function (Table $table) { + $table->dropColumn('public_profile_allow_chat_with_me'); + }); + } + } +} diff --git a/resources/views/profile.blade.php b/resources/views/profile.blade.php index 708e0a7b..9628d855 100644 --- a/resources/views/profile.blade.php +++ b/resources/views/profile.blade.php @@ -269,6 +269,15 @@ /> Show Email on Public Profile? +
+ +