Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
helpfulrobot
committed
Dec 31, 2015
1 parent
fd272b8
commit 3c8ffbf
Showing
4 changed files
with
226 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,93 @@ | ||
<?php | ||
|
||
class EditProfilePage extends Page | ||
{ | ||
} | ||
|
||
class EditProfilePage_Controller extends Page_Controller | ||
{ | ||
static $allowed_actions = array( | ||
'EditProfileForm' | ||
); | ||
|
||
function EditProfileForm() | ||
{ | ||
//Create our fields | ||
$fields = new FieldList( | ||
new TextField('FirstName', '<span>*</span> Firstname'), | ||
new TextField('Surname', '<span>*</span> Surname'), | ||
new EmailField('Email', '<span>*</span> Email'), | ||
new TextField('JobTitle', 'Job Title'), | ||
new TextField('Website', 'Website (Without http://)'), | ||
new TextareaField('Blurb'), | ||
new ConfirmedPasswordField('Password', 'New Password') | ||
); | ||
|
||
// Create action | ||
$actions = new FieldList( | ||
new FormAction('SaveProfile', 'Save') | ||
); | ||
|
||
// Create action | ||
$validator = new RequiredFields('FirstName', 'Email'); | ||
|
||
//Create form | ||
$Form = new Form($this, 'EditProfileForm', $fields, $actions, $validator); | ||
|
||
//Populate the form with the current members data | ||
$Member = Member::CurrentUser(); | ||
$Form->loadDataFrom($Member->data()); | ||
|
||
//Return the form | ||
return $Form; | ||
} | ||
|
||
//Save profile | ||
function SaveProfile($data, $form) | ||
{ | ||
//Check for a logged in member | ||
if($CurrentMember = Member::currentUser()) | ||
{ | ||
//Check for another member with the same email address | ||
if($member = DataObject::get_one("Member", "Email = '". Convert::raw2sql($data['Email']) . "' AND ID != " . $CurrentMember->ID)) | ||
{ | ||
//Set error message | ||
$form->sessionMessage($data['Email'].". Sorry, that email address already exists. Please choose another.", 'bad'); | ||
|
||
//Return back to form | ||
return $this->redirectBack(); | ||
//return Director::redirectBack(); | ||
} | ||
//Otherwise check that user IDs match and save | ||
else | ||
{ | ||
$form->saveInto($CurrentMember); | ||
|
||
$CurrentMember->write(); | ||
|
||
return $this->redirect($this->Link('?saved=1')); | ||
} | ||
} | ||
//If not logged in then return a permission error | ||
else | ||
{ | ||
return Security::PermissionFailure($this->controller, 'You must <a href="register">registered</a> and logged in to edit your profile:'); | ||
} | ||
} | ||
|
||
//Check for just saved | ||
function Saved() | ||
{ | ||
return $this->request->getVar('saved'); | ||
} | ||
|
||
/* | ||
//Check for success status | ||
function Success() | ||
{ | ||
return $this->request->getVar('success'); | ||
} | ||
*/ | ||
|
||
//Check for edit status | ||
function Edit(){ | ||
return $this->request->getVar('edit'); | ||
} | ||
|
||
|
||
} | ||
<?php | ||
|
||
class EditProfilePage extends Page | ||
{ | ||
} | ||
|
||
class EditProfilePage_Controller extends Page_Controller | ||
{ | ||
public static $allowed_actions = array( | ||
'EditProfileForm' | ||
); | ||
|
||
public function EditProfileForm() | ||
{ | ||
//Create our fields | ||
$fields = new FieldList( | ||
new TextField('FirstName', '<span>*</span> Firstname'), | ||
new TextField('Surname', '<span>*</span> Surname'), | ||
new EmailField('Email', '<span>*</span> Email'), | ||
new TextField('JobTitle', 'Job Title'), | ||
new TextField('Website', 'Website (Without http://)'), | ||
new TextareaField('Blurb'), | ||
new ConfirmedPasswordField('Password', 'New Password') | ||
); | ||
|
||
// Create action | ||
$actions = new FieldList( | ||
new FormAction('SaveProfile', 'Save') | ||
); | ||
|
||
// Create action | ||
$validator = new RequiredFields('FirstName', 'Email'); | ||
|
||
//Create form | ||
$Form = new Form($this, 'EditProfileForm', $fields, $actions, $validator); | ||
|
||
//Populate the form with the current members data | ||
$Member = Member::CurrentUser(); | ||
$Form->loadDataFrom($Member->data()); | ||
|
||
//Return the form | ||
return $Form; | ||
} | ||
|
||
//Save profile | ||
public function SaveProfile($data, $form) | ||
{ | ||
//Check for a logged in member | ||
if ($CurrentMember = Member::currentUser()) { | ||
//Check for another member with the same email address | ||
if ($member = DataObject::get_one("Member", "Email = '". Convert::raw2sql($data['Email']) . "' AND ID != " . $CurrentMember->ID)) { | ||
//Set error message | ||
$form->sessionMessage($data['Email'].". Sorry, that email address already exists. Please choose another.", 'bad'); | ||
|
||
//Return back to form | ||
return $this->redirectBack(); | ||
//return Director::redirectBack(); | ||
} | ||
//Otherwise check that user IDs match and save | ||
else { | ||
$form->saveInto($CurrentMember); | ||
|
||
$CurrentMember->write(); | ||
|
||
return $this->redirect($this->Link('?saved=1')); | ||
} | ||
} | ||
//If not logged in then return a permission error | ||
else { | ||
return Security::PermissionFailure($this->controller, 'You must <a href="register">registered</a> and logged in to edit your profile:'); | ||
} | ||
} | ||
|
||
//Check for just saved | ||
public function Saved() | ||
{ | ||
return $this->request->getVar('saved'); | ||
} | ||
|
||
/* | ||
//Check for success status | ||
function Success() | ||
{ | ||
return $this->request->getVar('success'); | ||
} | ||
*/ | ||
|
||
//Check for edit status | ||
public function Edit() | ||
{ | ||
return $this->request->getVar('edit'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
<?php | ||
class MemberDecorator extends DataExtension{ | ||
|
||
private static $db=array( | ||
"JobTitle" => 'Varchar', | ||
"Blurb" => "Text", | ||
"Website" => "Varchar(100)" | ||
); | ||
|
||
//Add form fields to CMS | ||
public function updateCMSFields(FieldList $fields) | ||
{ | ||
$fields->addFieldToTab("Root.Profile", new TextField('JobTitle', 'Job Title')); | ||
$fields->addFieldToTab("Root.Profile", new TextField('Website', 'Website', 'http://')); | ||
$fields->addFieldToTab("Root.Profile", new TextareaField('Blurb', 'Blurb')); | ||
} | ||
|
||
//Link to the edit profile page | ||
function Link() | ||
{ | ||
if($ProfilePage = DataObject::get_one('EditProfilePage')) | ||
{ | ||
return $ProfilePage->Link(); | ||
} | ||
} | ||
|
||
} | ||
<?php | ||
class MemberDecorator extends DataExtension | ||
{ | ||
|
||
private static $db=array( | ||
"JobTitle" => 'Varchar', | ||
"Blurb" => "Text", | ||
"Website" => "Varchar(100)" | ||
); | ||
|
||
//Add form fields to CMS | ||
public function updateCMSFields(FieldList $fields) | ||
{ | ||
$fields->addFieldToTab("Root.Profile", new TextField('JobTitle', 'Job Title')); | ||
$fields->addFieldToTab("Root.Profile", new TextField('Website', 'Website', 'http://')); | ||
$fields->addFieldToTab("Root.Profile", new TextareaField('Blurb', 'Blurb')); | ||
} | ||
|
||
//Link to the edit profile page | ||
public function Link() | ||
{ | ||
if ($ProfilePage = DataObject::get_one('EditProfilePage')) { | ||
return $ProfilePage->Link(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,26 @@ | ||
<?php | ||
class MemberPage extends Page{ | ||
|
||
class MemberPage extends Page | ||
{ | ||
} | ||
|
||
class MemberPage_Controller extends Page_Controller{ | ||
|
||
static $allowed_actions = array('index'); | ||
|
||
function index(){ | ||
$Member = Member::CurrentUser(); | ||
if ($Member==null) { | ||
//echo "do resgistration"; | ||
if ($RegistrationPage = DataObject::get_one('RegistrationPage')){ | ||
return $this->redirect($RegistrationPage->Link()); | ||
} | ||
} | ||
else{ | ||
//echo "do edit registration"; | ||
if ($EditProfilePage = DataObject::get_one('EditProfilePage')){ | ||
return $this->redirect($EditProfilePage->Link()); | ||
class MemberPage_Controller extends Page_Controller | ||
{ | ||
|
||
} | ||
} | ||
} | ||
|
||
} | ||
public static $allowed_actions = array('index'); | ||
|
||
public function index() | ||
{ | ||
$Member = Member::CurrentUser(); | ||
if ($Member==null) { | ||
//echo "do resgistration"; | ||
if ($RegistrationPage = DataObject::get_one('RegistrationPage')) { | ||
return $this->redirect($RegistrationPage->Link()); | ||
} | ||
} else { | ||
//echo "do edit registration"; | ||
if ($EditProfilePage = DataObject::get_one('EditProfilePage')) { | ||
return $this->redirect($EditProfilePage->Link()); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.