Hi Everyone
Well I am having a complete nightmare with the Member system and creating a custom login page, who knew it would be nearly impossible to work with and without proper documentation anywhere!
I am simply trying to build a login page for members that have a certain Boolean checked, and then redirect them to a different page. However I am suffering barriers in all directions.
The current ones are:
1. [Strict Notice] Non-static method Controller::redirect() should not be called statically, assuming $this from incompatible context
2. When clicking the logout button it takes me no a white screen
CustomLogin .php
<?php
class CustomLogin extends MemberLoginForm {
// this function is overloaded on our sublcass (this) to do something different
public function dologin($data) {
if($this->performLogin($data)) {
if(!$this->redirectByGroup($data)){
return Controller::redirect("/home");
//echo 'done';
}
} else {
if($badLoginURL = Session::get("BadLoginURL")) {
return Controller::redirect($badLoginURL);
} else {
return Controller::redirectBack();
}
}
}
public function redirectByGroup($data) {
// gets the current member that is logging in.
$member = Member::currentUser();
// gets all the groups.
$Groups = DataObject::get("Group");
//cycle through each group
foreach($Groups as $Group){
//if the member is in the group and that group has GoToAdmin checked
if($member->inGroup($Group->ID) && $Group->GoToAdmin == 1)
{
//redirect to the admin page
return Controller::redirect('/admin');
return true;
}
//otherwise if the member is in the group and that group has a page link defined
elseif($member->inGroup($Group->ID) && $Group->GoToMemberProfile == 1)
{
Controller::redirect('/members/profile');
return true;
}
}
//otherwise if none of the above worked return fase
return false;
}
}
?>
GroupDecorator.php
<?php
class GroupDecorator extends DataExtension {
static $db = array (
"GoToAdmin" => "Boolean",
"GoToMemberProfile" => "Boolean"
);
private static $has_one = array(
);
function updateCMSFields(FieldList $fields) {
$fields->push(new CheckboxField("GoToAdmin", " Go to Admin area"), "Members");
$fields->push(new CheckboxField("GoToMemberProfile", " Go to Member area"), "Members");
}
}
_config.php
Object::useCustomClass('MemberLoginForm', 'CustomLogin');
//Tells silverstripe to add our extention to the group class
Object::add_extension('Group', 'GroupDecorator');
MemberLoginPage.php
...
class MemberLoginPage_Controller extends Page_Controller {
private static $allowed_actions = array (
"LoginForm"
);
function LoginForm() {
$form = new CustomLogin($this,"LoginForm");
// print_r($_REQUEST);
return $form;
}
}
Any help will be great. I have looked at the SSBits tutorial, I have tried the member profiles extension on GitHub, read hours of documentation and nothing is giving in!
Thanks