Welcome to SS
here we go.
in your _config.php add the following lines
Object::useCustomClass('MemberLoginForm', 'CustomLogin');
//Tells silverstripe to add our extention to the group class
Object::add_extension('Group', 'GroupDecorator');
create a page called CustomLogin.php and paste the code below which will do all the work for you.
<?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))
Director::redirect(Director::baseURL());
//echo 'done';
} else {
if($badLoginURL = Session::get("BadLoginURL")) {
Director::redirect($badLoginURL);
} else {
Director::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
Director::redirect(Director::baseURL() . '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->LinkPageID != 0)
{
//Get the page that is referenced in the group
$Link = DataObject::get_by_id("SiteTree", "{$Group->LinkPageID}")->URLSegment;
//direct to that page
Director::redirect(Director::baseURL() . $Link);
return true;
}
}
//otherwise if none of the above worked return fase
return false;
}
}
?>
after you have rebuild the db you will notice that for each group you will create, you have to apecify whether it access the admin area by checking admin area or specify a page to be redirected to. failure to specify where to take that group will result in nothing happening after log in.
create CustomerPage.php and change the access level to Login users
Under security create a secondary Users called Customers and specify the redirect page to be the newly created customers page.
So now you will be having Administrators and Customers.
yell if problems
ta
PAt