Skip to content

Commit 8a3e97c

Browse files
committed
Updated user Profile (#2)
Added public_profile_allow_chat_with_me Updated token introspection response Signed-off-by: [email protected] <[email protected]> Change-Id: Ib22b674605e469f52d582b5e6e62a0b42c00c6ae
1 parent 9dc5085 commit 8a3e97c

File tree

6 files changed

+112
-21
lines changed

6 files changed

+112
-21
lines changed

app/Http/Controllers/Factories/UserValidationRulesFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public static function build(array $data, $update = false, ?User $currentUser =
6565
'public_profile_show_photo' => 'sometimes|boolean',
6666
'public_profile_show_fullname' => 'sometimes|boolean',
6767
'public_profile_show_email' => 'sometimes|boolean',
68+
'public_profile_allow_chat_with_me' => 'sometimes|boolean',
6869
];
6970

7071
if(!is_null($currentUser) && !$currentUser->isAdmin() && $currentUser->hasPasswordSet()){
@@ -108,6 +109,7 @@ public static function build(array $data, $update = false, ?User $currentUser =
108109
'public_profile_show_photo' => 'sometimes|boolean',
109110
'public_profile_show_fullname' => 'sometimes|boolean',
110111
'public_profile_show_email' => 'sometimes|boolean',
112+
'public_profile_allow_chat_with_me' => 'sometimes|boolean',
111113
];
112114
}
113115
}

