public function run() { $user = new Core_Auth_User(); if ($user->getRole() === null) { $user->setRole('guest'); } Core_View_Layout_JavascriptTemplate::singleton()->setCurrentJsFramework(Core_View_Layout_JavascriptTemplate::YUI); $this->router = new Core_Router_Route(); $sql = new Core_Model_Connection_MySql('localhost', 'root', 'root', 'betting_last'); $queriesTemplate = new Extension_Core_Model_Template_MySqlQueries(); Core_Model_Adapter_Sql::setSqlConnection($sql); Core_Model_Adapter_Sql::setSqlTemplate($queriesTemplate); }
public function actionLogin() { $this->preventTemplateRender(); $user = new Model_UserModel(); $isVarsSet = true; if (!isset($_POST['username'])) { $user->setValidationError('username', 'Username not set'); $isVarsSet = false; } if (!isset($_POST['password'])) { $user->setValidationError('password', 'Password not set'); $isVarsSet = false; } if (!$isVarsSet) { echo json_encode(array('status' => 'error', 'errors' => $user->getValidationErrors())); return; } $user->setUserName($_POST['username']); $user->setPasswordBeforeSalt($_POST['password']); $user->validateFields(array('user_name', 'password_before_salt')); if ($user->isValid()) { if (!$user->login()) { echo json_encode(array('status' => 'error', 'errors' => $user->getValidationErrors())); } else { $userSession = new Core_Auth_User(); $userSession->setData($user->getData()); $userStatus = new Model_UserStatusModel(); $userStatus->load($user->getUserStatusIdFK()); $userSession->isAuth(true); $userSession->setRole($userStatus->getStatusName()); echo json_encode(array('status' => 'ok')); } } else { echo json_encode(array('status' => 'error', 'errors' => $user->getValidationErrors())); } }