Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/engine/PhabricatorAuthSessionEngine.php
Show First 20 Lines • Show All 629 Lines • ▼ Show 20 Lines | public function getOneTimeLoginURI( | ||||
$type = self::ONETIME_RESET) { | $type = self::ONETIME_RESET) { | ||||
$key = Filesystem::readRandomCharacters(32); | $key = Filesystem::readRandomCharacters(32); | ||||
$key_hash = $this->getOneTimeLoginKeyHash($user, $email, $key); | $key_hash = $this->getOneTimeLoginKeyHash($user, $email, $key); | ||||
$onetime_type = PhabricatorAuthOneTimeLoginTemporaryTokenType::TOKENTYPE; | $onetime_type = PhabricatorAuthOneTimeLoginTemporaryTokenType::TOKENTYPE; | ||||
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites(); | ||||
id(new PhabricatorAuthTemporaryToken()) | id(new PhabricatorAuthTemporaryToken()) | ||||
->setObjectPHID($user->getPHID()) | ->setTokenResource($user->getPHID()) | ||||
->setTokenType($onetime_type) | ->setTokenType($onetime_type) | ||||
->setTokenExpires(time() + phutil_units('1 day in seconds')) | ->setTokenExpires(time() + phutil_units('1 day in seconds')) | ||||
->setTokenCode($key_hash) | ->setTokenCode($key_hash) | ||||
->save(); | ->save(); | ||||
unset($unguarded); | unset($unguarded); | ||||
$uri = '/login/once/'.$type.'/'.$user->getID().'/'.$key.'/'; | $uri = '/login/once/'.$type.'/'.$user->getID().'/'.$key.'/'; | ||||
if ($email) { | if ($email) { | ||||
Show All 27 Lines | public function loadOneTimeLoginKey( | ||||
PhabricatorUserEmail $email = null, | PhabricatorUserEmail $email = null, | ||||
$key = null) { | $key = null) { | ||||
$key_hash = $this->getOneTimeLoginKeyHash($user, $email, $key); | $key_hash = $this->getOneTimeLoginKeyHash($user, $email, $key); | ||||
$onetime_type = PhabricatorAuthOneTimeLoginTemporaryTokenType::TOKENTYPE; | $onetime_type = PhabricatorAuthOneTimeLoginTemporaryTokenType::TOKENTYPE; | ||||
return id(new PhabricatorAuthTemporaryTokenQuery()) | return id(new PhabricatorAuthTemporaryTokenQuery()) | ||||
->setViewer($user) | ->setViewer($user) | ||||
->withObjectPHIDs(array($user->getPHID())) | ->withTokenResources(array($user->getPHID())) | ||||
->withTokenTypes(array($onetime_type)) | ->withTokenTypes(array($onetime_type)) | ||||
->withTokenCodes(array($key_hash)) | ->withTokenCodes(array($key_hash)) | ||||
->withExpired(false) | ->withExpired(false) | ||||
->executeOne(); | ->executeOne(); | ||||
} | } | ||||
/** | /** | ||||
Show All 27 Lines |