app/libs/Auth/Factories/UserFactory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ public static function populate(User $user, array $payload):User{
163163
if(isset($payload['public_profile_show_email']))
164164
$user->setPublicProfileShowEmail(boolval($payload['public_profile_show_email']));
165165

166+
if(isset($payload['public_profile_allow_chat_with_me']))
167+
$user->setPublicProfileAllowChatWithMe(boolval($payload['public_profile_allow_chat_with_me']));
168+
166169
if(isset($payload['email_verified']) && boolval($payload['email_verified']) === true && !$user->isEmailVerified()) {
167170
// we have this variable to bypass email UserEmailVerified
168171
$send_email_verified_notice = isset($payload['send_email_verified_notice']) ? boolval($payload['send_email_verified_notice']):true;

app/libs/Auth/Models/User.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ class User extends BaseEntity
9292
*/
9393
private $public_profile_show_email;
9494

95+
/**
96+
* @ORM\Column(name="public_profile_allow_chat_with_me", options={"default":0}, type="boolean")
97+
* @var bool
98+
*/
99+
private $public_profile_allow_chat_with_me;
100+
95101
/**
96102
* @ORM\Column(name="last_login_date", type="datetime")
97103
* @var \DateTime
@@ -417,6 +423,7 @@ public function __construct()
417423
$this->public_profile_show_photo = false;
418424
$this->public_profile_show_email = false;
419425
$this->public_profile_show_fullname = false;
426+
$this->public_profile_allow_chat_with_me = false;
420427
$this->password = "";
421428
$this->identifier = null;
422429
$this->gender_specify = "";
@@ -984,6 +991,22 @@ public function setPublicProfileShowEmail(bool $public_profile_show_email): void
984991
$this->public_profile_show_email = $public_profile_show_email;
985992
}
986993

994+
/**
995+
* @return bool
996+
*/
997+
public function isPublicProfileAllowChatWithMe(): bool
998+
{
999+
return $this->public_profile_allow_chat_with_me;
1000+
}
1001+
1002+
/**
1003+
* @param bool $public_profile_allow_chat_with_me
1004+
*/
1005+
public function setPublicProfileAllowChatWithMe(bool $public_profile_allow_chat_with_me): void
1006+
{
1007+
$this->public_profile_allow_chat_with_me = $public_profile_allow_chat_with_me;
1008+
}
1009+
9871010
/**
9881011
* @return \DateTime|null
9891012
*/

app/libs/OAuth2/Responses/OAuth2AccessTokenValidationResponse.php

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
use OAuth2\Models\IClient;
1818
use OAuth2\OAuth2Protocol;
1919
use Utils\Http\HttpContentType;
20+
2021
/**
2122
* Class OAuth2AccessTokenValidationResponse
2223
* @package OAuth2\Responses
2324
*/
24-
class OAuth2AccessTokenValidationResponse extends OAuth2DirectResponse {
25+
class OAuth2AccessTokenValidationResponse extends OAuth2DirectResponse
26+
{
2527

2628
/**
2729
* @param array|int $access_token
@@ -48,40 +50,43 @@ public function __construct
4850
// Successful Responses: A server receiving a valid request MUST send a
4951
// response with an HTTP status code of 200.
5052
parent::__construct(self::HttpOkResponse, HttpContentType::Json);
51-
$this[OAuth2Protocol::OAuth2Protocol_AccessToken] = $access_token;
52-
$this[OAuth2Protocol::OAuth2Protocol_ClientId] = $client->getClientId();
53-
$this['application_type'] = $client->getApplicationType();
54-
$this[OAuth2Protocol::OAuth2Protocol_TokenType] = 'Bearer';
55-
$this[OAuth2Protocol::OAuth2Protocol_Scope] = $scope;
56-
$this[OAuth2Protocol::OAuth2Protocol_Audience] = $audience;
53+
$this[OAuth2Protocol::OAuth2Protocol_AccessToken] = $access_token;
54+
$this[OAuth2Protocol::OAuth2Protocol_ClientId] = $client->getClientId();
55+
$this['application_type'] = $client->getApplicationType();
56+
$this[OAuth2Protocol::OAuth2Protocol_TokenType] = 'Bearer';
57+
$this[OAuth2Protocol::OAuth2Protocol_Scope] = $scope;
58+
$this[OAuth2Protocol::OAuth2Protocol_Audience] = $audience;
5759
$this[OAuth2Protocol::OAuth2Protocol_AccessToken_ExpiresIn] = $expires_in;
5860

59-
if(!is_null($user))
60-
{
61+
if (!is_null($user)) {
6162
// user info if present
6263
$this[OAuth2Protocol::OAuth2Protocol_UserId] = $user->getId();
63-
$this['user_identifier'] = $user->getIdentifier();
64-
$this['user_email'] = $user->getEmail();
65-
$this['user_first_name'] = $user->getFirstName();
66-
$this['user_last_name'] = $user->getLastName();
67-
$this['user_language'] = $user->getLanguage();
68-
$this['user_country'] = $user->getCountry();
69-
$this['user_email_verified'] = $user->isEmailVerified();
70-
$this['user_pic'] = $user->getPic();
64+
$this['user_identifier'] = $user->getIdentifier();
65+
$this['user_email'] = $user->getEmail();
66+
$this['user_first_name'] = $user->getFirstName();
67+
$this['user_last_name'] = $user->getLastName();
68+
$this['user_language'] = $user->getLanguage();
69+
$this['user_country'] = $user->getCountry();
70+
$this['user_email_verified'] = $user->isEmailVerified();
71+
$this['user_pic'] = $user->getPic();
72+
$this["user_public_profile_show_fullname"] = $user->isPublicProfileShowFullname();
73+
$this['user_public_profile_show_email'] = $user->isPublicProfileShowEmail();
74+
$this['user_public_profile_show_photo'] = $user->isPublicProfileShowPhoto();
75+
$this['user_public_profile_allow_chat_with_me'] = $user->isPublicProfileAllowChatWithMe();
7176
// default empty value
72-
$user_groups = [];
73-
foreach ($user->getGroups() as $group){
77+
$user_groups = [];
78+
foreach ($user->getGroups() as $group) {
7479
$user_groups[] = SerializerRegistry::getInstance()->getSerializer($group)->serialize();
7580
}
7681

7782
$this['user_groups'] = $user_groups;
7883
}
7984

80-
if(count($allowed_urls)){
85+
if (count($allowed_urls)) {
8186
$this['allowed_return_uris'] = implode(' ', $allowed_urls);
8287
}
8388

84-
if(count($allowed_origins)){
89+
if (count($allowed_origins)) {
8590
$this['allowed_origins'] = implode(' ', $allowed_origins);
8691
}
8792
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php namespace Database\Migrations;
2+
/**
3+
* Copyright 2021 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
use Doctrine\Migrations\AbstractMigration;
15+
use Doctrine\DBAL\Schema\Schema as Schema;
16+
use LaravelDoctrine\Migrations\Schema\Builder;
17+
use LaravelDoctrine\Migrations\Schema\Table;
18+
/**
19+
* Class Version20210916210607
20+
* @package Database\Migrations
21+
*/
22+
class Version20210916210607 extends AbstractMigration
23+
{
24+
/**
25+
* @param Schema $schema
26+
*/
27+
public function up(Schema $schema): void
28+
{
29+
$builder = new Builder($schema);
30+
if($schema->hasTable("users") && !$builder->hasColumn("users","public_profile_allow_chat_with_me") ) {
31+
$builder->table('users', function (Table $table) {
32+
$table->boolean('public_profile_allow_chat_with_me')->setNotnull(false)->setDefault(false);
33+
});
34+
}
35+
}
36+
37+
/**
38+
* @param Schema $schema
39+
*/
40+
public function down(Schema $schema): void
41+
{
42+
$builder = new Builder($schema);
43+
if($schema->hasTable("users") && $builder->hasColumn("users","public_profile_allow_chat_with_me") ) {
44+
$builder->table('users', function (Table $table) {
45+
$table->dropColumn('public_profile_allow_chat_with_me');
46+
});
47+
}
48+
}
49+
}

resources/views/profile.blade.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,15 @@
269269
/>&nbsp;Show Email on Public Profile?
270270
</label>
271271
</div>
272+
<div class="checkbox col-xs-10 col-sm-4 col-md-12 col-lg-12">
273+
<label>
274+
<input type="checkbox" id="public_profile_allow_chat_with_me" name="public_profile_allow_chat_with_me"
275+
@if($user->public_profile_allow_chat_with_me)
276+
checked
277+
@endif
278+
/>&nbsp;Allow people to chat with me?
279+
</label>
280+
</div>
272281
<button type="submit" class="btn btn-default btn-lg btn-primary">Save</button>
273282
<input type="hidden" name="id" id="id" value="{!! $user->id !!}"/>
274283
</form>

0 commit comments

Comments
 (0)