Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added some extra functionality to the Gdn_AuthenticationProviderModel.

  • Loading branch information...
commit 52bd574bd80946293ab3781a80d39c982dd07f88 1 parent 80534e6
@tburry tburry authored
View
2  applications/dashboard/settings/structure.php
@@ -146,7 +146,7 @@
->Column('Name', 'varchar(50)', TRUE)
->Column('URL', 'varchar(255)', TRUE)
->Column('AssociationSecret', 'text', FALSE)
- ->Column('AssociationHashMethod', 'varchar(20)', FALSE)
+ ->Column('AssociationHashMethod', 'varchar(20)', TRUE)
->Column('AuthenticateUrl', 'varchar(255)', TRUE)
->Column('RegisterUrl', 'varchar(255)', TRUE)
->Column('SignInUrl', 'varchar(255)', TRUE)
View
72 library/core/class.authenticationprovidermodel.php
@@ -13,23 +13,36 @@
*/
class Gdn_AuthenticationProviderModel extends Gdn_Model {
-
+ const COLUMN_KEY = 'AuthenticationKey';
+ const COLUMN_ALIAS = 'AuthenticationSchemeAlias';
+ const COLUMN_NAME = 'Name';
+
public function __construct() {
parent::__construct('UserAuthenticationProvider');
+ $this->PrimaryKey = self::COLUMN_KEY;
+ }
+
+ protected static function _Calcualate(&$Row) {
+ $Attributes = @unserialize($Row['Attributes']);
+ if (is_array($Attributes))
+ $Row = array_merge($Attributes, $Row);
+ unset($Row['Attributes']);
}
- public function GetProviderByKey($AuthenticationProviderKey) {
+ public static function GetProviderByKey($AuthenticationProviderKey) {
$ProviderData = Gdn::SQL()
->Select('uap.*')
->From('UserAuthenticationProvider uap')
->Where('uap.AuthenticationKey', $AuthenticationProviderKey)
->Get()
->FirstRow(DATASET_TYPE_ARRAY);
+
+ self::_Calcualate($ProviderData);
return $ProviderData;
}
- public function GetProviderByURL($AuthenticationProviderURL) {
+ public static function GetProviderByURL($AuthenticationProviderURL) {
$ProviderData = Gdn::SQL()
->Select('uap.*')
->From('UserAuthenticationProvider uap')
@@ -37,10 +50,12 @@ public function GetProviderByURL($AuthenticationProviderURL) {
->Get()
->FirstRow(DATASET_TYPE_ARRAY);
+ self::_Calcualate($ProviderData);
+
return $ProviderData;
}
- public function GetProviderByScheme($AuthenticationSchemeAlias, $UserID = NULL) {
+ public static function GetProviderByScheme($AuthenticationSchemeAlias, $UserID = NULL) {
$ProviderQuery = Gdn::SQL()
->Select('uap.*')
->From('UserAuthenticationProvider uap')
@@ -50,10 +65,55 @@ public function GetProviderByScheme($AuthenticationSchemeAlias, $UserID = NULL)
$ProviderQuery->Join('UserAuthentication ua', 'ua.ProviderKey = uap.AuthenticationKey', 'left')->Where('ua.UserID', $UserID);
$ProviderData = $ProviderQuery->Get();
- if ($ProviderData->NumRows())
- return $ProviderData->FirstRow(DATASET_TYPE_ARRAY);
+ if ($ProviderData->NumRows()) {
+ $Result = $ProviderData->FirstRow(DATASET_TYPE_ARRAY);
+ self::_Calcualate($Result);
+ return $Result;
+ }
return FALSE;
}
+ public function Save($Data, $Settings = FALSE) {
+ // Grab the current record.
+ $Row = FALSE;
+ if (isset($Data[$this->PrimaryKey]))
+ $Row = $this->GetWhere(array($this->PrimaryKey => $Data[$this->PrimaryKey]))->FirstRow(DATASET_TYPE_ARRAY);
+ elseif ($PK = GetValue('PK', $Settings)) {
+ $Row = $this->GetWhere(array($PK => $Data[$PK]));
+ }
+
+ // Get the columns and put the extended data in the attributes.
+ $this->DefineSchema();
+ $Columns = $this->Schema->Fields();
+ $Attributes = array_diff_key($Data, $Columns, array('TransientKey' => 1, 'hpt' => 1, 'Save' => 1));
+
+ if (!empty($Attributes)) {
+ $Data = array_diff($Data, $Attributes);
+ $Data['Attributes'] = serialize($Attributes);
+ }
+
+ $Insert = !$Row;
+ if ($Insert) {
+ $this->AddInsertFields($Data);
+ } else {
+ $this->AddUpdateFields($Data);
+ }
+
+ // Validate the form posted values
+ if ($this->Validate($Data, $Insert) === TRUE) {
+ $Fields = $this->Validation->ValidationFields();
+ if ($Insert === FALSE) {
+ $PrimaryKeyVal = $Row[$this->PrimaryKey];
+ $this->Update($Fields, array($this->PrimaryKey => $PrimaryKeyVal));
+
+ } else {
+ $PrimaryKeyVal = $this->Insert($Fields);
+ }
+ } else {
+ $PrimaryKeyVal = FALSE;
+ }
+ return $PrimaryKeyVal;
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.