/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = Users::findByUsername($this->username); } return $this->_user; }
/** * Finds user by [[username]] * * @return User|null */ protected function getUser() { if ($this->_user === null) { $this->_user = Users::findByUsername($this->username); } return $this->_user; }
public function actionAuthenticate() { $request = Yii::$app->request; $username = $request->post('username'); $user = Users::findByUsername($username); // Just create the user if not found if (!$user) { $user = new Users(); $user->username = $username; $user->save(); } echo json_encode(['auth' => $user->getId() ? true : false, 'id' => $user->id, 'username' => $user->username]); }
public function actionGetScore() { $request = Yii::$app->request; $username = $request->post('username'); $testId = $request->post('testId'); $user = Users::findByUsername($username); $test = Test::findOne($testId); if (!$user || !$test) { return ['success' => false, 'message' => 'Eiher the user or test was not found']; } return ['success' => true, 'score' => $test->score]; }
}); Uploads::applyFilter('save', function ($self, $params, $chain) { if ($params['data']) { $params['entity']->set($params['data']); $params['data'] = array(); } if (!$params['entity']->id) { $params['entity']->created = date('Y-m-d H:i:s'); } return $chain->next($self, $params, $chain); }); use lithium\util\Validator; Validator::add('usernameTaken', function ($value) { $success = false; if (strlen($value) != 0) { $success = count(Users::findByUsername($value)) == 0 ? false : true; } return !$success; }); use lithium\core\Libraries; Libraries::add('upload', array('path' => LITHIUM_APP_PATH . '/libraries/_source/upload/')); Libraries::add('captcha', array('path' => LITHIUM_APP_PATH . '/libraries/_source/captcha/', 'webroot' => LITHIUM_APP_PATH . '/libraries/_source/captcha/', "bootstrap" => "securimage.php")); define('_INSTALL', file_exists($_SERVER['DOCUMENT_ROOT'] . "/install") ? '1' : '0'); function getBaseUrl() { $protocol = isset($_SERVER["HTTPS"]) && $_SERVER['HTTPS'] != "off" ? "https" : "http"; return $protocol . "://" . $_SERVER['HTTP_HOST']; } use lithium\core\Environment; Environment::is(function ($request) { return in_array($request->env('SERVER_ADDR'), array('::1', '127.0.0.1')) ? 'development' : 'production';