Commit 8954440c authored by Ben Hayward's avatar Ben Hayward

Surge token deletion on logout. #1270

1 merge request!436Surge token deletion on logout #1270
Pipeline #107889461 passed with stages
in 7 minutes and 56 seconds
......@@ -146,10 +146,12 @@ class notifications implements Interfaces\Api
'service' => $service,
'token' => $passed_token
]);
Core\Session::getLoggedInUser()
->setSurgeToken($token)
->save();
(new Core\Data\Call('entities'))
->insert(static::getCurrentUserGuid(), [ 'surge_token' => $token ]);
break;
break;
}
return Factory::response([]);
......
......@@ -8,6 +8,7 @@ namespace Minds\Core\Sessions;
use Minds\Common\Cookie;
use Minds\Core;
use Minds\Core\Di\Di;
use Minds\Entities\User;
use Lcobucci\JWT;
use Lcobucci\JWT\Signer\Key;
use Lcobucci\JWT\Signer\Rsa\Sha512;
......@@ -246,7 +247,15 @@ class Manager
public function destroy($all = false)
{
if ($this->session) {
$this->repository->delete($this->session, $all);
if (!$this->user) {
// If no user set grab from session.
$this->user = new User($this->session->getLoggedInUser());
}
$this->user->setSurgeToken('') // Delete push notification token.
->save();
$this->repository->delete($this->session, $all); // Delete from repository.
}
$this->cookie
......
......@@ -62,6 +62,7 @@ class User extends \ElggUser
$this->attributes['mode'] = ChannelMode::OPEN;
$this->attributes['email_confirmation_token'] = null;
$this->attributes['email_confirmed_at'] = null;
$this->attributes['surge_token'] = '';
parent::initializeAttributes();
}
......@@ -1227,6 +1228,7 @@ class User extends \ElggUser
'toaster_notifications',
'mode',
'btc_address',
'surge_token',
]);
}
......@@ -1394,4 +1396,26 @@ class User extends \ElggUser
return $this;
}
/**
* Gets the Surge Token of the user for push notifications.
*
* @return string Token.
*/
public function getSurgeToken(): string
{
return (string) $this->surge_token ?? '';
}
/**
* Sets the Surge Token of the user for push notifications.
*
* @param string $token - the token string.
* @return User instance of $this for chaining.
*/
public function setSurgeToken(string $token = ''): User
{
$this->surge_token = $token;
return $this;
}
}
......@@ -324,7 +324,8 @@ YSoKTsWFlvr9YG4o6R2ktgzKJ5ofiGTz5e2wLzP3a0ma8vGNke4Q
public function it_should_destroy_session_on_client_and_server(
Repository $repository,
Cookie $cookie
Cookie $cookie,
\Minds\Entities\User $user
) {
$this->beConstructedWith(
$repository,
......@@ -343,6 +344,19 @@ YSoKTsWFlvr9YG4o6R2ktgzKJ5ofiGTz5e2wLzP3a0ma8vGNke4Q
$repository->delete('mock_session_id');
$user->guid = 123;
$this->setUser($user);
$user->setSurgeToken('')
->shouldBeCalled()
->willReturn($user);
$user->save()
->shouldBeCalled()
->willReturn(null);
$cookie->setName('minds_sess')
->shouldBeCalled()
->willReturn($cookie);
......
......@@ -71,4 +71,18 @@ class UserSpec extends ObjectBehavior
$export = $this->export()->getWrappedObject();
expect($export['mode'])->shouldEqual(ChannelMode::OPEN);
}
public function it_should_get_surge_token()
{
$token = '11111';
$this->surge_token = $token;
$this->getSurgeToken()->shouldReturn($token);
}
public function it_should_set_surge_token()
{
$token = '11111';
$this->setSurgeToken($token)->shouldReturnAnInstanceOf('Minds\Entities\User');
$this->getSurgeToken()->shouldReturn($token);
}
}
Please register or to comment