Source for file User.php
Documentation is available at User.php
* DotBoost Technologies Inc.
* DotKernel Application Framework
* @copyright Copyright (c) 2009 DotBoost Technologies (http://www.dotboost.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @version $Id: User.php 160 2010-06-28 04:24:28Z teo $
* Here are all the actions related to the user
* @author DotKernel Team <team@dotkernel.com>
$this->db = Zend_Registry::get('database');
$this->option = Zend_Registry::get('option');
* Check to see if user can login
$select = $this->db->select()
->where('isActive = ?','1')
->where('username = ?', $data['username'])
->where('password = ?', $data['password']);
$result = $this->db->fetchAll($select);
( 1 == count($result)) ? $return = $result[0] : $return = array();
public function getUserBy($field = '', $value = '')
$select = $this->db->select()
->where($field. ' = ?', $value)
$result = $this->db->fetchRow($select);
$select = $this->db->select()
return $this->db->fetchRow($select);
// if you want to add an inactive user, un-comment the below line, default: isActive = 1
// $data['isActive'] = 0;
$this->db->insert('user',$data);
$this->db->update('user', $data, 'id = '. $id);
$this->db->insert('userLogin', $data);
* Validate the data that comes from login form
* @param string $username
* @param string $password
* @param string $send [optional] which is a control key
public function validateLogin($username, $password, $send = 'off')
$validatorUsername = new Zend_Validate();
$validatorUsername->addValidator(new Zend_Validate_Alnum())
->addValidator(new Zend_Validate_StringLength(
$this->option->validate->username->lengthMin,
$this->option->validate->username->lengthMax
if ($validatorUsername->isValid($username))
$login['username'] = $username;
$error['username'] = $this->option->errorMessage->invalidUsername;
$validatorPassword = new Zend_Validate();
$validatorPassword->addValidator(new Zend_Validate_StringLength(
$this->option->validate->password->lengthMin,
$this->option->validate->password->lengthMax
if ($validatorPassword->isValid($password))
$login['password'] = $password;
$error['password'] = $this->option->errorMessage->invalidPassword;
return array('login'=> $login, 'error'=> $error);
* Validate user input, add or update form
* $values is an array on multiple levels. On first level, the key suggest what validation will be done.
* - details - only filter the input
* - username - validate with Zend_Validate_Alnum, Zend_Validate_StringLength and filter the input
* - email - validate with Zend_Validate_EmailAddress and filter the input
* - password - validate with Zend_Validate_StringLength and filter the input
//validate the input data - username, password and email will be also filtered
$validatorChain = new Zend_Validate();
//validate details parameters
$validatorChain = new Zend_Validate();
$validatorChain->addValidator(new Zend_Validate_Alnum())
->addValidator(new Zend_Validate_StringLength(
$this->option->validate->details->lengthMin,
$this->option->validate->details->lengthMax
$validatorEmail = new Zend_Validate_EmailAddress();
if($values['password']['password'] == $values['password']['password2'])
unset ($values['password']['password2']);
$validatorChain = new Zend_Validate();
$validatorChain->addValidator(new Zend_Validate_StringLength(
$this->option->validate->password->lengthMin,
$this->option->validate->password->lengthMax
$error['password'] = $this->option->errorMessage->passwordTwice;
return array('data' => $data, 'error' => $error);
* Validate email user input
$validatorEmail = new Zend_Validate_EmailAddress();
* Send forgot password to user
$session = Zend_Registry::get('session');
$dotEmail->addTo($email);
$dotEmail->setSubject($this->option->forgotPassword->subject);
array($value['firstName'], $value['password']),
$this->option->forgotPassword->message);
$dotEmail->setBodyText($msg);
$succeed = $dotEmail->send();
$session->message['txt'] = $this->option->errorMessage->emailSent. $email;
$session->message['type'] = 'info';
$session->message['txt'] = $this->option->errorMessage->emailNotSent. $email;
$session->message['type'] = 'error';
$session->message['txt'] = $email. $this->option->errorMessage->emailNotFound;
$session->message['type'] = 'error';
|