array('fields' => array('email', 'first_name', 'last_name'), 'label' => 'Personal info'),
array('fields' => $permissions, 'label' => 'Permissions'),
);
+
+ /*
+ * User's profile
+ */
+
+ $profileTable = IPF::get('auth_profile_model');
+ if ($profileTable) {
+ $table = IPF_ORM::getTable($profileTable);
+ $profileFields = IPF_Form_Model::suggestFields($table);
+
+ $fieldGroup = array();
+ foreach ($profileFields as $field) {
+ list($n, $f) = $field;
+ $this->fields[$n] = $f;
+ $fieldGroup[] = $n;
+ }
+
+ $this->field_groups[] = array('fields' => $fieldGroup, 'label' => __('Profile'));
+ }
}
public function add__Permissions__field()
return $ok;
}
+
+ function save($commit=true)
+ {
+ $user = parent::save($commit);
+ $profileTable = IPF::get('auth_profile_model');
+ if ($profileTable) {
+ $profile = $user->getProfile();
+
+ $profile->SetFromFormData($this->cleaned_data);
+ $profile->save();
+ }
+ return $user;
+ }
}
class AdminUser extends IPF_Admin_Model
return implode(' / ', $roles);
}
- public function fields()
- {
- $fields = array(
- 'username',
- 'password',
- 'email',
- 'first_name',
- 'last_name',
- 'is_active',
- 'is_staff',
- 'is_superuser',
- );
- if (IPF_Auth_App::ArePermissionsEnabled()) {
- $fields[] = 'Permissions';
- $fields[] = 'Roles';
- }
- return $fields;
- }
-
function _searchFields()
{
return array(
{
const UNUSABLE_PASSWORD = '!';
public $session_key = 'IPF_User_auth';
+ private $profile = null;
public function __toString()
{
else
return false;
}
+
+ public function getData()
+ {
+ $data = parent::getData();
+ $profile = $this->getProfile();
+ if ($profile)
+ $data = $data + $profile->getData();
+ return $data;
+ }
+
+ public function getProfile()
+ {
+ $profileTable = IPF::get('auth_profile_model');
+ if (!$profileTable)
+ return null;
+
+ if (!$this->profile)
+ $this->profile = IPF_ORM::getTable($profileTable)->findOneByUserId($this->id);
+
+ if (!$this->profile) {
+ $this->profile = new $profileTable;
+ $this->profile->user = $this;
+ }
+
+ return $this->profile;
+ }
}
IPF_Admin_Model::register('User', 'AdminUser');