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 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); }