<div id="content" class="colM">
<div id="content-main">
<form method="post">
- {if $form.message}<ul class="errorlist"><li>{$form.message}</li></ul>{/if}
{$form_html}
<div class="submit-row">
<input type="submit" value="Sign In" class="default" />
if ($request->method == 'POST') {
$form = new IPF_Auth_Forms_Login($request->POST);
if ($form->isValid()) {
- $users = new User();
- if (false === ($user = $users->checkCreditentials($form->cleaned_data['username'], $form->cleaned_data['password']))) {
- $form->message = __('The login or the password is not valid. The login and the password are case sensitive.');
- } else {
- IPF_Auth_App::login($request, $user);
- return new IPF_HTTP_Response_Redirect($success_url);
- }
+ IPF_Auth_App::login($request, $form->user);
+ return new IPF_HTTP_Response_Redirect($success_url);
}
} else {
$form = new IPF_Auth_Forms_Login(array('next'=>$success_url));
}
+
$context = array(
'page_title' => IPF::get('admin_title'),
'form' => $form,
<?php
-class IPF_Auth_Forms_ChangePassword extends IPF_Form{
-
+class IPF_Auth_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.'));
+ $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.'),
+ ));
}
- function isValid(){
- $ok = parent::isValid();
- if ($ok===true){
- if ($this->cleaned_data['password1']!=$this->cleaned_data['password2']){
- $this->is_valid = false;
- $this->errors['password2'][] = "The two password fields didn't match.";
- $ok = false;
- }
- }
- return $ok;
+ public function clean()
+ {
+ $data = parent::clean();
+
+ if ($data['password1'] != $data['password2'])
+ $this->errors['password2'][] = __('The two password fields didn\'t match.');
+
+ return $data;
}
}
+
+++ /dev/null
-<?php
-
-class IPF_Auth_Forms_ChangeSelfPassword extends IPF_Form{
-
- function initFields($extra=array())
- {
- $this->fields['oldpassword'] = new IPF_Form_Field_Varchar(array('label'=>'Current Password', 'required'=>true, 'widget'=>'IPF_Form_Widget_PasswordInput'));
- $this->fields['password1'] = new IPF_Form_Field_Varchar(array('label'=>'New Password', 'required'=>true,'widget'=>'IPF_Form_Widget_PasswordInput'));
- $this->fields['password2'] = new IPF_Form_Field_Varchar(array('label'=>'New Password (repeat)','required'=>true,'widget'=>'IPF_Form_Widget_PasswordInput','help_text'=>'Enter the same password as above, for verification.'));
- }
-
- function isValid($request){
- $ok = parent::isValid();
- if ($ok===true){
- if ($this->cleaned_data['password1']!=$this->cleaned_data['password2']){
- $this->is_valid = false;
- $this->errors['password2'][] = "The two password fields didn't match.";
- $ok = false;
- }
- $u = new User();
- if ($u->checkCreditentials($request->user->username, $this->cleaned_data['oldpassword'])===false){
- $this->is_valid = false;
- $this->errors['oldpassword'][] = "Incorrect old password";
- $ok = false;
- }
- }
- return $ok;
- }
-}
-<?php
+<?php
-class IPF_Auth_Forms_Login extends IPF_Form{
- var $message = null;
- function initFields($extra=array()){
+class IPF_Auth_Forms_Login extends IPF_Form
+{
+ public $message = null;
+ public $user = null;
+
+ protected function initFields($extra=array())
+ {
$this->fields['username'] = new IPF_Form_Field_Varchar(array('required'=>true));
$this->fields['password'] = new IPF_Form_Field_Varchar(array('required'=>true,'widget'=>'IPF_Form_Widget_PasswordInput'));
$this->fields['next'] = new IPF_Form_Field_Varchar(array('required'=>false,'widget'=>'IPF_Form_Widget_HiddenInput'));
}
+
+ public function clean()
+ {
+ $data = parent::clean();
+
+ $this->user = User::checkCreditentials($data['username'], $data['password']);
+ if (!$this->user)
+ throw new IPF_Exception_Form(__('The login or the password is not valid. The login and the password are case sensitive.'));
+
+ return $data;
+ }
}
+
return 0 === (int)$this->id;
}
- function checkCreditentials($username, $password)
+ public static function checkCreditentials($username, $password)
{
- $user = $this->getTable()->findOneByUsername($username);
- if ($user === false) {
- return false;
- }
- if ($user->is_active and $user->checkPassword($password)) {
+ $user = self::table()->findOneByUsername($username);
+ if ($user && $user->is_active && $user->checkPassword($password))
return $user;
- }
- return false;
+ else
+ return false;
}
}
function isValid()
{
- if ($this->is_valid !== null) {
+ if ($this->is_valid !== null)
return $this->is_valid;
- }
+
$this->cleaned_data = array();
$this->errors = array();
$form_methods = get_class_methods($this);
}
}
}
- try {
- $this->cleaned_data = $this->clean();
- } catch (IPF_Exception_Form $e) {
- if (!isset($this->errors['__all__'])) $this->errors['__all__'] = array();
- $this->errors['__all__'][] = $e->getMessage();
+
+ if (empty($this->errors)) {
+ try {
+ $this->cleaned_data = $this->clean();
+ } catch (IPF_Exception_Form $e) {
+ if (!isset($this->errors['__all__'])) $this->errors['__all__'] = array();
+ $this->errors['__all__'][] = $e->getMessage();
+ }
}
+
if (empty($this->errors)) {
$this->is_valid = true;
return true;
+ } else {
+ // as some errors, we do not have cleaned data available.
+ $this->cleaned_data = array();
+ $this->is_valid = false;
+ return false;
}
- // as some errors, we do not have cleaned data available.
- $this->cleaned_data = array();
- $this->is_valid = false;
- return false;
}
public function clean()