<?php $user = new Core_Auth_User(); if (!$user->isAuth()) { ?> Y.one('<?php echo $this->getHtmlIds('loginPopUp', true); ?> ').on('click', function() { Y.one('#loginContent').setStyle('display','block'); <?php echo $this->getLoginPanel()->getId(); ?> .show(); } ) Y.one('<?php echo $this->getHtmlIds('registerPopUp', true); ?> ').on('click', function() { Y.one('#registrationContent').setStyle('display','block'); <?php echo $this->getRegistrationPanel()->getId();
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())); } }
<style> #loginContent { display:none; } #registrationContent { display:none; } </style> <?php $user = new Core_Auth_User(); if ($user->isAuth()) { ?> <div style="float:right"> <a href="<?php echo $url = Application::getRouter()->getFullUrl(array('controller' => 'index', 'action' => 'logout')); ?> "> Logout </a> </div> <?php } else { ?> <div style="float:right"> <span><a id="<?php echo $this->getHtmlIds('loginPopUp'); ?> " href="#"> Login </a></span>