Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Client/ Admin log-in, but with register form?


Go to End


1129 Views

Avatar
borriej

Community Member, 267 Posts

24 December 2010 at 1:29am

Edited: 24/12/2010 1:31am

Hello,

I've extended the CMS with Client's being able to log-in:

config:

Object::add_extension('Group', 'GroupDecorator');
Object::useCustomClass('MemberLoginForm', 'CustomLoginForm');

GroupDecorator:

<?php
   class GroupDecorator extends DataObjectDecorator {
   	
	function augmentSQL(SQLQuery &$query) {}
	
	public function extraStatics(){
		
		return array(
			'db' => array(
				"GoToAdmin" => "Boolean"
			),
			'has_one' => array(
				"LinkPage" => "SiteTree"
			),
		);

	}	

	public function updateCMSFields(FieldSet &$fields) {
	   $fields->addFieldToTab("Root.Members", new CheckboxField("GoToAdmin", " Go to Admin area"), 'Members');
	   $fields->addFieldToTab("Root.Members", new TreeDropdownField("LinkPageID", "Or select a Page to redirect to", "SiteTree"), 'Members');
	}

}

CustomLoginForm

<?php

class CustomLoginForm 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;
				
	}
					
	
}	 


?>

This all works offcourse.. but it would be great if people could register on the website with a registration form.

People are not supposed to gain immediate acces -> the admin must activate their accounts first.
My idea is that they simply click activate in the CMS.

At the moment i have a separate register form, but the admin must retype all forms in the cms access panel.

How would I do this?

Thx!