summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2017-03-23 16:06:57 +0100
committerMorris Jobke <hey@morrisjobke.de>2017-04-28 23:41:36 -0300
commit6f41a3edc0bb7a297a28f3e5fa81fb68e3d71a1f (patch)
tree6934f8b244580a3daf8362d1bd76613d944bbedb
parentc9ccdca1ec2f586b8884b41a5319e4a908888df7 (diff)
downloadnextcloud-server-6f41a3edc0bb7a297a28f3e5fa81fb68e3d71a1f.tar.gz
nextcloud-server-6f41a3edc0bb7a297a28f3e5fa81fb68e3d71a1f.zip
store verification status in accounts table and update lookup server
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
-rw-r--r--lib/private/Accounts/AccountManager.php46
-rw-r--r--settings/Controller/UsersController.php11
2 files changed, 56 insertions, 1 deletions
diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php
index 2eb518d4f04..91be4be4ab7 100644
--- a/lib/private/Accounts/AccountManager.php
+++ b/lib/private/Accounts/AccountManager.php
@@ -53,6 +53,10 @@ class AccountManager {
const PROPERTY_ADDRESS = 'address';
const PROPERTY_TWITTER = 'twitter';
+ const NOT_VERIFIED = '0';
+ const VERIFICATION_IN_PROGRESS = '1';
+ const VERIFIED = '2';
+
/** @var IDBConnection database connection */
private $connection;
@@ -85,6 +89,7 @@ class AccountManager {
if (empty($userData)) {
$this->insertNewUser($user, $data);
} elseif ($userData !== $data) {
+ $data = $this->updateVerifyStatus($userData, $data);
$this->updateExistingUser($user, $data);
} else {
// nothing needs to be done if new and old data set are the same
@@ -124,6 +129,41 @@ class AccountManager {
}
/**
+ * reset verification status if personal data changed
+ *
+ * @param array $oldData
+ * @param array $newData
+ * @return array
+ */
+ protected function updateVerifyStatus($oldData, $newData) {
+
+ $twitterVerified = isset($oldData[self::PROPERTY_TWITTER]['verified']) && $oldData[self::PROPERTY_TWITTER]['verified'] === self::VERIFIED;
+ $websiteVerified = isset($oldData[self::PROPERTY_WEBSITE]['verified']) && $oldData[self::PROPERTY_WEBSITE]['verified'] === self::VERIFIED;
+ $emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED;
+
+ if($twitterVerified &&
+ $oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value']
+ ) {
+ $newData[self::PROPERTY_TWITTER]['value']['verified'] = self::NOT_VERIFIED;
+ }
+
+ if($websiteVerified &&
+ $oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value']
+ ) {
+ $newData[self::PROPERTY_WEBSITE]['value']['verified'] = self::NOT_VERIFIED;
+ }
+
+ if($emailVerified &&
+ $oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']
+ ) {
+ $newData[self::PROPERTY_EMAIL]['value']['verified'] = self::NOT_VERIFIED;
+ }
+
+ return $newData;
+
+ }
+
+ /**
* add new user to accounts table
*
* @param IUser $user
@@ -171,21 +211,25 @@ class AccountManager {
[
'value' => $user->getDisplayName(),
'scope' => self::VISIBILITY_CONTACTS_ONLY,
+ 'verified' => '0',
],
self::PROPERTY_ADDRESS =>
[
'value' => '',
'scope' => self::VISIBILITY_PRIVATE,
+ 'verified' => '0',
],
self::PROPERTY_WEBSITE =>
[
'value' => '',
'scope' => self::VISIBILITY_PRIVATE,
+ 'verified' => '0',
],
self::PROPERTY_EMAIL =>
[
'value' => $user->getEMailAddress(),
'scope' => self::VISIBILITY_CONTACTS_ONLY,
+ 'verified' => '0',
],
self::PROPERTY_AVATAR =>
[
@@ -195,11 +239,13 @@ class AccountManager {
[
'value' => '',
'scope' => self::VISIBILITY_PRIVATE,
+ 'verified' => '0',
],
self::PROPERTY_TWITTER =>
[
'value' => '',
'scope' => self::VISIBILITY_PRIVATE,
+ 'verified' => '0',
],
];
}
diff --git a/settings/Controller/UsersController.php b/settings/Controller/UsersController.php
index c9194d85308..e80c4956bcb 100644
--- a/settings/Controller/UsersController.php
+++ b/settings/Controller/UsersController.php
@@ -516,6 +516,12 @@ class UsersController extends Controller {
public function getVerificationCode($account) {
$user = $this->userSession->getUser();
+
+ if ($user === null) {
+ return new DataResponse([], Http::STATUS_BAD_REQUEST);
+ }
+
+ $accountData = $this->accountManager->getUser($user);
$cloudId = $user->getCloudId();
$message = "Use my Federated Cloud ID to share with me: " . $cloudId;
$privateKey = $this->keyManager->getKey($user)->getPrivate();
@@ -527,17 +533,20 @@ class UsersController extends Controller {
switch ($account) {
case 'verify-twitter':
+ $accountData[AccountManager::PROPERTY_TWITTER]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS;
$msg = $this->l10n->t('In order to verify your Twitter account post following tweet on Twitter:');
$code = $codeMd5;
break;
case 'verify-website':
+ $accountData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS;
$msg = $this->l10n->t('In order to verify your Website store following content in your webroot at \'CloudIdVerificationCode.txt\':');
break;
default:
return new DataResponse([], Http::STATUS_BAD_REQUEST);
- break;
}
+ $this->accountManager->updateUser($user, $accountData);
+
return new DataResponse(['msg' => $msg, 'code' => $code]);
}