Merge pull request #3148 from appwrite/fix-account-bugs
fix(account): magic url and sessions locale
This commit is contained in:
commit
68cb0dc281
|
@ -838,6 +838,7 @@ App::put('/v1/account/sessions/magic-url')
|
||||||
}
|
}
|
||||||
|
|
||||||
$user
|
$user
|
||||||
|
->setAttribute('emailVerification', true)
|
||||||
->setAttribute('sessions', $session, Document::SET_TYPE_APPEND)
|
->setAttribute('sessions', $session, Document::SET_TYPE_APPEND)
|
||||||
->setAttribute('tokens', $tokens);
|
->setAttribute('tokens', $tokens);
|
||||||
|
|
||||||
|
@ -868,9 +869,7 @@ App::put('/v1/account/sessions/magic-url')
|
||||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||||
;
|
;
|
||||||
|
|
||||||
$countryName = (isset($countries[strtoupper($session->getAttribute('countryCode'))]))
|
$countryName = $locale->getText('countries.'.strtolower($session->getAttribute('countryCode')), $locale->getText('locale.country.unknown'));
|
||||||
? $countries[strtoupper($session->getAttribute('countryCode'))]
|
|
||||||
: $locale->getText('locale.country.unknown');
|
|
||||||
|
|
||||||
$session
|
$session
|
||||||
->setAttribute('current', true)
|
->setAttribute('current', true)
|
||||||
|
@ -1013,9 +1012,7 @@ App::post('/v1/account/sessions/anonymous')
|
||||||
->setStatusCode(Response::STATUS_CODE_CREATED)
|
->setStatusCode(Response::STATUS_CODE_CREATED)
|
||||||
;
|
;
|
||||||
|
|
||||||
$countryName = (isset($countries[strtoupper($session->getAttribute('countryCode'))]))
|
$countryName = $locale->getText('countries.'.strtolower($session->getAttribute('countryCode')), $locale->getText('locale.country.unknown'));
|
||||||
? $countries[strtoupper($session->getAttribute('countryCode'))]
|
|
||||||
: $locale->getText('locale.country.unknown');
|
|
||||||
|
|
||||||
$session
|
$session
|
||||||
->setAttribute('current', true)
|
->setAttribute('current', true)
|
||||||
|
@ -1280,15 +1277,13 @@ App::get('/v1/account/sessions/:sessionId')
|
||||||
|
|
||||||
$sessions = $user->getAttribute('sessions', []);
|
$sessions = $user->getAttribute('sessions', []);
|
||||||
$sessionId = ($sessionId === 'current')
|
$sessionId = ($sessionId === 'current')
|
||||||
? Auth::sessionVerify($user->getAttribute('sessions'), Auth::$secret)
|
? Auth::sessionVerify($user->getAttribute('sessions'), Auth::$secret)
|
||||||
: $sessionId;
|
: $sessionId;
|
||||||
|
|
||||||
foreach ($sessions as $session) {/** @var Document $session */
|
foreach ($sessions as $session) {/** @var Document $session */
|
||||||
if ($sessionId == $session->getId()) {
|
if ($sessionId == $session->getId()) {
|
||||||
|
|
||||||
$countryName = (isset($countries[strtoupper($session->getAttribute('countryCode'))]))
|
$countryName = $locale->getText('countries.'.strtolower($session->getAttribute('countryCode')), $locale->getText('locale.country.unknown'));
|
||||||
? $countries[strtoupper($session->getAttribute('countryCode'))]
|
|
||||||
: $locale->getText('locale.country.unknown');
|
|
||||||
|
|
||||||
$session
|
$session
|
||||||
->setAttribute('current', ($session->getAttribute('secret') == Auth::hash(Auth::$secret)))
|
->setAttribute('current', ($session->getAttribute('secret') == Auth::hash(Auth::$secret)))
|
||||||
|
@ -1622,7 +1617,7 @@ App::delete('/v1/account/sessions/:sessionId')
|
||||||
if ($session->getAttribute('secret') == Auth::hash(Auth::$secret)) { // If current session delete the cookies too
|
if ($session->getAttribute('secret') == Auth::hash(Auth::$secret)) { // If current session delete the cookies too
|
||||||
$session
|
$session
|
||||||
->setAttribute('current', true)
|
->setAttribute('current', true)
|
||||||
->setAttribute('countryName', (isset($countries[strtoupper($session->getAttribute('countryCode'))])) ? $countries[strtoupper($session->getAttribute('countryCode'))] : $locale->getText('locale.country.unknown'))
|
->setAttribute('countryName', $locale->getText('countries.'.strtolower($session->getAttribute('countryCode')), $locale->getText('locale.country.unknown')))
|
||||||
;
|
;
|
||||||
|
|
||||||
if (!Config::getParam('domainVerification')) {
|
if (!Config::getParam('domainVerification')) {
|
||||||
|
@ -1806,7 +1801,7 @@ App::delete('/v1/account/sessions')
|
||||||
|
|
||||||
$session
|
$session
|
||||||
->setAttribute('current', false)
|
->setAttribute('current', false)
|
||||||
->setAttribute('countryName', (isset($countries[strtoupper($session->getAttribute('countryCode'))])) ? $countries[strtoupper($session->getAttribute('countryCode'))] : $locale->getText('locale.country.unknown'))
|
->setAttribute('countryName', $locale->getText('countries.'.strtolower($session->getAttribute('countryCode')), $locale->getText('locale.country.unknown')))
|
||||||
;
|
;
|
||||||
|
|
||||||
if ($session->getAttribute('secret') == Auth::hash(Auth::$secret)) { // If current session delete the cookies too
|
if ($session->getAttribute('secret') == Auth::hash(Auth::$secret)) { // If current session delete the cookies too
|
||||||
|
|
|
@ -1339,6 +1339,7 @@ trait AccountBase
|
||||||
{
|
{
|
||||||
$id = $data['id'] ?? '';
|
$id = $data['id'] ?? '';
|
||||||
$token = $data['token'] ?? '';
|
$token = $data['token'] ?? '';
|
||||||
|
$email = $data['email'] ?? '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for SUCCESS
|
* Test for SUCCESS
|
||||||
|
@ -1361,6 +1362,20 @@ trait AccountBase
|
||||||
$sessionId = $response['body']['$id'];
|
$sessionId = $response['body']['$id'];
|
||||||
$session = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_'.$this->getProject()['$id']];
|
$session = $this->client->parseCookie((string)$response['headers']['set-cookie'])['a_session_'.$this->getProject()['$id']];
|
||||||
|
|
||||||
|
$response = $this->client->call(Client::METHOD_GET, '/account', array_merge([
|
||||||
|
'origin' => 'http://localhost',
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session,
|
||||||
|
]));
|
||||||
|
|
||||||
|
$this->assertEquals($response['headers']['status-code'], 200);
|
||||||
|
$this->assertNotEmpty($response['body']);
|
||||||
|
$this->assertNotEmpty($response['body']['$id']);
|
||||||
|
$this->assertIsNumeric($response['body']['registration']);
|
||||||
|
$this->assertEquals($response['body']['email'], $email);
|
||||||
|
$this->assertTrue($response['body']['emailVerification']);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for FAILURE
|
* Test for FAILURE
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue