2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2007-09-16 02:44:30 +02:00
|
|
|
/**
|
|
|
|
* The member class which represents the users of the system
|
2008-02-25 03:10:37 +01:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage security
|
2007-09-16 02:44:30 +02:00
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
class Member extends DataObject {
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
static $db = array(
|
|
|
|
'FirstName' => "Varchar",
|
|
|
|
'Surname' => "Varchar",
|
|
|
|
'Email' => "Varchar",
|
2007-09-15 23:51:37 +02:00
|
|
|
'Password' => "Varchar(64)", // support for up to SHA256!
|
2007-09-14 21:10:18 +02:00
|
|
|
'RememberLoginToken' => "Varchar(50)",
|
2007-07-19 12:40:28 +02:00
|
|
|
'NumVisit' => "Int",
|
|
|
|
'LastVisited' => 'Datetime',
|
2007-09-16 03:59:59 +02:00
|
|
|
'Bounced' => 'Boolean', // Note: This does not seem to be used anywhere.
|
2007-09-16 02:32:48 +02:00
|
|
|
'AutoLoginHash' => 'Varchar(30)',
|
2007-09-14 21:10:18 +02:00
|
|
|
'AutoLoginExpired' => 'Datetime',
|
|
|
|
'BlacklistedEmail' => 'Boolean',
|
2007-09-15 23:51:37 +02:00
|
|
|
'PasswordEncryption' => "Enum('none', 'none')",
|
2007-10-21 21:53:57 +02:00
|
|
|
'Salt' => 'Varchar(50)',
|
2008-04-26 08:31:52 +02:00
|
|
|
'PasswordExpiry' => 'Date',
|
2008-04-26 08:32:05 +02:00
|
|
|
'LockedOutUntil' => 'Datetime',
|
2008-04-26 08:31:52 +02:00
|
|
|
'Locale' => 'Varchar(6)',
|
2007-07-19 12:40:28 +02:00
|
|
|
);
|
2007-09-15 23:51:37 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
static $belongs_many_many = array(
|
|
|
|
"Groups" => "Group",
|
|
|
|
|
|
|
|
);
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2008-04-09 13:27:29 +02:00
|
|
|
static $has_one = array();
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
static $has_many = array(
|
|
|
|
'UnsubscribedRecords' => 'Member_UnsubscribeRecord'
|
|
|
|
);
|
2007-10-02 06:55:55 +02:00
|
|
|
|
|
|
|
static $many_many = array();
|
|
|
|
static $many_many_extraFields = array();
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
static $default_sort = "Surname, FirstName";
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
static $indexes = array(
|
|
|
|
'Email' => true,
|
2007-09-16 02:32:48 +02:00
|
|
|
'AutoLoginHash' => 'unique (AutoLoginHash)'
|
2007-07-19 12:40:28 +02:00
|
|
|
);
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
static $notify_password_change = false;
|
|
|
|
|
2008-03-10 22:28:35 +01:00
|
|
|
/**
|
|
|
|
* All searchable database columns
|
|
|
|
* in this object, currently queried
|
|
|
|
* with a "column LIKE '%keywords%'
|
|
|
|
* statement.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @todo Generic implementation of $searchable_fields on DataObject,
|
|
|
|
* with definition for different searching algorithms
|
|
|
|
* (LIKE, FULLTEXT) and default FormFields to construct a searchform.
|
|
|
|
*/
|
|
|
|
static $searchable_fields = array(
|
2008-08-11 04:57:59 +02:00
|
|
|
'FirstName',
|
|
|
|
'Surname',
|
|
|
|
'Email',
|
2008-03-10 22:28:35 +01:00
|
|
|
);
|
|
|
|
|
2008-04-26 08:31:52 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@link PasswordValidator} object for validating user's password
|
|
|
|
*/
|
|
|
|
protected static $password_validator = null;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The number of days that a password should be valid for.
|
|
|
|
* By default, this is null, which means that passwords never expire
|
|
|
|
*/
|
|
|
|
protected static $password_expiry_days = null;
|
2008-04-26 08:32:05 +02:00
|
|
|
|
|
|
|
protected static $lock_out_after_incorrect_logins = null;
|
2008-04-26 08:31:52 +02:00
|
|
|
|
2007-09-15 23:51:37 +02:00
|
|
|
/**
|
|
|
|
* This method is used to initialize the static database members
|
|
|
|
*
|
|
|
|
* Since PHP doesn't support any expressions for the initialization of
|
|
|
|
* static member variables we need a method that does that.
|
|
|
|
*
|
|
|
|
* This method adds all supported encryption algorithms to the
|
|
|
|
* PasswordEncryption Enum field.
|
|
|
|
*
|
|
|
|
* @todo Maybe it would be useful to define this in DataObject and call
|
|
|
|
* it automatically?
|
|
|
|
*/
|
|
|
|
public static function init_db_fields() {
|
|
|
|
self::$db['PasswordEncryption'] = "Enum(array('none', '" .
|
2008-03-10 22:28:35 +01:00
|
|
|
implode("', '", array_map("addslashes", Security::get_encryption_algorithms())) .
|
2007-09-15 23:51:37 +02:00
|
|
|
"'), 'none')";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-16 02:32:48 +02:00
|
|
|
/**
|
|
|
|
* Check if the passed password matches the stored one
|
|
|
|
*
|
|
|
|
* @param string $password The clear text password to check
|
2008-03-10 22:28:35 +01:00
|
|
|
* @return bool Returns TRUE if the passed password is valid, otherwise FALSE.
|
2007-09-16 02:32:48 +02:00
|
|
|
*/
|
|
|
|
public function checkPassword($password) {
|
2008-04-26 08:32:05 +02:00
|
|
|
// Only confirm that the password matches if the user isn't locked out
|
|
|
|
if(!$this->isLockedOut()) {
|
|
|
|
$encryption_details = Security::encrypt_password($password, $this->Salt, $this->PasswordEncryption);
|
|
|
|
return ($this->Password === $encryption_details['password']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this user is locked out
|
|
|
|
*/
|
|
|
|
public function isLockedOut() {
|
|
|
|
return $this->LockedOutUntil && time() < strtotime($this->LockedOutUntil);
|
2007-09-16 02:32:48 +02:00
|
|
|
}
|
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
|
|
|
* Regenerate the session_id.
|
2008-03-10 22:28:35 +01:00
|
|
|
* This wrapper is here to make it easier to disable calls to session_regenerate_id(), should you need to.
|
|
|
|
* They have caused problems in certain
|
2008-02-25 03:10:37 +01:00
|
|
|
* quirky problems (such as using the Windmill 0.3.6 proxy).
|
|
|
|
*/
|
|
|
|
static function session_regenerate_id() {
|
2008-08-06 08:54:59 +02:00
|
|
|
$file = ""; $line = "";
|
|
|
|
if (!headers_sent($file, $line)) session_regenerate_id(true);
|
|
|
|
else user_error("Content already sent at line $line in $file, can't call session_regenerate_id", E_USER_WARNING);
|
2008-04-26 08:31:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a {@link PasswordValidator} object to use to validate member's passwords.
|
|
|
|
*/
|
|
|
|
static function set_password_validator($pv) {
|
|
|
|
self::$password_validator = $pv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the number of days that a password should be valid for.
|
|
|
|
* Set to null (the default) to have passwords never expire.
|
|
|
|
*/
|
|
|
|
static function set_password_expiry($days) {
|
|
|
|
self::$password_expiry_days = $days;
|
|
|
|
}
|
|
|
|
|
2008-04-26 08:32:05 +02:00
|
|
|
/**
|
|
|
|
* Configure the security system to lock users out after this many incorrect logins
|
|
|
|
*/
|
|
|
|
static function lock_out_after_incorrect_logins($numLogins) {
|
|
|
|
self::$lock_out_after_incorrect_logins = $numLogins;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-26 08:31:52 +02:00
|
|
|
function isPasswordExpired() {
|
|
|
|
if(!$this->PasswordExpiry) return false;
|
|
|
|
return strtotime(date('Y-m-d')) >= strtotime($this->PasswordExpiry);
|
2008-02-25 03:10:37 +01:00
|
|
|
}
|
2007-09-16 02:32:48 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-14 21:10:18 +02:00
|
|
|
* Logs this member in
|
|
|
|
*
|
2008-03-10 22:28:35 +01:00
|
|
|
* @param bool $remember If set to TRUE, the member will be logged in automatically the next time.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2007-09-14 21:10:18 +02:00
|
|
|
function logIn($remember = false) {
|
2008-02-25 03:10:37 +01:00
|
|
|
self::session_regenerate_id();
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
Session::set("loggedInAs", $this->ID);
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->NumVisit++;
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
if($remember) {
|
|
|
|
$token = substr(md5(uniqid(rand(), true)), 0, 49 - strlen($this->ID));
|
|
|
|
$this->RememberLoginToken = $token;
|
|
|
|
Cookie::set('alc_enc', $this->ID . ':' . $token);
|
|
|
|
} else {
|
|
|
|
$this->RememberLoginToken = null;
|
|
|
|
Cookie::set('alc_enc', null);
|
|
|
|
Cookie::forceExpiry('alc_enc');
|
|
|
|
}
|
2008-04-26 08:32:05 +02:00
|
|
|
|
|
|
|
// Clear the incorrect log-in count
|
|
|
|
if(self::$lock_out_after_incorrect_logins) {
|
|
|
|
$failedLogins = Session::get('Member.FailedLogins');
|
|
|
|
$failedLogins[$this->Email] = 0;
|
|
|
|
Session::set('Member.FailedLogins', $failedLogins);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->LockedOutUntil = null;
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->write();
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Log the user in if the "remember login" cookie is set
|
|
|
|
*
|
|
|
|
* The <i>remember login token</i> will be changed on every successful
|
|
|
|
* auto-login.
|
|
|
|
*/
|
|
|
|
static function autoLogin() {
|
2007-09-15 23:43:04 +02:00
|
|
|
if(strpos(Cookie::get('alc_enc'), ':') && !Session::get("loggedInAs")) {
|
|
|
|
list($uid, $token) = explode(':', Cookie::get('alc_enc'), 2);
|
2007-09-15 02:27:40 +02:00
|
|
|
$SQL_uid = Convert::raw2sql($uid);
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2007-10-02 23:57:12 +02:00
|
|
|
$member = DataObject::get_one("Member", "Member.ID = '$SQL_uid'");
|
2007-09-15 02:27:40 +02:00
|
|
|
|
2007-10-02 23:57:12 +02:00
|
|
|
if($member && $member->RememberLoginToken != $token) {
|
|
|
|
$member = null;
|
|
|
|
}
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
if($member) {
|
2008-02-25 03:10:37 +01:00
|
|
|
self::session_regenerate_id();
|
2007-09-14 21:10:18 +02:00
|
|
|
Session::set("loggedInAs", $member->ID);
|
|
|
|
|
2007-10-02 23:57:12 +02:00
|
|
|
$token = substr(md5(uniqid(rand(), true)), 0, 49 - strlen($member->ID));
|
2007-09-14 21:10:18 +02:00
|
|
|
$member->RememberLoginToken = $token;
|
|
|
|
Cookie::set('alc_enc', $member->ID . ':' . $token);
|
|
|
|
|
|
|
|
$member->NumVisit++;
|
|
|
|
$member->write();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-14 21:10:18 +02:00
|
|
|
* Logs this member out.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2007-09-14 21:10:18 +02:00
|
|
|
function logOut() {
|
2007-07-19 12:40:28 +02:00
|
|
|
Session::clear("loggedInAs");
|
2008-02-25 03:10:37 +01:00
|
|
|
self::session_regenerate_id();
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
$this->RememberLoginToken = null;
|
|
|
|
Cookie::set('alc_enc', null);
|
|
|
|
Cookie::forceExpiry('alc_enc');
|
|
|
|
|
|
|
|
$this->write();
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate an auto login hash
|
|
|
|
*
|
2007-09-16 02:32:48 +02:00
|
|
|
* This creates an auto login hash that can be used to reset the password.
|
|
|
|
*
|
2008-03-10 22:28:35 +01:00
|
|
|
* @param int $lifetime The lifetime of the auto login hash in days (by default 2 days)
|
2007-09-16 02:32:48 +02:00
|
|
|
*
|
2008-03-10 22:28:35 +01:00
|
|
|
* @todo Make it possible to handle database errors such as a "duplicate key" error
|
2007-09-14 21:10:18 +02:00
|
|
|
*/
|
2007-09-16 02:32:48 +02:00
|
|
|
function generateAutologinHash($lifetime = 2) {
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-16 02:32:48 +02:00
|
|
|
do {
|
|
|
|
$hash = substr(base_convert(md5(uniqid(mt_rand(), true)), 16, 36),
|
|
|
|
0, 30);
|
|
|
|
} while(DataObject::get_one('Member', "`AutoLoginHash` = '$hash'"));
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-16 02:32:48 +02:00
|
|
|
$this->AutoLoginHash = $hash;
|
|
|
|
$this->AutoLoginExpired = date('Y-m-d', time() + (86400 * $lifetime));
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->write();
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-16 02:32:48 +02:00
|
|
|
* Return the member for the auto login hash
|
|
|
|
*
|
|
|
|
* @param bool $login Should the member be logged in?
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2008-08-11 07:18:18 +02:00
|
|
|
static function member_from_autologinhash($RAW_hash, $login = false) {
|
2007-09-14 21:10:18 +02:00
|
|
|
$SQL_hash = Convert::raw2sql($RAW_hash);
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-16 02:32:48 +02:00
|
|
|
$member = DataObject::get_one('Member',"`AutoLoginHash`='" . $SQL_hash .
|
|
|
|
"' AND `AutoLoginExpired` > NOW()");
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-16 02:32:48 +02:00
|
|
|
if($login && $member)
|
2007-07-19 12:40:28 +02:00
|
|
|
$member->logIn();
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return $member;
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send signup, change password or forgot password informations to an user
|
|
|
|
*
|
2008-03-10 22:28:35 +01:00
|
|
|
* @param string $type Information type to send ("signup", "changePassword" or "forgotPassword")
|
|
|
|
* @param array $data Additional data to pass to the email (can be used in the template)
|
2007-09-14 21:10:18 +02:00
|
|
|
*/
|
2007-09-16 02:32:48 +02:00
|
|
|
function sendInfo($type = 'signup', $data = null) {
|
2007-07-19 12:40:28 +02:00
|
|
|
switch($type) {
|
2007-09-14 21:10:18 +02:00
|
|
|
case "signup":
|
2008-02-25 03:10:37 +01:00
|
|
|
$e = Object::create('Member_SignupEmail');
|
2007-09-14 21:10:18 +02:00
|
|
|
break;
|
|
|
|
case "changePassword":
|
2008-02-25 03:10:37 +01:00
|
|
|
$e = Object::create('Member_ChangePasswordEmail');
|
2007-09-14 21:10:18 +02:00
|
|
|
break;
|
|
|
|
case "forgotPassword":
|
2008-02-25 03:10:37 +01:00
|
|
|
$e = Object::create('Member_ForgotPasswordEmail');
|
2007-09-14 21:10:18 +02:00
|
|
|
break;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-16 02:32:48 +02:00
|
|
|
|
|
|
|
if(is_array($data)) {
|
|
|
|
foreach($data as $key => $value)
|
|
|
|
$e->$key = $value;
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$e->populateTemplate($this);
|
|
|
|
$e->send();
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
/**
|
2007-12-02 22:28:41 +01:00
|
|
|
* Returns the fields for the member form - used in the registration/profile module.
|
|
|
|
* It should return fields that are editable by the admin and the logged-in user.
|
2007-09-14 21:10:18 +02:00
|
|
|
*
|
|
|
|
* @return FieldSet Returns a {@link FieldSet} containing the fields for
|
|
|
|
* the member form.
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
function getMemberFormFields() {
|
2007-12-02 22:28:41 +01:00
|
|
|
$fields = new FieldSet(
|
2007-10-25 04:47:45 +02:00
|
|
|
new TextField("FirstName", _t('Member.FIRSTNAME', 'First Name')),
|
|
|
|
new TextField("Surname", _t('Member.SURNAME', "Surname")),
|
|
|
|
new TextField("Email", _t('Member.EMAIL', "Email", PR_MEDIUM, 'Noun')),
|
|
|
|
new TextField("Password", _t('Member.PASSWORD', 'Password'))
|
2007-07-19 12:40:28 +02:00
|
|
|
);
|
2007-12-02 22:28:41 +01:00
|
|
|
|
|
|
|
$this->extend('augmentMemberFormFields', $fields);
|
|
|
|
return $fields;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Factory method for the member validator
|
|
|
|
*
|
|
|
|
* @return Member_Validator Returns an instance of a
|
|
|
|
* {@link Member_Validator} object.
|
|
|
|
*/
|
2008-02-25 03:10:37 +01:00
|
|
|
function getNewsletterSubscriptions(){
|
|
|
|
$groups = $this->Groups()->toDropDownMap("ID","ID");
|
|
|
|
return $groups;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This does some cunning and automatically save the newsletter subscriptions
|
|
|
|
* by adding and removing the member from the appropriate
|
|
|
|
* groups based on a checkboxset field.
|
|
|
|
* This function is called by the form handler
|
|
|
|
* whenever form->saveInto($member); is called with an
|
|
|
|
* checkboxsetfield in the data with the name
|
|
|
|
* "newsletterSubscriptions"
|
|
|
|
*/
|
|
|
|
function saveNewsletterSubscriptions($groups){
|
|
|
|
$checkboxsetfield = new CheckboxSetField(
|
|
|
|
"NewsletterSubscriptions",
|
|
|
|
"",
|
|
|
|
$sourceitems = DataObject::get("NewsletterType")->toDropDownMap("GroupID","Title"),
|
|
|
|
$selectedgroups = $groups
|
|
|
|
);
|
|
|
|
return $this->Groups()->setByCheckboxSetField($checkboxsetfield);
|
|
|
|
}
|
|
|
|
|
|
|
|
function removeAllNewsletterSubscriptions(){
|
|
|
|
$groups = $this->Groups();
|
|
|
|
$groupIDs = $groups->getIDList();
|
|
|
|
$newsletterTypes = DataObject::get("NewsletterType");
|
|
|
|
if($newsletterTypes&&$newsletterTypes->count()){
|
|
|
|
foreach($newsletterTypes as $type){
|
|
|
|
$newsletterGroupIDs[] = $type->GroupID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($newsletterGroupIDs) {
|
|
|
|
foreach($newsletterGroupIDs as $newsletterGroupID){
|
|
|
|
if($groupIDs&&in_array($newsletterGroupID, $groupIDs)){
|
|
|
|
$groups->remove($newsletterGroupID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function getValidator() {
|
|
|
|
return new Member_Validator();
|
|
|
|
}
|
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-14 21:10:18 +02:00
|
|
|
* Returns the current logged in user
|
|
|
|
*
|
|
|
|
* @return bool|Member Returns the member object of the current logged in
|
|
|
|
* user or FALSE.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
static function currentUser() {
|
2007-09-14 21:10:18 +02:00
|
|
|
$id = Session::get("loggedInAs");
|
|
|
|
if(!$id) {
|
|
|
|
self::autoLogin();
|
|
|
|
$id = Session::get("loggedInAs");
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
if($id) {
|
2007-07-19 12:40:28 +02:00
|
|
|
return DataObject::get_one("Member", "Member.ID = $id");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
/**
|
|
|
|
* Get the ID of the current logged in user
|
|
|
|
*
|
|
|
|
* @return int Returns the ID of the current logged in user or 0.
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
static function currentUserID() {
|
|
|
|
$id = Session::get("loggedInAs");
|
2007-09-14 21:10:18 +02:00
|
|
|
if(!$id) {
|
|
|
|
self::autoLogin();
|
|
|
|
$id = Session::get("loggedInAs");
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return is_numeric($id) ? $id : 0;
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-14 21:10:18 +02:00
|
|
|
* Add the members email address to the blacklist
|
|
|
|
*
|
|
|
|
* With this method the blacklisted email table is updated to ensure that
|
|
|
|
* no promotional material is sent to the member (newsletters).
|
|
|
|
* Standard system messages are still sent such as receipts.
|
|
|
|
*
|
|
|
|
* @param bool $val Set to TRUE if the address should be added to the
|
|
|
|
* blacklist, otherwise to FALSE.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2007-09-14 21:10:18 +02:00
|
|
|
function setBlacklistedEmail($val) {
|
|
|
|
if($val && $this->Email) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$blacklisting = new Email_BlackList();
|
|
|
|
$blacklisting->BlockedEmail = $this->Email;
|
|
|
|
$blacklisting->MemberID = $this->ID;
|
|
|
|
$blacklisting->write();
|
|
|
|
}
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
$this->setField("BlacklistedEmail", $val);
|
2007-09-16 03:53:02 +02:00
|
|
|
// Save the BlacklistedEmail field to the Member table
|
|
|
|
$this->write();
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
/*
|
2008-03-10 22:28:35 +01:00
|
|
|
* Generate a random password, with randomiser to kick in if there's no words file on the
|
2007-09-14 21:10:18 +02:00
|
|
|
* filesystem.
|
|
|
|
*
|
|
|
|
* @return string Returns a random password.
|
|
|
|
*/
|
2008-02-25 03:10:37 +01:00
|
|
|
static function create_new_password() {
|
2007-10-25 03:51:53 +02:00
|
|
|
if(file_exists(Security::get_word_list())) {
|
|
|
|
$words = file(Security::get_word_list());
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
list($usec, $sec) = explode(' ', microtime());
|
|
|
|
srand($sec + ((float) $usec * 100000));
|
|
|
|
|
|
|
|
$word = trim($words[rand(0,sizeof($words)-1)]);
|
|
|
|
$number = rand(10,999);
|
|
|
|
|
|
|
|
return $word . $number;
|
|
|
|
} else {
|
|
|
|
$random = rand();
|
|
|
|
$string = md5($random);
|
|
|
|
$output = substr($string, 0, 6);
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler called before writing to the database
|
|
|
|
*
|
|
|
|
* If an email's filled out look for a record with the same email and if
|
|
|
|
* found update this record to merge with that member.
|
|
|
|
*/
|
2008-04-26 08:31:52 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function onBeforeWrite() {
|
2008-03-11 02:30:29 +01:00
|
|
|
if($this->SetPassword) $this->Password = $this->SetPassword;
|
2007-09-15 23:51:37 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if($this->Email) {
|
2007-09-14 21:10:18 +02:00
|
|
|
if($this->ID) {
|
|
|
|
$idClause = "AND `Member`.ID <> $this->ID";
|
|
|
|
} else {
|
|
|
|
$idClause = "";
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
$existingRecord = DataObject::get_one(
|
|
|
|
"Member", "Email = '" . addslashes($this->Email) . "' $idClause");
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// Debug::message("Found an existing member for email $this->Email");
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if($existingRecord) {
|
|
|
|
$newID = $existingRecord->ID;
|
|
|
|
if($this->ID) {
|
|
|
|
DB::query("UPDATE Group_Members SET MemberID = $newID WHERE MemberID = $this->ID");
|
|
|
|
}
|
|
|
|
$this->ID = $newID;
|
|
|
|
// Merge existing data into the local record
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
foreach($existingRecord->getAllFields() as $k => $v) {
|
2007-08-14 00:04:03 +02:00
|
|
|
if(!isset($this->changed[$k]) || !$this->changed[$k]) $this->record[$k] = $v;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-02-25 03:10:37 +01:00
|
|
|
|
2008-07-21 00:36:58 +02:00
|
|
|
// We don't send emails out on dev/tests sites to prevent accidentally spamming users.
|
|
|
|
// However, if TestMailer is in use this isn't a risk.
|
|
|
|
if((Director::isLive() || Email::mailer() instanceof TestMailer) &&
|
2008-04-22 01:57:04 +02:00
|
|
|
isset($this->changed['Password']) && $this->changed['Password'] && $this->record['Password'] &&
|
2008-02-25 03:10:37 +01:00
|
|
|
Member::$notify_password_change) $this->sendInfo('changePassword');
|
|
|
|
|
2008-04-26 08:31:52 +02:00
|
|
|
// The test on $this->ID is used for when records are initially created
|
|
|
|
if(!$this->ID || (isset($this->changed['Password']) && $this->changed['Password'])) {
|
2008-03-11 02:30:29 +01:00
|
|
|
// Password was changed: encrypt the password according the settings
|
|
|
|
$encryption_details = Security::encrypt_password($this->Password);
|
|
|
|
$this->Password = $encryption_details['password'];
|
|
|
|
$this->Salt = $encryption_details['salt'];
|
|
|
|
$this->PasswordEncryption = $encryption_details['algorithm'];
|
|
|
|
|
|
|
|
$this->changed['Salt'] = true;
|
|
|
|
$this->changed['PasswordEncryption'] = true;
|
2008-04-26 08:31:52 +02:00
|
|
|
|
|
|
|
// If we haven't manually set a password expiry
|
|
|
|
if(!isset($this->changed['PasswordExpiry']) || !$this->changed['PasswordExpiry']) {
|
|
|
|
// then set it for us
|
|
|
|
if(self::$password_expiry_days) {
|
|
|
|
$this->PasswordExpiry = date('Y-m-d', time() + 86400 * self::$password_expiry_days);
|
|
|
|
} else {
|
|
|
|
$this->PasswordExpiry = null;
|
|
|
|
}
|
|
|
|
}
|
2008-03-11 02:30:29 +01:00
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
parent::onBeforeWrite();
|
|
|
|
}
|
2008-04-26 08:31:52 +02:00
|
|
|
|
|
|
|
function onAfterWrite() {
|
|
|
|
parent::onAfterWrite();
|
|
|
|
|
|
|
|
if(isset($this->changed['Password']) && $this->changed['Password']) {
|
|
|
|
MemberPassword::log($this);
|
|
|
|
}
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Check if the member is in one of the given groups
|
2007-09-14 21:10:18 +02:00
|
|
|
*
|
|
|
|
* @param array $groups Groups to check
|
|
|
|
* @return bool Returns TRUE if the member is in one of the given groups,
|
|
|
|
* otherwise FALSE.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2007-09-14 21:10:18 +02:00
|
|
|
public function inGroups(array $groups) {
|
|
|
|
foreach($this->Groups() as $group)
|
2007-07-19 12:40:28 +02:00
|
|
|
$memberGroups[] = $group->Title;
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
return count(array_intersect($memberGroups, $groups)) > 0;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
/**
|
|
|
|
* Check if the member is in the given group
|
|
|
|
*
|
|
|
|
* @param int $groupID ID of the group to check
|
|
|
|
* @return bool Returns TRUE if the member is in the given group,
|
|
|
|
* otherwise FALSE.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2008-02-25 03:10:37 +01:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
public function inGroup($groupID) {
|
|
|
|
foreach($this->Groups() as $group) {
|
|
|
|
if($groupID == $group->ID)
|
|
|
|
return true;
|
2008-02-25 03:10:37 +01:00
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
return false;
|
|
|
|
}
|
2008-02-25 03:10:37 +01:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
/**
|
|
|
|
* Alias for {@link inGroup}
|
|
|
|
*
|
|
|
|
* @param int $groupID ID of the group to check
|
|
|
|
* @return bool Returns TRUE if the member is in the given group,
|
|
|
|
* otherwise FALSE.
|
|
|
|
* @see inGroup()
|
|
|
|
*/
|
|
|
|
public function isInGroup($groupID) {
|
|
|
|
return $this->inGroup($groupID);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Returns true if this user is an administrator.
|
|
|
|
* Administrators have access to everything. The lucky bastards! ;-)
|
2007-09-14 21:10:18 +02:00
|
|
|
*
|
|
|
|
* @return Returns TRUE if this user is an administrator.
|
2007-08-06 02:47:31 +02:00
|
|
|
* @todo Should this function really exists? Is not {@link isAdmin()} the
|
|
|
|
* only right name for this?
|
|
|
|
* @todo Is {@link Group}::CanCMSAdmin not deprecated?
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2008-08-12 04:51:33 +02:00
|
|
|
function isAdmin() {
|
2007-07-19 12:40:28 +02:00
|
|
|
if($groups = $this->Groups()) {
|
2007-09-14 21:10:18 +02:00
|
|
|
foreach($groups as $group) {
|
|
|
|
if($group->CanCMSAdmin)
|
|
|
|
return true;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-08-06 02:47:31 +02:00
|
|
|
|
|
|
|
return Permission::check('ADMIN');
|
|
|
|
}
|
2008-08-12 04:51:33 +02:00
|
|
|
|
|
|
|
function _isAdmin() {
|
|
|
|
user_error("Deprecated. Use isAdmin() instead", E_USER_NOTICE);
|
|
|
|
return $this->isAdmin();
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2008-08-12 04:51:33 +02:00
|
|
|
|
|
|
|
function isCMSUser() {
|
2007-07-19 12:40:28 +02:00
|
|
|
if($groups = $this->Groups()) {
|
2007-09-14 21:10:18 +02:00
|
|
|
foreach($groups as $group) {
|
|
|
|
if($group->CanCMS)
|
|
|
|
return true;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2008-08-12 04:51:33 +02:00
|
|
|
function _isCMSUser() {
|
|
|
|
user_error("Deprecated. Use isCMSUser() instead", E_USER_NOTICE);
|
|
|
|
return $this->isCMSUser();
|
|
|
|
}
|
|
|
|
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
//------------------- HELPER METHODS -----------------------------------//
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
/**
|
|
|
|
* Get the complete name of the member
|
|
|
|
*
|
|
|
|
* @return string Returns the first- and surname of the member. If the ID
|
|
|
|
* of the member is equal 0, only the surname is returned.
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
public function getTitle() {
|
|
|
|
if($this->getField('ID') === 0)
|
|
|
|
return $this->getField('Surname');
|
|
|
|
return $this->getField('Surname') . ', ' . $this->getField('FirstName');
|
2007-09-14 20:23:28 +02:00
|
|
|
}
|
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the complete name of the member
|
|
|
|
*
|
|
|
|
* @return string Returns the first- and surname of the member.
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
public function getName() {
|
|
|
|
return $this->FirstName . ' ' . $this->Surname;
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set first- and surname
|
|
|
|
*
|
|
|
|
* This method assumes that the last part of the name is the surname, e.g.
|
|
|
|
* <i>A B C</i> will result in firstname <i>A B</i> and surname <i>C</i>
|
|
|
|
*
|
|
|
|
* @param string $name The name
|
|
|
|
*/
|
|
|
|
public function setName($name) {
|
|
|
|
$nameParts = explode(' ', $name);
|
|
|
|
$this->Surname = array_pop($nameParts);
|
|
|
|
$this->FirstName = join(' ', $nameParts);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Alias for {@link setName}
|
|
|
|
*
|
|
|
|
* @param string $name The name
|
|
|
|
* @see setName()
|
|
|
|
*/
|
|
|
|
public function splitName($name) {
|
|
|
|
return $this->setName($name);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
//---------------------------------------------------------------------//
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
/**
|
2007-09-15 02:23:44 +02:00
|
|
|
* Get a "many-to-many" map that holds for all members their group
|
|
|
|
* memberships
|
|
|
|
*
|
|
|
|
* @return Member_GroupSet Returns a map holding for all members their
|
|
|
|
* group memberships.
|
2007-09-14 21:10:18 +02:00
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
public function Groups() {
|
|
|
|
$groups = $this->getManyManyComponents("Groups");
|
2007-09-15 02:40:28 +02:00
|
|
|
|
2008-08-11 05:10:59 +02:00
|
|
|
$unsecure = DataObject::get("Group_Unsecure");
|
2007-09-14 21:10:18 +02:00
|
|
|
if($unsecure) {
|
|
|
|
foreach($unsecure as $unsecureItem) {
|
|
|
|
$groups->push($unsecureItem);
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$groupIDs = $groups->column();
|
|
|
|
$collatedGroups = array();
|
|
|
|
foreach($groups as $group) {
|
2007-09-15 02:23:44 +02:00
|
|
|
$collatedGroups = array_merge((array)$collatedGroups,
|
|
|
|
$group->collateAncestorIDs());
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$table = "Group_Members";
|
|
|
|
|
2007-09-14 20:23:28 +02:00
|
|
|
if(count($collatedGroups) > 0) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$collatedGroups = implode(", ", array_unique($collatedGroups));
|
|
|
|
|
2008-04-26 08:35:03 +02:00
|
|
|
$unfilteredGroups = singleton('Group')->instance_get("`ID` IN ($collatedGroups)", "ID", "", "", "Member_GroupSet");
|
|
|
|
$result = new ComponentSet();
|
|
|
|
|
|
|
|
// Only include groups where allowedIPAddress() returns true
|
|
|
|
foreach($unfilteredGroups as $group) {
|
|
|
|
if($group->allowedIPAddress($_SERVER['REMOTE_ADDR'])) $result->push($group);
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
} else {
|
|
|
|
$result = new Member_GroupSet();
|
|
|
|
}
|
|
|
|
|
2007-09-15 02:23:44 +02:00
|
|
|
$result->setComponentInfo("many-to-many", $this, "Member", $table,
|
|
|
|
"Group");
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
/**
|
2007-09-15 02:23:44 +02:00
|
|
|
* Get member SQLMap
|
|
|
|
*
|
|
|
|
* @param string $filter Filter for the SQL statement (WHERE clause)
|
|
|
|
* @param string $sort Sorting function (ORDER clause)
|
|
|
|
* @param string $blank Shift a blank member in the items
|
|
|
|
* @return SQLMap Returns an SQLMap that returns all Member data.
|
|
|
|
*
|
|
|
|
* @todo Improve documentation of this function! (Markus)
|
2007-09-14 21:10:18 +02:00
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
public function map($filter = "", $sort = "", $blank="") {
|
|
|
|
$ret = new SQLMap(singleton('Member')->extendedSQL($filter, $sort));
|
2007-09-14 21:10:18 +02:00
|
|
|
if($blank) {
|
2008-07-11 01:52:08 +02:00
|
|
|
$blankMember = Object::create('Member');
|
2007-07-19 12:40:28 +02:00
|
|
|
$blankMember->Surname = $blank;
|
|
|
|
$blankMember->ID = 0;
|
|
|
|
|
|
|
|
$ret->getItems()->shift($blankMember);
|
|
|
|
}
|
2007-09-15 02:23:44 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return $ret;
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
/**
|
2007-09-15 02:23:44 +02:00
|
|
|
* Get a member SQLMap of members in specific groups
|
|
|
|
*
|
|
|
|
* @param mixed $groups Optional groups to include in the map. If NULL is
|
|
|
|
* passed, all groups are returned, i.e.
|
|
|
|
* {@link map()} will be called.
|
|
|
|
* @return SQLMap Returns an SQLMap that returns all Member data.
|
|
|
|
* @see map()
|
|
|
|
*
|
|
|
|
* @todo Improve documentation of this function! (Markus)
|
2007-09-14 21:10:18 +02:00
|
|
|
*/
|
|
|
|
public static function mapInGroups($groups = null) {
|
|
|
|
if(!$groups)
|
2007-07-19 12:40:28 +02:00
|
|
|
return Member::map();
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$groupIDList = array();
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
if(is_a($groups, 'DataObjectSet')) {
|
2007-07-19 12:40:28 +02:00
|
|
|
foreach( $groups as $group )
|
|
|
|
$groupIDList[] = $group->ID;
|
2007-09-14 21:10:18 +02:00
|
|
|
} elseif(is_array($groups)) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$groupIDList = $groups;
|
2007-09-14 21:10:18 +02:00
|
|
|
} else {
|
2007-07-19 12:40:28 +02:00
|
|
|
$groupIDList[] = $groups;
|
2007-09-14 21:10:18 +02:00
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
if(empty($groupIDList))
|
2007-09-14 20:23:28 +02:00
|
|
|
return Member::map();
|
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
return new SQLMap(singleton('Member')->extendedSQL(
|
|
|
|
"`GroupID` IN (" . implode( ',', $groupIDList ) .
|
|
|
|
")", "Surname, FirstName", "", "INNER JOIN `Group_Members` ON `MemberID`=`Member`.`ID`"));
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-14 21:10:18 +02:00
|
|
|
* Get a map of all members in the groups given that have CMS permissions
|
|
|
|
*
|
|
|
|
* If no groups are passed, all groups with CMS permissions will be used.
|
|
|
|
*
|
|
|
|
* @param array $groups Groups to consider or NULL to use all groups with
|
|
|
|
* CMS permissions.
|
|
|
|
* @return SQLMap Returns a map of all members in the groups given that
|
|
|
|
* have CMS permissions.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2007-09-14 21:10:18 +02:00
|
|
|
public static function mapInCMSGroups($groups = null) {
|
|
|
|
if(!$groups || $groups->Count() == 0) {
|
|
|
|
$groups = DataObject::get('Group', "", "",
|
|
|
|
"INNER JOIN `Permission` ON `Permission`.GroupID = `Group`.ID AND `Permission`.Code IN ('ADMIN', 'CMS_ACCESS_AssetAdmin')");
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$groupIDList = array();
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
if(is_a($groups, 'DataObjectSet')) {
|
|
|
|
foreach($groups as $group)
|
2007-07-19 12:40:28 +02:00
|
|
|
$groupIDList[] = $group->ID;
|
2007-09-14 21:10:18 +02:00
|
|
|
} elseif(is_array($groups)) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$groupIDList = $groups;
|
2007-09-14 21:10:18 +02:00
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/*if( empty( $groupIDList ) )
|
|
|
|
return Member::map(); */
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
$filterClause = ($groupIDList)
|
|
|
|
? "`GroupID` IN (" . implode( ',', $groupIDList ) . ")"
|
|
|
|
: "";
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
return new SQLMap(singleton('Member')->extendedSQL($filterClause,
|
|
|
|
"Surname, FirstName", "",
|
|
|
|
"INNER JOIN `Group_Members` ON `MemberID`=`Member`.`ID` INNER JOIN `Group` ON `Group`.`ID`=`GroupID`"));
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2007-09-14 20:23:28 +02:00
|
|
|
/**
|
2007-09-14 21:10:18 +02:00
|
|
|
* Get the groups in which the member is NOT in
|
|
|
|
*
|
|
|
|
* When passed an array of groups, and a component set of groups, this
|
|
|
|
* function will return the array of groups the member is NOT in.
|
|
|
|
*
|
|
|
|
* @param array $groupList An array of group code names.
|
|
|
|
* @param array $memberGroups A component set of groups (if set to NULL,
|
|
|
|
* $this->groups() will be used)
|
|
|
|
* @return array Groups in which the member is NOT in.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2007-09-14 21:10:18 +02:00
|
|
|
public function memberNotInGroups($groupList, $memberGroups = null){
|
|
|
|
if(!$memberGroups)
|
|
|
|
$memberGroups = $this->Groups();
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
foreach($memberGroups as $group) {
|
|
|
|
if(in_array($group->Code, $groupList)) {
|
|
|
|
$index = array_search($group->Code, $groupList);
|
2007-07-19 12:40:28 +02:00
|
|
|
unset($groupList[$index]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $groupList;
|
|
|
|
}
|
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-14 21:10:18 +02:00
|
|
|
* Return a {@link FieldSet} of fields that would appropriate for editing
|
|
|
|
* this member.
|
|
|
|
*
|
|
|
|
* @return FieldSet Return a FieldSet of fields that would appropriate for
|
|
|
|
* editing this member.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
public function getCMSFields() {
|
2007-10-21 21:53:57 +02:00
|
|
|
$locale = ($this->Locale) ? $this->Locale : i18n::get_locale();
|
|
|
|
|
2007-11-12 03:58:27 +01:00
|
|
|
$password = new ConfirmedPasswordField('Password', 'Password');
|
|
|
|
$password->setCanBeEmpty(true);
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$fields = new FieldSet(
|
|
|
|
//new TextField("Salutation", "Title"),
|
2007-10-25 04:47:45 +02:00
|
|
|
new HeaderField(_t('Member.PERSONALDETAILS', "Personal Details", PR_MEDIUM, 'Headline for formfields')),
|
|
|
|
new TextField("FirstName", _t('Member.FIRSTNAME')),
|
|
|
|
new TextField("Surname", _t('Member.SURNAME')),
|
|
|
|
new HeaderField(_t('Member.USERDETAILS', "User Details", PR_MEDIUM, 'Headline for formfields')),
|
|
|
|
new TextField("Email", _t('Member.EMAIL')),
|
|
|
|
new DropdownField(
|
|
|
|
"Locale",
|
|
|
|
_t('Member.INTERFACELANG', "Interface Language", PR_MEDIUM, 'Language of the CMS'),
|
|
|
|
i18n::get_existing_translations(),
|
|
|
|
$locale
|
|
|
|
),
|
2007-11-12 03:58:27 +01:00
|
|
|
$password
|
2007-07-19 12:40:28 +02:00
|
|
|
);
|
2007-09-15 02:40:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->extend('updateCMSFields', $fields);
|
2007-09-15 02:40:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return $fields;
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
/**
|
|
|
|
* Unsubscribe from newsletter
|
|
|
|
*
|
|
|
|
* @param NewsletterType $newsletterType Newsletter type to unsubscribe
|
|
|
|
* from
|
|
|
|
*/
|
|
|
|
function unsubscribeFromNewsletter(NewsletterType $newsletterType) {
|
2007-07-19 12:40:28 +02:00
|
|
|
// record today's date in unsubscriptions
|
2007-09-14 21:10:18 +02:00
|
|
|
// this is a little bit redundant
|
|
|
|
$unsubscribeRecord = new Member_UnsubscribeRecord();
|
|
|
|
$unsubscribeRecord->unsubscribe($this, $newsletterType);
|
|
|
|
$this->Groups()->remove($newsletterType->GroupID);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function requireDefaultRecords() {
|
|
|
|
parent::requireDefaultRecords();
|
|
|
|
|
2007-07-20 01:15:05 +02:00
|
|
|
if(!DB::query("SELECT * FROM Member")->value() && isset($_REQUEST['username']) && isset($_REQUEST['password'])) {
|
2007-07-19 12:40:28 +02:00
|
|
|
Security::findAnAdministrator($_REQUEST['username'], $_REQUEST['password']);
|
2007-08-24 05:31:14 +02:00
|
|
|
Database::alteration_message("Added admin account","created");
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
2007-11-09 02:10:45 +01:00
|
|
|
|
|
|
|
function canEdit() {
|
2007-11-09 02:21:26 +01:00
|
|
|
if( $this->ID == Member::currentUserID() ) return true;
|
|
|
|
|
|
|
|
return Permission::check( 'ADMIN' );
|
2007-11-09 02:10:45 +01:00
|
|
|
}
|
2008-04-26 08:31:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate this member object.
|
|
|
|
*/
|
|
|
|
function validate() {
|
|
|
|
$valid = parent::validate();
|
|
|
|
|
|
|
|
if(!$this->ID || (isset($this->changed['Password']) && $this->changed['Password'])) {
|
|
|
|
if(self::$password_validator) {
|
|
|
|
$valid->combineAnd(self::$password_validator->validate($this->Password, $this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-15 09:14:31 +02:00
|
|
|
if((!$this->ID && $this->SetPassword) || (isset($this->changed['SetPassword']) && $this->changed['SetPassword'])) {
|
2008-04-26 08:36:03 +02:00
|
|
|
if(self::$password_validator) {
|
|
|
|
$valid->combineAnd(self::$password_validator->validate($this->SetPassword, $this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-26 08:31:52 +02:00
|
|
|
return $valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
function changePassword($password) {
|
|
|
|
$this->Password = $password;
|
|
|
|
$valid = $this->validate();
|
|
|
|
|
|
|
|
if($valid->valid()) {
|
|
|
|
$this->AutoLoginHash = null;
|
|
|
|
$this->write();
|
2008-04-26 08:35:14 +02:00
|
|
|
|
|
|
|
// Emails will be sent by Member::onBeforeWrite().
|
2008-04-26 08:31:52 +02:00
|
|
|
|
2008-04-26 08:35:14 +02:00
|
|
|
//$this->sendinfo('changePassword', array('CleartextPassword' => $password));
|
2008-04-26 08:31:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $valid;
|
|
|
|
}
|
2008-04-26 08:32:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tell this member that someone made a failed attempt at logging in as them.
|
|
|
|
* This can be used to lock the user out temporarily if too many failed attempts are made.
|
|
|
|
*/
|
|
|
|
function registerFailedLogin() {
|
|
|
|
if(self::$lock_out_after_incorrect_logins) {
|
|
|
|
// Keep a tally of the number of failed log-ins so that we can lock people out
|
|
|
|
$failedLogins = Session::get('Member.FailedLogins');
|
|
|
|
if(!isset($failedLogins[$this->Email])) $failedLogins[$this->Email] = 0;
|
|
|
|
$failedLogins[$this->Email]++;
|
|
|
|
Session::set('Member.FailedLogins', $failedLogins);
|
|
|
|
|
|
|
|
if($failedLogins[$this->Email] >= self::$lock_out_after_incorrect_logins) {
|
|
|
|
$this->LockedOutUntil = date('Y-m-d H:i:s', time() + 15*60);
|
|
|
|
$this->write();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-14 21:10:18 +02:00
|
|
|
* Special kind of {@link ComponentSet} that has special methods for
|
|
|
|
* manipulating a user's membership
|
2008-02-25 03:10:37 +01:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage security
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class Member_GroupSet extends ComponentSet {
|
|
|
|
/**
|
2007-09-14 20:23:28 +02:00
|
|
|
* Control group membership with a number of checkboxes.
|
2007-09-14 21:10:18 +02:00
|
|
|
* - If the checkbox fields are present in $data, then the member will be
|
|
|
|
* added to the group with the same codename.
|
|
|
|
* - If the checkbox fields are *NOT* present in $data, then the member
|
|
|
|
* will be removed from the group with the same codename.
|
|
|
|
*
|
|
|
|
* @param array $checkboxes An array list of the checkbox fieldnames (only
|
|
|
|
* values are used). E.g. array(0, 1, 2)
|
|
|
|
* @param array $data The form data. Uually in the format array(0 => 2)
|
|
|
|
* (just pass the checkbox data from your form)
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2007-09-14 21:10:18 +02:00
|
|
|
function setByCheckboxes(array $checkboxes, array $data) {
|
2007-07-19 12:40:28 +02:00
|
|
|
foreach($checkboxes as $checkbox) {
|
2007-09-14 21:10:18 +02:00
|
|
|
if($data[$checkbox]) {
|
2007-09-14 20:23:28 +02:00
|
|
|
$add[] = $checkbox;
|
2007-09-14 21:10:18 +02:00
|
|
|
} else {
|
2007-07-19 12:40:28 +02:00
|
|
|
$remove[] = $checkbox;
|
2007-09-14 20:23:28 +02:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
if($add)
|
|
|
|
$this->addManyByCodename($add);
|
|
|
|
|
|
|
|
if($remove)
|
|
|
|
$this->removeManyByCodename($remove);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-14 21:10:18 +02:00
|
|
|
* Allows you to set groups based on a CheckboxSetField
|
2007-09-14 20:23:28 +02:00
|
|
|
*
|
2007-09-14 21:10:18 +02:00
|
|
|
* Pass the form element from your post data directly to this method, and
|
|
|
|
* it will update the groups and add and remove the member as appropriate.
|
2007-09-14 20:23:28 +02:00
|
|
|
*
|
2007-09-14 21:10:18 +02:00
|
|
|
* On the form setup:
|
2007-09-14 20:23:28 +02:00
|
|
|
*
|
2007-09-14 21:10:18 +02:00
|
|
|
* <code>
|
|
|
|
* $fields->push(
|
|
|
|
* new CheckboxSetField(
|
|
|
|
* "NewsletterSubscriptions",
|
|
|
|
* "Receive email notification of events in ",
|
|
|
|
* $sourceitems = DataObject::get("NewsletterType")->toDropDownMap("GroupID","Title"),
|
|
|
|
* $selectedgroups = $member->Groups()->Map("ID","ID")
|
|
|
|
* )
|
|
|
|
* );
|
|
|
|
* </code>
|
2007-09-14 20:23:28 +02:00
|
|
|
*
|
|
|
|
* On the form handler:
|
|
|
|
*
|
2007-09-14 21:10:18 +02:00
|
|
|
* <code>
|
|
|
|
* $groups = $member->Groups();
|
|
|
|
* $checkboxfield = $form->Fields()->fieldByName("NewsletterSubscriptions");
|
|
|
|
* $groups->setByCheckboxSetField($checkboxfield);
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* @param CheckboxSetField $checkboxsetfield The CheckboxSetField (with
|
|
|
|
* data) from your form.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2007-09-14 21:10:18 +02:00
|
|
|
function setByCheckboxSetField(CheckboxSetField $checkboxsetfield) {
|
2007-09-14 20:23:28 +02:00
|
|
|
// Get the values from the formfield.
|
2007-07-19 12:40:28 +02:00
|
|
|
$values = $checkboxsetfield->Value();
|
|
|
|
$sourceItems = $checkboxsetfield->getSource();
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
if($sourceItems) {
|
2007-07-19 12:40:28 +02:00
|
|
|
// If (some) values are present, add and remove as necessary.
|
2007-09-14 21:10:18 +02:00
|
|
|
if($values) {
|
2007-07-19 12:40:28 +02:00
|
|
|
// update the groups based on the selections
|
2007-09-14 21:10:18 +02:00
|
|
|
foreach($sourceItems as $k => $item) {
|
|
|
|
if(in_array($k,$values)) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$add[] = $k;
|
2007-09-14 21:10:18 +02:00
|
|
|
} else {
|
2007-07-19 12:40:28 +02:00
|
|
|
$remove[] = $k;
|
2007-09-14 20:23:28 +02:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// else we should be removing all from the necessary groups.
|
2007-09-14 21:10:18 +02:00
|
|
|
} else {
|
2008-02-25 03:10:37 +01:00
|
|
|
$remove = array_keys($sourceItems);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
if($add)
|
|
|
|
$this->addManyByGroupID($add);
|
|
|
|
|
|
|
|
if($remove)
|
|
|
|
$this->RemoveManyByGroupID($remove);
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
} else {
|
|
|
|
USER_ERROR("Member::setByCheckboxSetField() - No source items could be found for checkboxsetfield " .
|
|
|
|
$checkboxsetfield->Name(), E_USER_WARNING);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-14 21:10:18 +02:00
|
|
|
* Adds this member to the groups based on the group IDs
|
|
|
|
*
|
|
|
|
* @param array $ids Group identifiers.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
function addManyByGroupID($groupIds){
|
|
|
|
$groups = $this->getGroupsFromIDs($groupIds);
|
2007-09-14 21:10:18 +02:00
|
|
|
if($groups) {
|
|
|
|
foreach($groups as $group) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->add($group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-14 21:10:18 +02:00
|
|
|
* Removes the member from many groups based on the group IDs
|
|
|
|
*
|
|
|
|
* @param array $ids Group identifiers.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2007-09-14 21:10:18 +02:00
|
|
|
function removeManyByGroupID($groupIds) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$groups = $this->getGroupsFromIDs($groupIds);
|
2007-09-14 21:10:18 +02:00
|
|
|
if($groups) {
|
|
|
|
foreach($groups as $group) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->remove($group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-14 21:10:18 +02:00
|
|
|
* Returns the groups from an array of group IDs
|
|
|
|
*
|
|
|
|
* @param array $ids Group identifiers.
|
|
|
|
* @return mixed Returns the groups from the array of Group IDs.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
function getGroupsFromIDs($ids){
|
2007-09-14 21:10:18 +02:00
|
|
|
if($ids && count($ids) > 1) {
|
|
|
|
return DataObject::get("Group", "ID IN (" . implode(",", $ids) . ")");
|
|
|
|
} else {
|
|
|
|
return DataObject::get_by_id("Group", $ids[0]);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-14 21:10:18 +02:00
|
|
|
* Adds this member to the groups based on the group codenames
|
|
|
|
*
|
|
|
|
* @param array $codenames Group codenames
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
function addManyByCodename($codenames) {
|
|
|
|
$groups = $this->codenamesToGroups($codenames);
|
2007-09-14 21:10:18 +02:00
|
|
|
if($groups) {
|
2007-07-19 12:40:28 +02:00
|
|
|
foreach($groups as $group){
|
|
|
|
$this->add($group);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-14 21:10:18 +02:00
|
|
|
* Removes this member from the groups based on the group codenames
|
|
|
|
*
|
|
|
|
* @param array $codenames Group codenames
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
function removeManyByCodename($codenames) {
|
|
|
|
$groups = $this->codenamesToGroups($codenames);
|
2007-09-14 21:10:18 +02:00
|
|
|
if($groups) {
|
|
|
|
foreach($groups as $group) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$this->remove($group);
|
2007-09-14 20:23:28 +02:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2007-09-14 21:10:18 +02:00
|
|
|
* Helper function to return the appropriate groups via a codenames
|
|
|
|
*
|
|
|
|
* @param array $codenames Group codenames
|
|
|
|
* @return array Returns the the appropriate groups.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
protected function codenamesToGroups($codenames) {
|
|
|
|
$list = "'" . implode("', '", $codenames) . "'";
|
|
|
|
$output = DataObject::get("Group", "Code IN ($list)");
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// Some are missing - throw warnings
|
2007-09-14 21:10:18 +02:00
|
|
|
if(!$output || ($output->Count() != sizeof($list))) {
|
|
|
|
foreach($codenames as $codename)
|
|
|
|
$missing[$codename] = $codename;
|
|
|
|
|
|
|
|
if($output) {
|
|
|
|
foreach($output as $record)
|
|
|
|
unset($missing[$record->Code]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($missing)
|
|
|
|
user_error("The following group-codes aren't matched to any groups: " .
|
|
|
|
implode(", ", $missing) .
|
|
|
|
". You probably need to link up the correct group codes in phpMyAdmin",
|
|
|
|
E_USER_WARNING);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
|
|
|
* Form for editing a member profile.
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage security
|
|
|
|
*/
|
2007-09-27 23:16:23 +02:00
|
|
|
class Member_ProfileForm extends Form {
|
|
|
|
|
|
|
|
function __construct($controller, $name, $member) {
|
|
|
|
Requirements::clear();
|
|
|
|
Requirements::css('jsparty/tabstrip/tabstrip.css');
|
2007-11-02 04:01:40 +01:00
|
|
|
Requirements::css('cms/css/typography.css');
|
2007-09-28 01:06:15 +02:00
|
|
|
Requirements::css('cms/css/cms_right.css');
|
2007-09-27 23:16:23 +02:00
|
|
|
Requirements::javascript("jsparty/prototype.js");
|
|
|
|
Requirements::javascript("jsparty/behaviour.js");
|
|
|
|
Requirements::javascript("jsparty/prototype_improvements.js");
|
|
|
|
Requirements::javascript("jsparty/loader.js");
|
|
|
|
Requirements::javascript("jsparty/tabstrip/tabstrip.js");
|
|
|
|
Requirements::javascript("jsparty/scriptaculous/scriptaculous.js");
|
|
|
|
Requirements::javascript("jsparty/scriptaculous/controls.js");
|
|
|
|
Requirements::javascript("jsparty/layout_helpers.js");
|
|
|
|
Requirements::css("sapphire/css/Form.css");
|
|
|
|
|
2007-09-28 01:06:15 +02:00
|
|
|
Requirements::css("sapphire/css/MemberProfileForm.css");
|
|
|
|
|
2007-09-27 23:16:23 +02:00
|
|
|
|
|
|
|
$fields = singleton('Member')->getCMSFields();
|
|
|
|
$fields->push(new HiddenField('ID','ID',$member->ID));
|
|
|
|
|
|
|
|
$actions = new FieldSet(
|
|
|
|
new FormAction('dosave',_t('CMSMain.SAVE'))
|
|
|
|
);
|
|
|
|
|
|
|
|
$validator = new RequiredFields(
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
parent::__construct($controller, $name, $fields, $actions, $validator);
|
|
|
|
|
|
|
|
$this->loadDataFrom($member);
|
|
|
|
}
|
|
|
|
|
|
|
|
function dosave($data, $form) {
|
|
|
|
$SQL_data = Convert::raw2sql($data);
|
|
|
|
|
|
|
|
$member = DataObject::get_by_id("Member", $SQL_data['ID']);
|
|
|
|
|
2007-10-21 21:53:57 +02:00
|
|
|
if($SQL_data['Locale'] != $member->Locale) {
|
|
|
|
$form->addErrorMessage("Generic", _t('Member.REFRESHLANG'),"good");
|
2007-09-27 23:16:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$form->saveInto($member);
|
|
|
|
$member->write();
|
|
|
|
|
|
|
|
Director::redirectBack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
/**
|
|
|
|
* Class used as template to send an email to new members
|
2008-02-25 03:10:37 +01:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage security
|
2007-09-14 21:10:18 +02:00
|
|
|
*/
|
2008-06-12 11:29:05 +02:00
|
|
|
class Member_SignupEmail extends Email {
|
2007-10-25 04:47:45 +02:00
|
|
|
protected $from = ''; // setting a blank from address uses the site's default administrator email
|
|
|
|
protected $to = '$Email';
|
|
|
|
protected $subject = '';
|
|
|
|
protected $body = '';
|
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
$this->subject = _t('Member.EMAILSIGNUPSUBJECT', "Thanks for signing up");
|
|
|
|
$this->body = '
|
2007-11-06 06:42:28 +01:00
|
|
|
<h1>' . _t('Member.GREETING','Welcome') . ', $FirstName.</h1>
|
2007-10-25 04:47:45 +02:00
|
|
|
<p>' . _t('Member.EMAILSIGNUPINTRO1','Thanks for signing up to become a new member, your details are listed below for future reference.') . '</p>
|
|
|
|
|
|
|
|
<p>' . _t('Member.EMAILSIGNUPINTRO2','You can login to the website using the credentials listed below') . ':
|
2007-07-19 12:40:28 +02:00
|
|
|
<ul>
|
2007-10-25 04:47:45 +02:00
|
|
|
<li><strong>' . _t('Member.EMAIL') . '</strong>$Email</li>
|
|
|
|
<li><strong>' . _t('Member.PASSWORD') . ':</strong>$Password</li>
|
2007-07-19 12:40:28 +02:00
|
|
|
</ul>
|
|
|
|
</p>
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-10-25 04:47:45 +02:00
|
|
|
<h3>' . _t('Member.CONTACTINFO','Contact Information') . '</h3>
|
2007-07-19 12:40:28 +02:00
|
|
|
<ul>
|
2007-10-25 04:47:45 +02:00
|
|
|
<li><strong>' . _t('Member.NAME','Name') . ':</strong> $FirstName $Surname</li>
|
2007-07-19 12:40:28 +02:00
|
|
|
<% if Phone %>
|
2007-10-25 04:47:45 +02:00
|
|
|
<li><strong>' . _t('Member.PHONE','Phone') . ':</strong> $Phone</li>
|
2007-07-19 12:40:28 +02:00
|
|
|
<% end_if %>
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
<% if Mobile %>
|
2007-10-25 04:47:45 +02:00
|
|
|
<li><strong>' . _t('Member.MOBILE','Mobile') . ':</strong> $Mobile</li>
|
2007-07-19 12:40:28 +02:00
|
|
|
<% end_if %>
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-10-25 04:47:45 +02:00
|
|
|
<li><strong>' . _t('Member.ADDRESS','Address') . ':</strong>
|
|
|
|
<br/>
|
|
|
|
$Number $Street $StreetType<br/>
|
|
|
|
$Suburb<br/>
|
|
|
|
$City $Postcode
|
|
|
|
</li>
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-10-25 04:47:45 +02:00
|
|
|
</ul>
|
|
|
|
';
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
function MemberData() {
|
|
|
|
return $this->template_data->listOfFields(
|
2007-09-14 21:10:18 +02:00
|
|
|
"FirstName", "Surname", "Email",
|
|
|
|
"Phone", "Mobile", "Street",
|
2007-09-21 02:07:15 +02:00
|
|
|
"Suburb", "City", "Postcode"
|
2007-07-19 12:40:28 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class used as template to send an email saying that the password has been
|
|
|
|
* changed
|
2008-02-25 03:10:37 +01:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage security
|
2007-09-14 21:10:18 +02:00
|
|
|
*/
|
2008-06-12 11:29:05 +02:00
|
|
|
class Member_ChangePasswordEmail extends Email {
|
2007-07-19 12:40:28 +02:00
|
|
|
protected $from = ''; // setting a blank from address uses the site's default administrator email
|
2007-10-25 04:47:45 +02:00
|
|
|
protected $subject = '';
|
2007-07-19 12:40:28 +02:00
|
|
|
protected $ss_template = 'ChangePasswordEmail';
|
2007-09-14 20:23:28 +02:00
|
|
|
protected $to = '$Email';
|
2007-10-25 04:47:45 +02:00
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
$this->subject = _t('Member.SUBJECTPASSWORDCHANGED', "Your password has been changed", PR_MEDIUM, 'Email subject');
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class used as template to send the forgot password email
|
2008-02-25 03:10:37 +01:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage security
|
2007-09-14 21:10:18 +02:00
|
|
|
*/
|
2008-06-12 11:29:05 +02:00
|
|
|
class Member_ForgotPasswordEmail extends Email {
|
2007-09-14 21:10:18 +02:00
|
|
|
protected $from = ''; // setting a blank from address uses the site's default administrator email
|
2007-10-25 04:47:45 +02:00
|
|
|
protected $subject = '';
|
2007-07-19 12:40:28 +02:00
|
|
|
protected $ss_template = 'ForgotPasswordEmail';
|
2007-09-14 20:23:28 +02:00
|
|
|
protected $to = '$Email';
|
2007-10-25 04:47:45 +02:00
|
|
|
|
|
|
|
function __construct() {
|
|
|
|
$this->subject = _t('Member.SUBJECTPASSWORDRESET', "Your password reset link", PR_MEDIUM, 'Email subject');
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2008-02-25 03:10:37 +01:00
|
|
|
* Record to keep track of which records a member has unsubscribed from and when.
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage security
|
2007-09-14 21:10:18 +02:00
|
|
|
* @todo Check if that email stuff ($from, $to, $subject, $body) is needed
|
|
|
|
* here! (Markus)
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
class Member_UnsubscribeRecord extends DataObject {
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
static $has_one = array(
|
|
|
|
'NewsletterType' => 'NewsletterType',
|
|
|
|
'Member' => 'Member'
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unsubscribe the member from a specific newsletter type
|
|
|
|
*
|
|
|
|
* @param int|Member $member Member object or ID
|
|
|
|
* @param int|NewsletterType $newsletterType Newsletter type object or ID
|
|
|
|
*/
|
|
|
|
function unsubscribe($member, $newsletterType) {
|
|
|
|
// $this->UnsubscribeDate()->setVal( 'now' );
|
|
|
|
$this->MemberID = (is_numeric($member))
|
|
|
|
? $member
|
|
|
|
: $member->ID;
|
|
|
|
|
2007-09-21 02:07:15 +02:00
|
|
|
$this->NewsletterTypeID = (is_numeric($newsletterType))
|
2007-09-14 21:10:18 +02:00
|
|
|
? $newsletterType
|
|
|
|
: $newsletterType->ID;
|
|
|
|
|
|
|
|
$this->write();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-14 20:23:28 +02:00
|
|
|
protected
|
2007-09-14 21:10:18 +02:00
|
|
|
$from = '', // setting a blank from address uses the site's default administrator email
|
2007-07-19 12:40:28 +02:00
|
|
|
$to = '$Email',
|
2007-10-25 04:47:45 +02:00
|
|
|
$subject = '',
|
|
|
|
$body = '';
|
|
|
|
|
2007-10-25 05:00:33 +02:00
|
|
|
function __construct($record = null, $isSingleton = false) {
|
2007-10-25 04:47:45 +02:00
|
|
|
$this->subject = _t('Member.SUBJECTPASSWORDCHANGED');
|
|
|
|
|
|
|
|
$this->body = '
|
|
|
|
<h1>' . _t('Member.EMAILPASSWORDINTRO', "Here's your new password") . '</h1>
|
|
|
|
<p>
|
|
|
|
<strong>' . _t('Member.EMAIL') . ':</strong> $Email<br />
|
|
|
|
<strong>' . _t('Member.PASSWORD') . ':</strong> $Password
|
|
|
|
</p>
|
|
|
|
<p>' . _t('Member.EMAILPASSWORDAPPENDIX', 'Your password has been changed. Please keep this email, for future reference.') . '</p>';
|
2007-10-25 05:00:33 +02:00
|
|
|
|
|
|
|
parent::__construct($record, $isSingleton);
|
2007-10-25 04:47:45 +02:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Member Validator
|
2008-02-25 03:10:37 +01:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage security
|
2007-09-14 21:10:18 +02:00
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
class Member_Validator extends RequiredFields {
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
protected $customRequired = array('FirstName', 'Email'); //, 'Password');
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
public function __construct() {
|
|
|
|
$required = func_get_args();
|
|
|
|
if(isset($required[0]) && is_array($required[0])) {
|
|
|
|
$required = $required[0];
|
|
|
|
}
|
|
|
|
$required = array_merge($required, $this->customRequired);
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
parent::__construct($required);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
/**
|
2007-09-16 18:55:47 +02:00
|
|
|
* Check if the submitted member data is valid (server-side)
|
2007-09-14 21:10:18 +02:00
|
|
|
*
|
|
|
|
* Check if a member with that email doesn't already exist, or if it does
|
|
|
|
* that it is this member.
|
|
|
|
*
|
|
|
|
* @param array $data Submitted data
|
|
|
|
* @return bool Returns TRUE if the submitted data is valid, otherwise
|
|
|
|
* FALSE.
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
function php($data) {
|
|
|
|
$valid = parent::php($data);
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
$member = DataObject::get_one('Member',
|
|
|
|
"Email = '". Convert::raw2sql($data['Email']) ."'");
|
|
|
|
|
|
|
|
// if we are in a complex table field popup, use ctf[childID], else use
|
|
|
|
// ID
|
2008-02-25 03:10:37 +01:00
|
|
|
if(isset($_REQUEST['ctf']['childID']))
|
|
|
|
$id = $_REQUEST['ctf']['childID'];
|
|
|
|
elseif(isset($_REQUEST['ID']))
|
|
|
|
$id = $_REQUEST['ID'];
|
|
|
|
else
|
|
|
|
$id = null;
|
|
|
|
|
|
|
|
if($id && is_object($member) && $member->ID != $id) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$emailField = $this->form->dataFieldByName('Email');
|
2007-09-14 21:10:18 +02:00
|
|
|
$this->validationError($emailField->id(),
|
2007-10-25 04:47:45 +02:00
|
|
|
_t('Member.VALIDATIONMEMBEREXISTS', "There already exists a member with this email"),
|
|
|
|
"required");
|
2007-07-19 12:40:28 +02:00
|
|
|
$valid = false;
|
|
|
|
}
|
2007-09-14 20:23:28 +02:00
|
|
|
|
2007-09-16 18:55:47 +02:00
|
|
|
|
|
|
|
// Execute the validators on the extensions
|
|
|
|
if($this->extension_instances) {
|
|
|
|
foreach($this->extension_instances as $extension) {
|
|
|
|
if($extension->hasMethod('updatePHP')) {
|
|
|
|
$valid &= $extension->updatePHP($data, $this->form);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return $valid;
|
|
|
|
}
|
2007-09-16 18:55:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the submitted member data is valid (client-side)
|
|
|
|
*
|
|
|
|
* @param array $data Submitted data
|
|
|
|
* @return bool Returns TRUE if the submitted data is valid, otherwise
|
|
|
|
* FALSE.
|
|
|
|
*/
|
|
|
|
function javascript() {
|
|
|
|
$js = parent::javascript();
|
|
|
|
|
|
|
|
// Execute the validators on the extensions
|
|
|
|
if($this->extension_instances) {
|
|
|
|
foreach($this->extension_instances as $extension) {
|
|
|
|
if($extension->hasMethod('updateJavascript')) {
|
|
|
|
$extension->updateJavascript($js, $this->form);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $js;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2007-09-15 23:51:37 +02:00
|
|
|
// Initialize the static DB variables to add the supported encryption
|
|
|
|
// algorithms to the PasswordEncryption Enum field
|
|
|
|
Member::init_db_fields();
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2007-11-05 04:04:58 +01:00
|
|
|
?>
|