+++ /dev/null
-<?php
-
-class IPF_Admin_Forms_ChangePassword extends IPF_Form
-{
- function initFields($extra=array())
- {
- $this->fields['password1'] = new IPF_Form_Field_Varchar(array(
- 'required' => true,
- 'widget' =>'IPF_Form_Widget_PasswordInput',
- ));
- $this->fields['password2'] = new IPF_Form_Field_Varchar(array(
- 'required' => true,
- 'widget' => 'IPF_Form_Widget_PasswordInput',
- 'help_text' => __('Enter the same password as above, for verification.'),
- ));
- }
-
- public function clean()
- {
- $data = parent::clean();
-
- if ($data['password1'] != $data['password2'])
- $this->errors['password2'][] = __('The two password fields didn\'t match.');
-
- return $data;
- }
-
- public function render()
- {
- return $this->renderLayout(new IPF_Admin_Form_Layout, false);
- }
-
- public function unescape($html)
- {
- return new IPF_Template_SafeString($html, true);
- }
-}
-
+++ /dev/null
-{extends "admin/base.html"}
-
-{block css}
- {superblock}
- <link rel="stylesheet" href="{$ADMIN_MEDIA_URL}css/forms.css" />
-{/block}
-
-{block bodyclass}change-form{/block}
-
-{block breadcrumbs}
-<div class="breadcrumbs">
- <a href="{url 'IPF_Admin_Views_Index'}">{trans 'Home'}</a> »
- <a href="{url 'IPF_Admin_Views_ListItems', array($app->slug(), $component->slug())}">{$classname}</a> »
- <a href="{url 'IPF_Admin_Views_EditItem', array($app->slug(), $component->slug(), $object.id)}">{$object}</a> »
- Change Password
-</div>
-{/block}
-
-{block content}
-<div id="content" class="colM">
- <h1>{$page_title}</h1>
- <div id="content-main">
- <form method="post" action="">
- <div>
- {if $form.errors}
- <p class="errornote">Please correct the error below.</p>
- {/if}
- <fieldset class="module aligned">
- {$form->render()}
- </fieldset>
- <div class="submit-row">
- <input type="submit" value="Change password" class="default" />
- <input type="button" value="Cancel" onclick="javascript:history.back();" />
- </div>
- </div>
- </form>
- </div>
-</div>
-{/block}
-
-{block scripts}
-{foreach $extra_js as $js}
-{$js|safe}
-{/foreach}
-{/block}
-
return new IPF_HTTP_Response_Json('Cannot find model');
}
-function IPF_Admin_Views_ChangePassword($request, $match)
-{
- $component = IPF_Admin_App::getComponent($request, array('view', 'change'));
-
- $user = User::table()->find($match[1]);
-
- if ($request->method == 'POST') {
- $form = new IPF_Admin_Forms_ChangePassword($request->POST);
- if ($form->isValid()) {
- $user->setPassword($form->cleaned_data['password1']);
- $user->save();
- return new IPF_HTTP_Response_Redirect('../');
- }
- } else {
- $form = new IPF_Admin_Forms_ChangePassword();
- }
-
- $context = array(
- 'component' => $this,
- 'app' => $app,
- 'page_title'=>'Change Password: '.$user->username,
- 'classname'=>'User',
- 'object'=>$user,
- 'form' => $form,
- 'extra_js' => array(),
- );
-
- return IPF_Admin_App::RenderToResponse('admin/changepassword.html', $context, $request);
-}
-
function IPF_Admin_Views_Login($request, $match)
{
$success_url = '';
'label' => __('Username'),
'help_text' => __('Required. 32 characters or less. Alphanumeric characters only (letters, digits and underscores).'),
));
- $this->fields['password'] = new IPF_Form_Field_Varchar(array(
- 'required' => true,
- 'max_length' => 128,
+
+ $this->fields['password1'] = new IPF_Form_Field_Varchar(array(
'label' => __('Password'),
+ 'required' => $this->isAdd,
+ 'max_length' => 32,
+ 'widget' => 'IPF_Form_Widget_PasswordInput'
+ ));
+
+ $this->fields['password2'] = new IPF_Form_Field_Varchar(array(
+ 'label' => __('Password (again)'),
+ 'required' => $this->isAdd,
+ 'max_length' => 32,
+ 'widget' => 'IPF_Form_Widget_PasswordInput',
+ 'help_text' => __('Enter the same password as above, for verification.'),
));
$this->fields['email'] = new IPF_Form_Field_Email(array(
'label' => __('Active'),
'help_text' => __('Designates whether this user should be treated as active. Unselect this instead of deleting accounts.'),
));
+
$this->fields['is_staff'] = new IPF_Form_Field_Boolean(array(
'label' => __('Staff status'),
'help_text' => __('Designates whether the user can log into this admin site.'),
));
+
$this->fields['is_superuser'] = new IPF_Form_Field_Boolean(array(
'label' => __('Superuser status'),
'help_text' => __('Designates that this user has all permissions without explicitly assigning them.'),
));
- if ($this->isAdd) {
- unset($this->fields['password']);
-
- $this->fields['password1'] = new IPF_Form_Field_Varchar(array(
- 'label' => __('Password'),
- 'required' => true,
- 'max_length' => 32,
- 'widget' => 'IPF_Form_Widget_PasswordInput'
- ));
-
- $this->fields['password2'] = new IPF_Form_Field_Varchar(array(
- 'label' => __('Password (again)'),
- 'required' => true,
- 'max_length' => 32,
- 'widget' => 'IPF_Form_Widget_PasswordInput',
- 'help_text' => __('Enter the same password as above, for verification.'),
- ));
-
- $account = array('username', 'password1', 'password2', 'email');
- } else {
- $this->fields['password']->help_text = __("Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>.");
-
- $account = array('username', 'password', 'email');
- }
-
$permissions = array('is_active', 'is_staff', 'is_superuser');
if (IPF_Auth_App::ArePermissionsEnabled()) {
$permissions[] = 'permissions';
}
$this->field_groups = array(
- array('fields' => $account),
+ array('fields' => array('username', 'password1', 'password2', 'email')),
array('fields' => $permissions, 'label' => __('Permissions')),
);
}
- function isValid()
+ public function clean()
{
- $ok = parent::isValid();
+ $data = parent::clean();
- if ($ok===true && $this->isAdd) {
- if ($this->cleaned_data['password1'] != $this->cleaned_data['password2']) {
- $this->is_valid = false;
- $this->errors['password2'][] = "The two password fields didn't match.";
-
- return false;
- }
-
- $this->cleaned_data['password'] = User::SetPassword2($this->cleaned_data['password1']);
+ if ($this->isAdd || $data['password1'] || $data['password2']) {
+ if ($data['password1'] != $data['password2'])
+ $this->errors['password2'][] = __('The two password fields didn\'t match.');
}
- return $ok;
+ return $data;
}
}
if ($user) {
$extra['initial'] = array(
'username' => $user->username,
- 'password' => $user->password,
'email' => $user->email,
'is_active' => $user->is_active,
'is_staff' => $user->is_staff,
/*
+// $this->cleaned_data['password'] = User::SetPassword2($this->cleaned_data['password1']);
+
+
+
\PFF\Container::databaseQuery()
->deleteFrom('auth_user_permission')
->where('user_id', $user->id)