Source for file UserController.php
Documentation is available at UserController.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: UserController.php 153 2010-06-23 10:06:25Z teo $
* @author DotKernel Team <team@dotkernel.com>
// instantiate classes related to User module: model & view
// all actions MUST set the variable $pageTitle
$pageTitle = $option->pageTitle->action->{$requestAction};
// switch based on the action, don't forget the default action
// default action is login
$pageTitle = $option->pageTitle->action->login;
if(!isset ($session->user))
$userView->loginForm('login');
header('Location: '. $config->website->params->url. '/user/account');
// validate the authorization request paramethers
$validate = $userModel->validateLogin($_POST['username'], $_POST['password'], $_POST['send']);
if(!empty($validate['login']) && empty($validate['error']))
// login info are VALID, we can see if is a valid user now
$user = $userModel->checkLogin($validate['login']);
// user is valid and logged in
//prepare data for register the login
'userId' => $session->user['id'],
'username' => $session->user['username'],
'referer' => $_SERVER['HTTP_REFERER'],
'userAgent' => $_SERVER["HTTP_USER_AGENT"]);
$userModel->registerLogin($dataLogin);
header('location: '. $config->website->params->url. '/user/account');
$session->message['txt'] = $option->errorMessage->login;
$session->message['type'] = 'error';
// login info are NOT VALID
$session->message['txt'] = array($validate['error']['username'], $validate['error']['password']);
$session->message['type'] = 'error';
$session->message['txt'] = $option->warningMessage->userPermission;
$session->message['type'] = 'warning';
header('Location: '. $config->website->params->url. '/user/login');
// display My Account page, if user is logged in
// POST values that will be validated
$values = array('details' =>
array('firstName'=> $_POST['firstName'],
'lastName'=> $_POST['lastName']
'email' => array('email' => $_POST['email']),
'password' => array('password' => $_POST['password'],
'password2' => $_POST['password2']
$valid = $userModel->validateUser($values);
$error = $valid['error'];
$data['id'] = $request['id'];
// no error - then update user
$userModel->updateUser($data);
$session->message['txt'] = $option->infoMessage->update;
$session->message['type'] = 'info';
$session->message['txt'] = $error;
$session->message['type'] = 'error';
$dataTmp = $userModel->getUserInfo($session->user['id']);
$data['username'] = $dataTmp['username'];
$data = $userModel->getUserInfo($session->user['id']);
$userView->details('update',$data);
// display signup form and allow user to register
// POST values that will be validated
$values = array('details' =>
array('firstName'=> $_POST['firstName'],
'lastName'=> $_POST['lastName']
'username' => array('username'=> $_POST['username']),
'email' => array('email' => $_POST['email']),
'password' => array('password' => $_POST['password'],
'password2' => $_POST['password2']
$valid = $userModel->validateUser($values);
$error = $valid['error'];
if(!isset ($_POST['recaptcha_response_field']) || strlen($_POST['recaptcha_response_field']) == 0)
$error['Secure Image'] = $option->errorMessage->captcha;
// validate secure image code
$result = $userView->getRecaptcha()->verify($_POST['recaptcha_challenge_field'],$_POST['recaptcha_response_field']);
$error['Secure Image'] = $option->errorMessage->captcha;
//check if user already exists by $field ('username','email')
$checkBy = array('username','email');
foreach ($checkBy as $field)
$userExists = $userModel->getUserBy($field, $data[$field]);
$error[$field] = ucfirst($field). $option->errorMessage->userExists;
// no error - then add user
$userModel->addUser($data);
$session->message['txt'] = $option->infoMessage->add;
$session->message['type'] = 'info';
$validate = $userModel->validateLogin($data['username'], $data['password'], 'on');
if(!empty($validate['login']) && empty($validate['error']))
// login info are VALID, we can see if is a valid user now
$user = $userModel->checkLogin($validate['login']);
//this else case should never be reach
$error['Error Login'] = $option->errorMessage->login;
// do not display password in the add form
unset ($data['password']);
// add action and validation are made with ajax - dojo.xhrPost, so return json string
echo Zend_Json::encode(array('data'=> $data, 'error'=> $error));
// return $data and $error as json
$userView->details('add',$data);
// send an emai with the forgotten password
$valid = $userModel->validateEmail($_POST['email']);
$error = $valid['error'];
// no error - then send password
$userModel->forgotPassword($data['email']);
$session->message['txt'] = $error;
$session->message['type'] = 'error';
$userView->details('forgot_password',$data);
header('location: '. $config->website->params->url);
|