ask lookup server if email address was verified by the user

Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
This commit is contained in:
Bjoern Schiessle 2017-04-21 17:36:03 +02:00 committed by Morris Jobke
parent 86701dce7b
commit 7c309c253b
No known key found for this signature in database
GPG Key ID: 9CE5ED29E7FCD38A
4 changed files with 45 additions and 5 deletions

View File

@ -33,7 +33,11 @@ $dispatcher->addListener('OC\AccountManager::userUpdated', function(\Symfony\Com
$lookupServer = $config->getSystemValue('lookup_server', ''); $lookupServer = $config->getSystemValue('lookup_server', '');
$updateLookupServer = new \OCA\LookupServerConnector\UpdateLookupServer( $updateLookupServer = new \OCA\LookupServerConnector\UpdateLookupServer(
new \OC\Accounts\AccountManager(\OC::$server->getDatabaseConnection(), \OC::$server->getEventDispatcher()), new \OC\Accounts\AccountManager(
\OC::$server->getDatabaseConnection(),
\OC::$server->getEventDispatcher(),
\OC::$server->getJobList()
),
\OC::$server->getHTTPClientService(), \OC::$server->getHTTPClientService(),
new \OC\Security\IdentityProof\Signer( new \OC\Security\IdentityProof\Signer(
$keyManager, $keyManager,

View File

@ -23,6 +23,7 @@
namespace OC\Accounts; namespace OC\Accounts;
use OCP\BackgroundJob\IJobList;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\IUser; use OCP\IUser;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@ -66,15 +67,22 @@ class AccountManager {
/** @var EventDispatcherInterface */ /** @var EventDispatcherInterface */
private $eventDispatcher; private $eventDispatcher;
/** @var IJobList */
private $jobList;
/** /**
* AccountManager constructor. * AccountManager constructor.
* *
* @param IDBConnection $connection * @param IDBConnection $connection
* @param EventDispatcherInterface $eventDispatcher * @param EventDispatcherInterface $eventDispatcher
* @param IJobList $jobList
*/ */
public function __construct(IDBConnection $connection, EventDispatcherInterface $eventDispatcher) { public function __construct(IDBConnection $connection,
EventDispatcherInterface $eventDispatcher,
IJobList $jobList) {
$this->connection = $connection; $this->connection = $connection;
$this->eventDispatcher = $eventDispatcher; $this->eventDispatcher = $eventDispatcher;
$this->jobList = $jobList;
} }
/** /**
@ -89,6 +97,7 @@ class AccountManager {
if (empty($userData)) { if (empty($userData)) {
$this->insertNewUser($user, $data); $this->insertNewUser($user, $data);
} elseif ($userData !== $data) { } elseif ($userData !== $data) {
$this->checkEmailVerification($userData, $data, $user);
$data = $this->updateVerifyStatus($userData, $data); $data = $this->updateVerifyStatus($userData, $data);
$this->updateExistingUser($user, $data); $this->updateExistingUser($user, $data);
} else { } else {
@ -128,6 +137,28 @@ class AccountManager {
return json_decode($result[0]['data'], true); return json_decode($result[0]['data'], true);
} }
/**
* check if we need to ask the server for email verification, if yes we create a cronjob
*
* @param $oldData
* @param $newData
* @param IUser $user
*/
protected function checkEmailVerification($oldData, $newData, IUser $user) {
if ($oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']) {
$this->jobList->add('OC\Settings\BackgroundJobs\VerifyUserData',
[
'verificationCode' => '',
'data' => $newData[self::PROPERTY_EMAIL]['value'],
'type' => self::PROPERTY_EMAIL,
'uid' => $user->getUID(),
'try' => 0,
'lastRun' => time()
]
);
}
}
/** /**
* reset verification status if personal data changed * reset verification status if personal data changed
* *
@ -152,7 +183,7 @@ class AccountManager {
} }
if(!isset($newData[self::PROPERTY_EMAIL]['verified'])) { if(!isset($newData[self::PROPERTY_EMAIL]['verified'])) {
$newData[self::PROPERTY_EMAIL]['verified'] = isset($oldData[self::PROPERTY_WEBSITE]['verified']) ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::NOT_VERIFIED; $newData[self::PROPERTY_EMAIL]['verified'] = isset($oldData[self::PROPERTY_WEBSITE]['verified']) ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::VERIFICATION_IN_PROGRESS;
} }
// reset verification status if a value from a previously verified data was changed // reset verification status if a value from a previously verified data was changed

View File

@ -89,7 +89,8 @@ class Hooks {
if (is_null($this->accountManager)) { if (is_null($this->accountManager)) {
$this->accountManager = new AccountManager( $this->accountManager = new AccountManager(
\OC::$server->getDatabaseConnection(), \OC::$server->getDatabaseConnection(),
\OC::$server->getEventDispatcher() \OC::$server->getEventDispatcher(),
\OC::$server->getJobList()
); );
} }
return $this->accountManager; return $this->accountManager;

View File

@ -40,7 +40,11 @@ OC_Util::checkLoggedIn();
$defaults = \OC::$server->getThemingDefaults(); $defaults = \OC::$server->getThemingDefaults();
$certificateManager = \OC::$server->getCertificateManager(); $certificateManager = \OC::$server->getCertificateManager();
$accountManager = new \OC\Accounts\AccountManager(\OC::$server->getDatabaseConnection(), \OC::$server->getEventDispatcher()); $accountManager = new \OC\Accounts\AccountManager(
\OC::$server->getDatabaseConnection(),
\OC::$server->getEventDispatcher(),
\OC::$server->getJobList()
);
$config = \OC::$server->getConfig(); $config = \OC::$server->getConfig();
$urlGenerator = \OC::$server->getURLGenerator(); $urlGenerator = \OC::$server->getURLGenerator();