2007-09-14 05:12:21 +02:00
|
|
|
<?php
|
2007-09-14 21:10:18 +02:00
|
|
|
|
|
|
|
/**
|
2008-02-25 02:06:39 +01:00
|
|
|
* Log-in form for the "member" authentication method
|
2007-09-14 21:10:18 +02:00
|
|
|
*/
|
|
|
|
|
2008-02-25 02:06:39 +01:00
|
|
|
|
|
|
|
|
2007-09-14 05:12:21 +02:00
|
|
|
/**
|
|
|
|
* Log-in form for the "member" authentication method
|
|
|
|
*/
|
2007-09-14 21:13:12 +02:00
|
|
|
class MemberLoginForm extends LoginForm {
|
2007-09-14 19:04:11 +02:00
|
|
|
|
2007-09-14 05:12:21 +02:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2007-09-14 21:10:18 +02:00
|
|
|
* @param Controller $controller The parent controller, necessary to
|
|
|
|
* create the appropriate form action tag.
|
|
|
|
* @param string $name The method on the controller that will return this
|
|
|
|
* form object.
|
|
|
|
* @param FieldSet|FormField $fields All of the fields in the form - a
|
|
|
|
* {@link FieldSet} of {@link FormField}
|
|
|
|
* objects.
|
|
|
|
* @param FieldSet|FormAction $actions All of the action buttons in the
|
|
|
|
* form - a {@link FieldSet} of
|
|
|
|
* {@link FormAction} objects
|
|
|
|
* @param bool $checkCurrentUser If set to TRUE, it will be checked if a
|
|
|
|
* the user is currently logged in, and if
|
|
|
|
* so, only a logout button will be rendered
|
2007-09-14 05:12:21 +02:00
|
|
|
*/
|
2007-09-14 21:10:18 +02:00
|
|
|
function __construct($controller, $name, $fields = null, $actions = null,
|
|
|
|
$checkCurrentUser = true) {
|
2007-09-14 05:12:21 +02:00
|
|
|
|
2007-09-15 02:08:23 +02:00
|
|
|
$this->authenticator_class = 'MemberAuthenticator';
|
|
|
|
|
2007-09-14 05:12:21 +02:00
|
|
|
$customCSS = project() . '/css/member_login.css';
|
|
|
|
if(Director::fileExists($customCSS)) {
|
|
|
|
Requirements::css($customCSS);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($_REQUEST['BackURL'])) {
|
|
|
|
$backURL = $_REQUEST['BackURL'];
|
|
|
|
} else {
|
|
|
|
$backURL = Session::get('BackURL');
|
|
|
|
}
|
|
|
|
|
|
|
|
if($checkCurrentUser && Member::currentUserID()) {
|
|
|
|
$fields = new FieldSet();
|
2007-10-25 04:47:45 +02:00
|
|
|
$actions = new FieldSet(new FormAction("logout", _t('Member.BUTTONLOGINOTHER', "Log in as someone else")));
|
2007-09-14 05:12:21 +02:00
|
|
|
} else {
|
|
|
|
if(!$fields) {
|
|
|
|
$fields = new FieldSet(
|
2007-10-25 04:47:45 +02:00
|
|
|
new HiddenField("AuthenticationMethod", null, $this->authenticator_class, $this),
|
|
|
|
new TextField("Email", _t('Member.EMAIL'),
|
2007-09-14 21:13:12 +02:00
|
|
|
Session::get('SessionForms.MemberLoginForm.Email'), null, $this),
|
2007-10-25 04:47:45 +02:00
|
|
|
new EncryptField("Password", _t('Member.PASSWORD'), null, $this),
|
|
|
|
new CheckboxField("Remember", _t('Member.REMEMBERME', "Remember me next time?"),
|
2007-09-14 21:13:12 +02:00
|
|
|
Session::get('SessionForms.MemberLoginForm.Remember'), $this)
|
2007-09-14 05:12:21 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
if(!$actions) {
|
|
|
|
$actions = new FieldSet(
|
2007-10-25 04:47:45 +02:00
|
|
|
new FormAction("dologin", _t('Member.BUTTONLOGIN', "Log in")),
|
|
|
|
new FormAction("forgotPassword", _t('Member.BUTTONLOSTPASSWORD', "I've lost my password"))
|
2007-09-14 05:12:21 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($backURL)) {
|
|
|
|
$fields->push(new HiddenField('BackURL', 'BackURL', $backURL));
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::__construct($controller, $name, $fields, $actions);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get message from session
|
|
|
|
*/
|
|
|
|
protected function getMessageFromSession() {
|
|
|
|
parent::getMessageFromSession();
|
2007-09-14 21:10:18 +02:00
|
|
|
if(($member = Member::currentUser()) &&
|
|
|
|
!Session::get('MemberLoginForm.force_message')) {
|
2007-10-25 04:47:45 +02:00
|
|
|
$this->message = sprintf(_t('Member.LOGGEDINAS', "You're logged in as %s."), $member->FirstName);
|
2007-09-14 05:12:21 +02:00
|
|
|
}
|
|
|
|
Session::set('MemberLoginForm.force_message', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Login form handler method
|
|
|
|
*
|
|
|
|
* This method is called when the user clicks on "Log in"
|
|
|
|
*
|
|
|
|
* @param array $data Submitted data
|
|
|
|
*/
|
|
|
|
public function dologin($data) {
|
2007-09-14 21:10:18 +02:00
|
|
|
if($this->performLogin($data)) {
|
|
|
|
Session::clear('SessionForms.MemberLoginForm.Email');
|
|
|
|
Session::clear('SessionForms.MemberLoginForm.Remember');
|
2007-09-14 05:12:21 +02:00
|
|
|
|
2008-02-25 02:06:39 +01:00
|
|
|
if($backURL = $_REQUEST['BackURL']) {
|
2007-09-14 05:12:21 +02:00
|
|
|
Session::clear("BackURL");
|
|
|
|
Director::redirect($backURL);
|
2007-11-04 22:30:57 +01:00
|
|
|
} else {
|
2008-02-25 02:06:39 +01:00
|
|
|
Director::redirectBack();
|
2007-11-04 22:30:57 +01:00
|
|
|
}
|
2007-09-14 18:57:12 +02:00
|
|
|
} else {
|
|
|
|
Session::set('SessionForms.MemberLoginForm.Email', $data['Email']);
|
2008-02-25 02:06:39 +01:00
|
|
|
Session::set('SessionForms.MemberLoginForm.Remember', isset($data['Remember']));
|
|
|
|
|
|
|
|
if(isset($_REQUEST['BackURL']) && $backURL = $_REQUEST['BackURL']) {
|
|
|
|
Session::set('BackURL', $backURL);
|
|
|
|
}
|
2007-11-04 22:30:57 +01:00
|
|
|
|
2007-09-14 21:10:18 +02:00
|
|
|
if($badLoginURL = Session::get("BadLoginURL")) {
|
2007-09-14 05:12:21 +02:00
|
|
|
Director::redirect($badLoginURL);
|
2007-09-14 18:57:12 +02:00
|
|
|
} else {
|
2007-09-15 22:00:00 +02:00
|
|
|
// Show the right tab on failed login
|
|
|
|
Director::redirect(Director::absoluteURL(Security::Link("login")) .
|
|
|
|
'#' . $this->FormName() .'_tab');
|
2007-09-14 05:12:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2007-09-14 21:10:18 +02:00
|
|
|
* Log out form handler method
|
2007-09-14 05:12:21 +02:00
|
|
|
*
|
2007-09-14 21:10:18 +02:00
|
|
|
* This method is called when the user clicks on "logout" on the form
|
|
|
|
* created when the parameter <i>$checkCurrentUser</i> of the
|
|
|
|
* {@link __construct constructor} was set to TRUE and the user was
|
|
|
|
* currently logged in.
|
2007-09-14 05:12:21 +02:00
|
|
|
*/
|
2007-09-14 21:10:18 +02:00
|
|
|
public function logout() {
|
2007-09-14 05:12:21 +02:00
|
|
|
$s = new Security();
|
2007-09-14 21:10:18 +02:00
|
|
|
$s->logout();
|
2007-09-14 05:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-14 19:04:11 +02:00
|
|
|
/**
|
|
|
|
* Try to authenticate the user
|
|
|
|
*
|
|
|
|
* @param array Submitted data
|
|
|
|
* @return Member Returns the member object on successful authentication
|
|
|
|
* or NULL on failure.
|
|
|
|
*/
|
2007-09-14 21:10:18 +02:00
|
|
|
public function performLogin($data) {
|
|
|
|
if($member = MemberAuthenticator::authenticate($data, $this)) {
|
2007-09-14 05:12:21 +02:00
|
|
|
$firstname = Convert::raw2xml($member->FirstName);
|
2007-10-25 04:47:45 +02:00
|
|
|
Session::set("Security.Message.message",
|
|
|
|
sprintf(_t('Member.WELCOMEBACK', "Welcome Back, %s"), $firstname)
|
|
|
|
);
|
2007-09-14 21:10:18 +02:00
|
|
|
Session::set("Security.Message.type", "good");
|
|
|
|
|
|
|
|
$member->LogIn(isset($data['Remember']));
|
2007-09-14 05:12:21 +02:00
|
|
|
return $member;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Forgot password form handler method
|
|
|
|
*
|
2007-09-14 21:10:18 +02:00
|
|
|
* This method is called when the user clicks on "I've lost my password"
|
2007-09-14 05:12:21 +02:00
|
|
|
*
|
|
|
|
* @param array $data Submitted data
|
|
|
|
*/
|
|
|
|
function forgotPassword($data) {
|
|
|
|
$SQL_data = Convert::raw2sql($data);
|
2007-09-14 21:10:18 +02:00
|
|
|
|
2007-09-16 02:32:48 +02:00
|
|
|
if(($data['Email']) && ($member = DataObject::get_one("Member",
|
|
|
|
"Member.Email = '$SQL_data[Email]'"))) {
|
|
|
|
|
|
|
|
$member->generateAutologinHash();
|
|
|
|
|
|
|
|
$member->sendInfo('forgotPassword', array('PasswordResetLink' =>
|
|
|
|
Security::getPasswordResetLink($member->AutoLoginHash)));
|
2007-09-14 05:12:21 +02:00
|
|
|
|
|
|
|
Director::redirect('Security/passwordsent/' . urlencode($data['Email']));
|
|
|
|
|
|
|
|
} else if($data['Email']) {
|
2007-09-14 21:10:18 +02:00
|
|
|
$this->sessionMessage(
|
2007-10-25 04:47:45 +02:00
|
|
|
_t('Member.ERRORSIGNUP', "Sorry, but I don't recognise the e-mail address. Maybe you need " .
|
|
|
|
"to sign up, or perhaps you used another e-mail address?"),
|
2007-09-14 21:10:18 +02:00
|
|
|
"bad");
|
2007-09-14 05:12:21 +02:00
|
|
|
Director::redirectBack();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Director::redirect("Security/lostpassword");
|
|
|
|
}
|
|
|
|
}
|
2007-09-14 21:13:12 +02:00
|
|
|
|
2007-09-14 05:12:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-25 02:06:39 +01:00
|
|
|
?>
|