Skip to content

Commit

Permalink
Fix issue with forms and profile in frontend com_users.
Browse files Browse the repository at this point in the history
git-svn-id: http://joomlacode.org/svn/joomla/development/trunk@16739 6f6e1ebd-4c2b-0410-823f-f34bde69bce9
  • Loading branch information
eddieajau committed May 4, 2010
1 parent d1b5d8d commit 8851fd3
Show file tree
Hide file tree
Showing 30 changed files with 497 additions and 553 deletions.
4 changes: 2 additions & 2 deletions components/com_users/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public function display()
switch ($vName) {
case 'registration':
// If the user is already logged in, redirect to the profile page.
$user = & JFactory::getUser();
$user = JFactory::getUser();
if ($user->get('guest') != 1) {
// Redirect to profile page.
$app = & JFactory::getApplication();
$app = JFactory::getApplication();
$app->redirect(JRoute::_('index.php?option=com_users&view=profile', false));
}

Expand Down
44 changes: 22 additions & 22 deletions components/com_users/controllers/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,36 @@ public function edit()

// Get the previous user id (if any) and the current user id.
$previousId = (int) $app->getUserState('com_users.edit.profile.id');
$memberId = (int) JRequest::getInt('member_id', null, '', 'array');
$userId = (int) JRequest::getInt('user_id', null, '', 'array');

// Check if the user is trying to edit another users profile.
if ($userId != $memberId) {
if ($userId != $userId) {
JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR'));
return false;
}

// Set the member id for the member to edit in the session.
$app->setUserState('com_users.edit.profile.id', $memberId);
// Set the user id for the user to edit in the session.
$app->setUserState('com_users.edit.profile.id', $userId);

// Get the model.
$model = &$this->getModel('Profile', 'UsersModel');

// Check out the member.
if ($memberId) {
$model->checkout($memberId);
// Check out the user.
if ($userId) {
$model->checkout($userId);
}

// Check in the previous member.
// Check in the previous user.
if ($previousId) {
$model->checkin($previousId);
}

// Redirect to the edit screen.
$this->setRedirect(JRoute::_('index.php?option=com_users&view=profile&layout=edit&member_id='.$memberId, false));
$this->setRedirect(JRoute::_('index.php?option=com_users&view=profile&layout=edit&user_id='.$userId, false));
}

/**
* Method to save a member's profile data.
* Method to save a user's profile data.
*
* @return void
* @since 1.6
Expand All @@ -73,12 +73,12 @@ public function save()
JRequest::checkToken() or jexit(JText::_('JInvalid_Token'));

// Initialise variables.
$app = &JFactory::getApplication();
$model = &$this->getModel('Profile', 'UsersModel');
$user = &JFactory::getUser();
$app = JFactory::getApplication();
$model = $this->getModel('Profile', 'UsersModel');
$user = JFactory::getUser();
$userId = (int) $user->get('id');

// Get the member data.
// Get the user data.
$data = JRequest::getVar('jform', array(), 'post', 'array');

// Force the ID to this user.
Expand Down Expand Up @@ -112,8 +112,8 @@ public function save()
$app->setUserState('com_users.edit.profile.data', $data);

// Redirect back to the edit screen.
$memberId = (int)$app->getUserState('com_users.edit.profile.id');
$this->setRedirect(JRoute::_('index.php?option=com_users&view=profile&layout=edit&member_id='.$memberId, false));
$userId = (int) $app->getUserState('com_users.edit.profile.id');
$this->setRedirect(JRoute::_('index.php?option=com_users&view=profile&layout=edit&user_id='.$userId, false));
return false;
}

Expand All @@ -126,9 +126,9 @@ public function save()
$app->setUserState('com_users.edit.profile.data', $data);

// Redirect back to the edit screen.
$memberId = (int)$app->getUserState('com_users.edit.profile.id');
$userId = (int)$app->getUserState('com_users.edit.profile.id');
$this->setMessage(JText::sprintf('USERS PROFILE SAVE FAILED', $model->getError()), 'notice');
$this->setRedirect(JRoute::_('index.php?option=com_users&view=profile&layout=edit&member_id='.$memberId, false));
$this->setRedirect(JRoute::_('index.php?option=com_users&view=profile&layout=edit&user_id='.$userId, false));
return false;
}

Expand All @@ -146,17 +146,17 @@ public function save()

default:
// Check in the profile.
$memberId = (int)$app->getUserState('com_users.edit.profile.id');
if ($memberId) {
$model->checkin($memberId);
$userId = (int)$app->getUserState('com_users.edit.profile.id');
if ($userId) {
$model->checkin($userId);
}

// Clear the profile id from the session.
$app->setUserState('com_users.edit.profile.id', null);

// Redirect to the list screen.
$this->setMessage(JText::_('USERS PROFILE SAVE SUCCESS'));
$this->setRedirect(JRoute::_('index.php?option=com_users&view=profile&member_id='.$return, false));
$this->setRedirect(JRoute::_('index.php?option=com_users&view=profile&user_id='.$return, false));
break;
}

Expand Down
4 changes: 2 additions & 2 deletions components/com_users/controllers/registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function activate()
}

/**
* Method to register a member.
* Method to register a user.
*
* @return boolean True on success, false on failure.
* @since 1.6
Expand All @@ -84,7 +84,7 @@ public function register()
$app = JFactory::getApplication();
$model = $this->getModel('Registration', 'UsersModel');

// Get the member data.
// Get the user data.
$data = JRequest::getVar('jform', array(), 'post', 'array');

// Validate the posted data.
Expand Down
1 change: 0 additions & 1 deletion components/com_users/models/forms/login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

<field name="username" type="text"
class="validate-username"
field="id"
filter="username"
label="COM_USERS_LOGIN_USERNAME_LABEL"
required="true"
Expand Down
2 changes: 0 additions & 2 deletions components/com_users/models/forms/profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<field name="username" type="text"
class="validate-username"
description="COM_USERS_PROFILE_USERNAME_DESC"
field="id"
filter="username"
label="COM_USERS_PROFILE_USERNAME_LABEL"
message="COM_USERS_PROFILE_USERNAME_MESSAGE"
Expand Down Expand Up @@ -54,7 +53,6 @@
<field name="email1" type="text"
class="validate-email"
description="Users_Profile_Email1_Desc"
field="id"
filter="string"
label="COM_USERS_PROFILE_EMAIL1_LABEL"
message="COM_USERS_PROFILE_EMAIL1_MESSAGE"
Expand Down
1 change: 0 additions & 1 deletion components/com_users/models/forms/registration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<field name="username" type="text"
class="validate-username"
description="COM_USERS_REGISTER_USERNAME_DESC"
field="id"
filter="username"
label="COM_USERS_REGISTER_USERNAME_LABEL"
message="COM_USERS_REGISTER_USERNAME_MESSAGE"
Expand Down
18 changes: 9 additions & 9 deletions components/com_users/models/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ function &getLoginForm()
$dispatcher = &JDispatcher::getInstance();
JPluginHelper::importPlugin('user');

// Trigger the form preparation event.
$results = $dispatcher->trigger('onPrepareUsersLoginForm', array($this->getState('member.id'), &$form));

// Check for errors encountered while preparing the form.
if (count($results) && in_array(false, $results, true)) {
$this->setError($dispatcher->getError());
return false;
}

// Check the session for previously entered login form data.
$app = JFactory::getApplication();
$data = $app->getUserState('users.login.form.data', array());
Expand All @@ -72,6 +63,15 @@ function &getLoginForm()
}
$app->setUserState('users.login.form.data', $data);

// Trigger the form preparation event.
$results = $dispatcher->trigger('onContentPrepareForm', array($form, $data));

// Check for errors encountered while preparing the form.
if (count($results) && in_array(false, $results, true)) {
$this->setError($dispatcher->getError());
return false;
}

// Bind the form data if present.
if (!empty($data)) {
$form->bind($data);
Expand Down
Loading

0 comments on commit 8851fd3

Please sign in to comment.