1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 16:52:41 +01:00

Expand the "PhabricatorExternalAccount" table for new registration

Summary:
Ref T1536. This is the schema code for `PhabricatorExternalAccount` which was previously in D4647. I'm splitting it out so I can put it earlier in the sequence and because it's simple and standalone.

Expands `PhabricatorExternalAccount` to have everything we need for the rest of registration.

Test Plan: Implemented the remainder of new registration on top of this.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T1536

Differential Revision: https://secure.phabricator.com/D6169
This commit is contained in:
epriestley 2013-06-14 06:55:18 -07:00
parent efbd3ecc48
commit 8886416e30
5 changed files with 63 additions and 1 deletions

View file

@ -0,0 +1,31 @@
TRUNCATE {$NAMESPACE}_user.user_externalaccount;
ALTER TABLE {$NAMESPACE}_user.user_externalaccount
CHANGE accountDomain accountDomain varchar(64) NOT NULL COLLATE utf8_bin;
ALTER TABLE {$NAMESPACE}_user.user_externalaccount
CHANGE displayName displayName varchar(255) COLLATE utf8_bin;
ALTER TABLE {$NAMESPACE}_user.user_externalaccount
ADD username VARCHAR(255) COLLATE utf8_bin;
ALTER TABLE {$NAMESPACE}_user.user_externalaccount
ADD realName VARCHAR(255) COLLATE utf8_bin;
ALTER TABLE {$NAMESPACE}_user.user_externalaccount
ADD email VARCHAR(255) COLLATE utf8_bin;
ALTER TABLE {$NAMESPACE}_user.user_externalaccount
ADD emailVerified BOOL NOT NULL COLLATE utf8_bin;
ALTER TABLE {$NAMESPACE}_user.user_externalaccount
ADD accountURI VARCHAR(255) COLLATE utf8_bin;
ALTER TABLE {$NAMESPACE}_user.user_externalaccount
ADD profileImagePHID VARCHAR(64) COLLATE utf8_bin;
ALTER TABLE {$NAMESPACE}_user.user_externalaccount
ADD properties LONGTEXT NOT NULL COLLATE utf8_bin;
ALTER TABLE {$NAMESPACE}_user.user_externalaccount
ADD KEY `key_userAccounts` (userPHID);

View file

@ -84,14 +84,17 @@ abstract class PhabricatorMailReceiver {
$allow_email_users = PhabricatorEnv::getEnvConfig($email_key); $allow_email_users = PhabricatorEnv::getEnvConfig($email_key);
if ($allow_email_users) { if ($allow_email_users) {
$xuser = id(new PhabricatorExternalAccount())->loadOneWhere( $xuser = id(new PhabricatorExternalAccount())->loadOneWhere(
'accountType = %s AND accountDomain IS NULL and accountID = %s', 'accountType = %s AND accountDomain = %s and accountID = %s',
'email', 'email',
'self',
$from); $from);
if (!$xuser) { if (!$xuser) {
$xuser = id(new PhabricatorExternalAccount()) $xuser = id(new PhabricatorExternalAccount())
->setAccountID($from) ->setAccountID($from)
->setAccountType('email') ->setAccountType('email')
->setAccountDomain('self')
->setDisplayName($from) ->setDisplayName($from)
->setEmail($from)
->save(); ->save();
} }
return $xuser->getPhabricatorUser(); return $xuser->getPhabricatorUser();

View file

@ -317,6 +317,13 @@ final class PhabricatorUserEditor extends PhabricatorEditor {
$oauth->delete(); $oauth->delete();
} }
$externals = id(new PhabricatorExternalAccount())->loadAllWhere(
'userPHID = %s',
$user->getPHID());
foreach ($externals as $external) {
$external->delete();
}
$prefs = id(new PhabricatorUserPreferences())->loadAllWhere( $prefs = id(new PhabricatorUserPreferences())->loadAllWhere(
'userPHID = %s', 'userPHID = %s',
$user->getPHID()); $user->getPHID());

View file

@ -8,6 +8,13 @@ final class PhabricatorExternalAccount extends PhabricatorUserDAO {
protected $accountSecret; protected $accountSecret;
protected $accountID; protected $accountID;
protected $displayName; protected $displayName;
protected $username;
protected $realName;
protected $email;
protected $emailVerified = 0;
protected $accountURI;
protected $profileImagePHID;
protected $properties = array();
public function generatePHID() { public function generatePHID() {
return PhabricatorPHID::generateNewPHID( return PhabricatorPHID::generateNewPHID(
@ -17,6 +24,9 @@ final class PhabricatorExternalAccount extends PhabricatorUserDAO {
public function getConfiguration() { public function getConfiguration() {
return array( return array(
self::CONFIG_AUX_PHID => true, self::CONFIG_AUX_PHID => true,
self::CONFIG_SERIALIZATION => array(
'properties' => self::SERIALIZATION_JSON,
),
) + parent::getConfiguration(); ) + parent::getConfiguration();
} }
@ -27,4 +37,11 @@ final class PhabricatorExternalAccount extends PhabricatorUserDAO {
return $tmp_usr; return $tmp_usr;
} }
public function save() {
if (!$this->getAccountSecret()) {
$this->setAccountSecret(Filesystem::readRandomCharacters(32));
}
return parent::save();
}
} }

View file

@ -1354,6 +1354,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
'type' => 'sql', 'type' => 'sql',
'name' => $this->getPatchPath('20130606.userxactions.sql'), 'name' => $this->getPatchPath('20130606.userxactions.sql'),
), ),
'20130607.xaccount.sql' => array(
'type' => 'sql',
'name' => $this->getPatchPath('20130607.xaccount.sql'),
),
); );
} }
} }