/** * Default action. * * @param $args array */ public function index(array $args = array()) { $error = null; $playerModel = \App::getModel('Player'); $session = \App::getModel('Session'); if (empty($_POST['username']) || empty($_POST['password'])) { $error = 'Please enter your username and password!'; } else { try { $player = $playerModel->authenticate($_POST['username'], $_POST['password']); } catch (\Exception $e) { $error = 'Invalid username and/or password.'; if (\Config::get('security.login.showInvalidLoginReason')) { $error = $e->getMessage(); } } } if (isset($error)) { $session->clear(); $error = '<strong>Sorry, you could not be logged in...</strong><br />' . $error; \View::setMessage($error, 'fail'); /* Changed from a header to just grabbing the view itself */ \View::setTemplate('Index.twig'); \View::set('credentials', array('username' => \Config::get('security.login.returnUsernameOnFailure') ? isset($_POST['username']) ? $_POST['username'] : '' : '')); } }
/** * Default action * @param $args array */ public function index(array $args = array()) { $hooks = array(); \View::set('registerLayoutHooks', $hooks); \View::set('username', isset($_POST['username']) ? $_POST['username'] : ''); \View::set('email', isset($_POST['email']) ? $_POST['email'] : ''); \View::set('password', isset($_POST['password']) ? $_POST['password'] : ''); \View::set('pageTitle', 'Register'); $auth = $this->app->getModel('player'); if (isset($_POST['register'])) { $insert = array(); $insert['username'] = $_POST['username']; $insert['email'] = $_POST['email']; $insert['password'] = $_POST['password']; $insert['confirm_password'] = $_POST['password2']; try { /* Attempt to register the account */ $register = $auth->create($insert); } catch (\Exception $e) { $message = '<strong>You could not be registered:</strong><ul>'; foreach (unserialize($e->getMessage()) as $prev) { $message .= '<li>' . $prev->getMessage() . '</li>'; } $message .= '</ul>'; \View::setMessage($message, 'warn'); } /* If the account is active, redirect the user to the login page */ if (isset($register['active']) && $register['active'] == '1') { \View::setMessage('Your accounts was successfully created. You may now log in.', 'success'); } elseif (isset($register['active']) && $register['active'] == '0') { \View::setMessage('Your account has been created, but requires activation.', 'success'); \View::setTemplate('Index.twig'); } } }
private function callView() { try { $view = getcwd() . '/application/views/' . $this->application->controller . '/' . $this->application->view . '.php'; if (!is_readable($view)) { throw new Exception('Controller cannot find the view file ' . $view); } else { View::setMessage($this->message); ob_start(); require_once $view; View::setContent(ob_get_clean()); } } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } }
/** * setPassword */ public function setpassword() { if ($_POST['username'] && $_POST['password']) { $playerModel = \App::getModel('Player'); $playerModel->safeMode = false; $player = $playerModel->find($_POST['username'], 'username'); if ($player !== false) { $id = $player['player_id']; $password = password_hash($_POST['password'], PASSWORD_BCRYPT); $playerModel->save(array('player_id' => $id, 'password' => $password)); \View::setMessage('Old Password Has: ' . $player['password'], 'info'); \View::setMessage('New Password Set: ' . $password, 'success'); } else { \View::setMessage('Username Not Found', 'warn'); } \View::setTemplate('DevTools.twig'); } $this->index(); }
/** * @covers Bedrock\View::hasMessages * @covers Bedrock\View::setMessage * * @return void */ public function testHasMessagesOnlyError() { // Setup $messages = array( 'error' => array( 'Testing message type: ERROR_01', 'Testing message type: ERROR_02', 'Testing message type: ERROR_03' ) ); // Assertions $this->_assertNoMessages($this->_object); $this->_object->setMessage(\Bedrock\View::MESSAGE_ERROR, $messages['error'][0]); $this->_object->setMessage(\Bedrock\View::MESSAGE_ERROR, $messages['error'][1]); $this->_object->setMessage(\Bedrock\View::MESSAGE_ERROR, $messages['error'][2]); $this->_assertOnlyMessagesOfType(\Bedrock\View::MESSAGE_ERROR, $this->_object); $this->assertAttributeSame($messages, '_messages', $this->_object); }
public function test() { \View::setMessage('Testing', 'good'); }