'Varchar(255)', // Remove in 5.0 'EmailHashed' => 'Varchar(255)', 'Status' => "Enum('Success,Failure')", 'IP' => 'Varchar(255)', ]; private static $has_one = [ 'Member' => Member::class, // only linked if the member actually exists ]; private static $indexes = [ "EmailHashed" => true ]; private static $table_name = "LoginAttempt"; /** * @skipUpgrade * @param bool $includerelations Indicate if the labels returned include relation fields * @return array */ public function fieldLabels($includerelations = true) { $labels = parent::fieldLabels($includerelations); $labels['Email'] = _t(__CLASS__ . '.Email', 'Email Address'); $labels['EmailHashed'] = _t(__CLASS__ . '.EmailHashed', 'Email Address (hashed)'); $labels['Status'] = _t(__CLASS__ . '.Status', 'Status'); $labels['IP'] = _t(__CLASS__ . '.IP', 'IP Address'); return $labels; } /** * Set email used for this attempt * * @param string $email * @return $this */ public function setEmail($email) { // Store hashed email only $this->EmailHashed = sha1($email ?? ''); return $this; } /** * Get all login attempts for the given email address * * @param string $email * @return DataList|LoginAttempt[] */ public static function getByEmail($email) { return static::get()->filterAny([ 'EmailHashed' => sha1($email ?? ''), ]); } }