public function loginAction() { $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $this->assets->collection('admin-login-css')->addCss(__DIR__ . '/../assets/login.css')->setLocal(true)->addFilter(new \Phalcon\Assets\Filters\Cssmin())->setTargetPath(PUBLIC_PATH . '/assets/admin-login.css')->setTargetUri('assets/admin-login.css'); $form = new LoginForm(); if ($this->request->isPost()) { if ($form->isValid($this->request->getPost())) { $login = $this->request->getPost('login', 'string'); $password = $this->request->getPost('password', 'string'); $user = AdminUser::findFirst("login='******'"); if ($user) { if ($user->checkPassword($password)) { if ($user->isActive()) { $this->session->set('auth', $user->getAuthData()); $this->flash->success($this->helper->translate("Wellcome to adminpanel")); $this->response->redirect('admin'); return $this->response->send(); } else { $this->flash->error($this->helper->translate("User isn't active")); } } else { $this->flash->error($this->helper->translate("Wrong login/password")); } } else { $this->flash->error($this->helper->translate("user not found Wrong login/password")); } } else { foreach ($form->getMessages() as $message) { $this->flash->error($message); } } } }
/** * The default action - show the home page */ public function indexAction() { $data = $this->getRequest(); $login_form = new LoginForm(); if ($data->isPost()) { $data = $this->getRequest()->getPost(); //验证 $inputFiler = new LoginFilter(); $login_form->setInputFilter($inputFiler)->setData($data); if (!$login_form->isValid()) { return new ViewModel(array('form' => $login_form, 'error' => "true")); } //通过验证 $authService = $this->getAuthService(); $adapter = $authService->getAdapter(); $adapter->setIdentityValue($data['worker_name']); $adapter->setCredentialValue(md5($data['worker_pwd'])); $authResult = $authService->authenticate(); $is = $authResult->isValid(); // var_dump($adapter);die(); if ($authResult->isValid()) { // 写入session $identity = $authResult->getIdentity(); $authService->getStorage()->write($identity); return $this->redirect()->toRoute('admin_album'); } } /* 显示登录页面 */ return array('form' => $login_form); }
public function loginAction() { $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $form = new LoginForm(); if ($this->request->isPost()) { if ($form->isValid($this->request->getPost())) { $login = $this->request->getPost('login', 'string'); $password = $this->request->getPost('password', 'string'); $user = AdminUser::findFirst("login='******'"); if ($user) { if ($user->checkPassword($password)) { if ($user->isActive()) { $this->session->set('auth', $user->getAuthData()); $this->flash->success($this->helper->translate("Приветствуем в административной панели управления!")); $this->response->redirect('admin'); return $this->response->send(); } else { $this->flash->error($this->helper->translate("Пользователь не активирован")); } } else { $this->flash->error($this->helper->translate("Неверный логин или пароль")); } } else { $this->flash->error($this->helper->translate("Неверный логин или пароль")); } } else { foreach ($form->getMessages() as $message) { $this->flash->error($message); } } } }
public function getServiceConfig() { return array('abstract_factories' => array(), 'aliases' => array(), 'factories' => array('AdminUsersTable' => function ($sm) { // echo __METHOD__." is reached; test echo in line ".__LINE__; $tableGateway = $sm->get('AdminUsersTableGateway'); $table = new AdminUsersTable($tableGateway); return $table; }, 'AdminUsersTableGateway' => function ($sm) { //echo __METHOD__." is reached; test echo in line ".__LINE__; $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new AdminUsers()); return new TableGateway('users', $dbAdapter, null, $resultSetPrototype); }, 'AdminCollectionTable' => function ($sm) { $tableGateway = $sm->get('AdminCollectionTableGateway'); $table = new AdminCollectionTable($tableGateway); return $table; }, 'AdminCollectionTableGateway' => function ($sm) { $dbAdapter = $sm->get('Zend\\Db\\Adapter\\Adapter'); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new AdminCollection()); return new TableGateway('items', $dbAdapter, null, $resultSetPrototype); }, 'LoginForm' => function ($sm) { $form = new LoginForm(); $form->setInputFilter($sm->get('LoginFormFilter')); return $form; }, 'AdminCollectionManagerForm' => function ($sm) { $form = new AdminCollectionManagerForm(); $form->setInputFilter($sm->get('AdminCollectionManagerFormFilter')); return $form; }, 'UserAddForm' => function ($sm) { $form = new UserAddForm(); $form->setInputFilter($sm->get('UserAddFormFilter')); return $form; }, 'LoginFormFilter' => function ($sm) { return new LoginFormFilter(); }, 'AdminCollectionManagerFormFilter' => function ($sm) { return new AdminCollectionManagerFormFilter(); }, 'UserAddFormFilter' => function ($sm) { return new UserAddFormFilter(); }), 'invokables' => array(), 'services' => array(), 'shared' => array()); }
public function addadminAction() { $form = new LoginForm(); $request = $this->getRequest(); if ($request->isPost()) { $admin = new Model\Admin(); $form->setInputFilter($admin->getInputFilter()); $form->setData($request->getPost()); if ($form->isValid()) { $admin->exchangeArray($form->getData()); $this->getAdminTable()->saveAdmin($admin); var_dump($_SESSION); exit; return $this->redirect()->toRoute('admin'); } else { throw new \Exception('Твоя гавноформа не проходит валидацию. Иди еби мозги'); } } return new ViewModel(['form' => $form]); }
public function getServiceConfig() { return ['factories' => ['Admin\\Form\\PersonForm' => function ($sm) { $form = new Form\PersonForm('person'); $form->setServiceManager($sm); return $form; }, 'Admin\\Form\\LoginForm' => function ($sm) { $form = new Form\LoginForm('login'); $form->setServiceManager($sm); $form->init(); return $form; }, 'Admin\\Service\\FileService' => function ($sm) { $service = new \Admin\Service\FileService(); $service->setServiceManager($sm); return $service; }, 'Admin\\Storage\\AuthenticationStorage' => function ($sm) { return new Admin\Storage\AuthenticationStorage(); }, 'Admin\\Service\\AuthenticationService' => function ($sm) { $service = new Service\AuthenticationService(); return $service; }]]; }
public function loginAction() { $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $form = new LoginForm(); if ($this->request->isPost()) { if ($this->security->checkToken()) { if ($form->isValid($this->request->getPost())) { $login = $this->request->getPost('login', 'string'); $password = $this->request->getPost('password', 'string'); $user = AdminUser::findFirst("login='******'"); if ($user) { if ($user->checkPassword($password)) { if ($user->isActive()) { $this->session->set('auth', $user->getAuthData()); $this->flash->success($this->helper->translate("Welcome to the administrative control panel!")); return $this->redirect($this->url->get() . 'admin'); } else { $this->flash->error($this->helper->translate("User is not activated yet")); } } else { $this->flash->error($this->helper->translate("Incorrect login or password")); } } else { $this->flash->error($this->helper->translate("Incorrect login or password")); } } else { foreach ($form->getMessages() as $message) { $this->flash->error($message); } } } else { $this->flash->error($this->helper->translate("Security errors")); } } $this->view->form = $form; }
public function createaccountAction() { $viewModel = new ViewModel(); $this->layout('layout/bags'); $form = new LoginForm(); $response = $this->getResponse(); $request = $this->getRequest(); if ($request->isPost()) { $admin = new Admin(); $form->setData($request->getPost()); if ($form->isValid()) { $admin->exchangeArray($form->getData()); $k = $this->getAdminTable()->checklogin($admin); if ($k == 1 || $k == 2) { echo 'Incorrect Username or password'; } if ($k == 0) { } } } return $viewModel; }
public function indexAction() { $this->layout("layout/empty"); $this->logged = new Container('user'); $table = $this->getUserTable(); $form = new LoginForm(); if (!$this->logged->boolLogged) { $messenger = new Messenger(); /* * if user has chosen the option 'remember me on this PC', then load * info from DB a redirect to admin */ if (isset($_COOKIE['sleanded_admin']) && $_COOKIE['sleanded_admin'] != '') { $credentials = explode(";", $_COOKIE['sleanded_admin']); $user = $table->autologin($credentials[0], $credentials[1]); /* * check, if the credentials in COOKIE are same as those in DB */ if (count($user) == 1) { $user = $user[0]; $this->registerSession($user, $this->logged); return $this->redirect()->toRoute('admin', array('controller' => 'index')); } else { unset($_COOKIE['sleanded_admin']); setcookie('sleanded_admin', '', time() - 3600); $message = ["Autologin failed, please log in", Messenger::ERROR]; } } $request = $this->getRequest(); if ($request->isPost()) { $form->addInputFilter(); $form->setData($request->getPost()); if ($form->isValid()) { /* * checks, if a pass & name are OK */ $u = new User(); $u->exchangeArray($request->getPost()); $user = $table->login($u->name, $u->password); if (count($user) == 1) { /* registering session * ---------------- * if option 'remember me on this PC' is selected: * save cookie + set param to DB */ $user = $user[0]; $this->registerSession($user, $this->logged); if ($u->remember == 1) { setcookie('sleanded_admin', $user['name'] . ';' . $user['password'], time() + 3600 * 24 * 15); $table->edit($user['id'], ['ip' => $_SERVER['REMOTE_ADDR'], 'remember' => 1]); } /* * redirecting to admin index page */ return $this->redirect()->toRoute('admin', array('controller' => 'index')); } else { $message = ["Invalid name/email or password. Please, try to log in again!", Messenger::ERROR]; } } else { $message = ["All form fields have to be filled!", Messenger::NOTICE]; } } } else { $this->logout(); } return ['message' => isset($message) ? $message : null, 'loginForm' => $form]; }
public function loginAction() { $form = new LoginForm(); if ($this->getRequest()->isPost() && $form->setData($this->getRequest()->getPost())->isValid()) { $authService = $this->getServiceLocator()->get('Zend\\Authentication\\AuthenticationService'); $authService->setAdapter($authService->getAdapter()->setIdentity($form->getInputFilter()->getValue('username'))->setCredential(md5($form->getInputFilter()->getValue('password')))); // check if authentication was successful // if authentication was successful, user information is stored automatically by adapter if ($authService->authenticate()->isValid()) { if ($this->identity()->getActive() == 1) { // redirect to user index page return $this->redirect()->toRoute('admin'); } // user account is not active, so set error message and flush identity $form->get('username')->setMessages(array('Your account has been deactivated')); $authService->clearIdentity(); // clear user } else { $form->get('username')->setMessages(array('Invalid username & password combination')); $form->get('password')->setMessages(array('Invalid username & password combination')); } } return array('form' => $form); }