本文整理汇总了PHP中Model\User::findFirst方法的典型用法代码示例。如果您正苦于以下问题:PHP User::findFirst方法的具体用法?PHP User::findFirst怎么用?PHP User::findFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model\User
的用法示例。
在下文中一共展示了User::findFirst方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: check
/**
* Checking user existing in system
*
* @param string $email
* @param string $password
* @param boolean $cookie
* @param boolean $log
* @return boolean
*/
public function check($email, $password, $cookie = false, $log = false)
{
$me = new \stdClass();
$myUser = \Model\User::findFirst(['email = :femail: AND status = :status:', 'bind' => ['femail' => $email, 'status' => \Model\User::STATUS_ENABLE]]);
if ($myUser) {
if ($this->security->checkHash($password, $myUser->password)) {
$me->id = $myUser->id;
$me->email = $myUser->email;
$me->name = $myUser->name;
$me->role = $myUser->role;
$me->roleName = $myUser->getRoleName();
$me->avatar = $myUser->avatar;
// create session for user
$this->session->set('me', $me);
// store cookie if chosen
if ($cookie == true) {
$this->cookie->set('remember-me', $me->id, time() + 15 * 86400);
}
if ($log) {
// Store user logged in (LOG_IN::userId::userEmail::userAgent::ip)
$this->logger->name = 'LOGIN';
// Your own log name
$this->logger->info($myUser->id . '::' . $myUser->email . '::' . $this->request->getUserAgent() . '::' . $this->request->getClientAddress());
}
return true;
} else {
$this->flash->error('Wrong user information. Try again.');
}
} else {
$this->flash->error('Wrong user information. Try again.');
}
}
示例2: beforeExecuteRoute
/**
* @param Event $event
* @param Dispatcher $dispatcher
* @return bool
*/
public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
{
$role = 'guest';
if ($this->session->has('user_id')) {
$userId = $this->session->get('user_id');
if ($userId) {
$user = User::findFirst($userId);
if ($user instanceof User) {
$role = 'user';
$dispatcher->setParam('user', $user);
}
}
}
$controller = strtolower($dispatcher->getControllerName());
$action = strtolower($dispatcher->getActionName());
if (!$this->acl->isAllowed($role, $controller, $action)) {
$this->session->set('__callback_url', $this->request->getServer('REQUEST_URI'));
$dispatcher->forward(['controller' => 'auth', 'action' => 'signIn']);
return false;
}
return true;
}
示例3: deleteAction
public function deleteAction()
{
$message = '';
$id = (int) $this->dispatcher->getParam('id');
$redirectUrl = (string) urldecode(base64_decode($this->dispatcher->getParam('redirect')));
$myUser = \Model\User::findFirst(['id = :id:', 'bind' => ['id' => (int) $id]])->delete();
if ($myUser) {
$this->flash->success(str_replace('###id###', $id, $this->lang->get('message_delete_success')));
} else {
foreach ($myUser->getMessages() as $msg) {
$message .= $msg->getMessage() . "</br>";
}
$this->flashSession->error($message);
}
return $this->response->redirect($redirectUrl);
}