2008-08-11 02:14:48 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Record all login attempts through the {@link LoginForm} object.
|
|
|
|
* This behaviour is disabled by default.
|
|
|
|
*
|
2013-03-21 19:48:54 +01:00
|
|
|
* Enable through {@link Security::$login_recording}.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2008-08-11 02:21:44 +02:00
|
|
|
* Caution: Please make sure that enabling logging
|
|
|
|
* complies with your privacy standards. We're logging
|
|
|
|
* username and IP.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-08-11 02:14:48 +02:00
|
|
|
* @subpackage security
|
2014-01-26 04:17:17 +01:00
|
|
|
*
|
2017-11-30 03:50:36 +01:00
|
|
|
* @property string $Email Email address used for login attempt. @deprecated 3.0...5.0
|
|
|
|
* @property string $EmailHashed sha1 hashed Email address used for login attempt
|
|
|
|
* @property string $Status Status of the login attempt, either 'Success' or 'Failure'
|
|
|
|
* @property string $IP IP address of user attempting to login
|
2014-01-26 04:17:17 +01:00
|
|
|
*
|
2017-11-30 03:50:36 +01:00
|
|
|
* @property int $MemberID ID of the Member, only if Member with Email exists
|
2014-01-26 04:17:17 +01:00
|
|
|
*
|
|
|
|
* @method Member Member() Member object of the user trying to log in, only if Member with Email exists
|
2008-08-11 02:14:48 +02:00
|
|
|
*/
|
|
|
|
class LoginAttempt extends DataObject {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $db = array(
|
2017-11-30 03:50:36 +01:00
|
|
|
'Email' => 'Varchar(255)', // Remove in 5.0
|
|
|
|
'EmailHashed' => 'Varchar(255)',
|
2014-08-15 08:53:05 +02:00
|
|
|
'Status' => "Enum('Success,Failure')",
|
|
|
|
'IP' => 'Varchar(255)',
|
2008-08-11 02:14:48 +02:00
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $has_one = array(
|
2008-08-11 02:14:48 +02:00
|
|
|
'Member' => 'Member', // only linked if the member actually exists
|
|
|
|
);
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function fieldLabels($includerelations = true) {
|
2009-04-29 02:07:39 +02:00
|
|
|
$labels = parent::fieldLabels($includerelations);
|
2008-11-02 21:04:10 +01:00
|
|
|
$labels['Email'] = _t('LoginAttempt.Email', 'Email Address');
|
2017-11-30 03:50:36 +01:00
|
|
|
$labels['EmailHashed'] = _t('LoginAttempt.EmailHashed', 'Email Address (hashed)');
|
2008-11-02 21:04:10 +01:00
|
|
|
$labels['Status'] = _t('LoginAttempt.Status', 'Status');
|
|
|
|
$labels['IP'] = _t('LoginAttempt.IP', 'IP Address');
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2008-11-02 21:04:10 +01:00
|
|
|
return $labels;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2017-11-30 03:50:36 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
public static function getByEmail($email) {
|
|
|
|
return static::get()->filterAny(array(
|
|
|
|
'Email' => $email,
|
|
|
|
'EmailHashed' => sha1($email),
|
|
|
|
));
|
|
|
|
}
|
2008-08-11 02:14:48 +02:00
|
|
|
}
|