/** * 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.'); } }
/** * @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; }
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); }