コード例 #1
0
 public function indexAction()
 {
     $layout = $this->layout();
     $layout->setTemplate('layout/login');
     $form = new AdminForm();
     $form->get('submit')->setValue('Add');
     $request = $this->getRequest();
     if ($request->isPost()) {
         //echo '<pre>'; print_r($request->getPost());
         //exit;
         $admin = new Admin();
         $form->setInputFilter($admin->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $username = $request->getPost('email');
             $password = $request->getPost('password');
             $this->getAuthService()->getAdapter()->setIdentity($username)->setCredential($password);
             $result = $this->getAuthService()->authenticate();
             foreach ($result->getMessages() as $message) {
                 //save message temporary into flashmessenger
                 $this->flashmessenger()->addMessage($message);
             }
             if ($result->isValid()) {
                 //$redirect = 'success';
                 //check if it has rememberMe :
                 if ($request->getPost('rememberme') == 1) {
                     $this->getSessionStorage()->setRememberMe(1);
                     //set storage again
                     $this->getAuthService()->setStorage($this->getSessionStorage());
                 }
                 $this->getAuthService()->getStorage()->write($request->getPost('email'));
                 return $this->redirect()->toRoute('admin', array('action' => 'dashboard'));
             } else {
                 return $this->redirect()->toRoute('admin', array('controller' => 'index', 'action' => 'index', 'id' => 0));
             }
             /*if($email == '*****@*****.**' && $password == 'welcome1')
             		{					
             			$sessionAdmin = new Container('admin');
             			$sessionAdmin->email = $email ;
             			$sessionAdmin->isvalid = "yes";
             			return $this->redirect()->toRoute('admin', array('action'=>'dashboard'));
             		}
             		else
             		{
             			return $this->redirect()->toRoute('admin', array('controller' => 'index', 'action'=>'index','id'=>0));
             			
             			
             		} */
         }
     }
     return array('form' => $form, 'messages' => $this->flashmessenger()->getMessages());
     //return new ViewModel();
     /*
     return new ViewModel(array(
                 'admins' => $this->getAdminTable()->fetchAll(),
             ));
     */
 }
コード例 #2
0
 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]);
 }
コード例 #3
0
 public function indexAction()
 {
     // If already login then redirect to dashboard.
     if ($this->getServiceLocator()->get('AuthService')->hasIdentity()) {
         return $this->redirect()->toRoute('admin', array('action' => 'dashboard'));
     }
     $layout = $this->layout();
     $layout->setTemplate('layout/login');
     $form = new AdminForm();
     $form->get('submit')->setValue('Add');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $admin = new Admin();
         $form->setInputFilter($admin->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $username = $request->getPost('email');
             $password = $request->getPost('password');
             $this->getAuthService()->getAdapter()->setIdentity($username)->setCredential($password);
             $result = $this->getAuthService()->authenticate();
             foreach ($result->getMessages() as $message) {
                 //save message temporary into flashmessenger
                 $this->flashmessenger()->addMessage($message);
             }
             if ($result->isValid()) {
                 $sessionAdmin = new Container('admin');
                 $sessionAdmin->email = $username;
                 $sessionAdmin->isvalid = "yes";
                 return $this->redirect()->toRoute('admin', array('action' => 'dashboard'));
             } else {
                 return $this->redirect()->toRoute('admin', array('controller' => 'index', 'action' => 'index', 'id' => 0));
             }
         }
     }
     return array('form' => $form, 'messages' => $this->flashmessenger()->getMessages());
 }
コード例 #4
0
 public function loginajaxAction()
 {
     $username = $this->params()->fromPost('username');
     $password = $this->params()->fromPost('password');
     $data = array('username' => $username, 'password' => $password);
     if ($username != '' and $password != '') {
         $data = array('username' => $username, 'password' => $password);
         $admin = new Admin();
         $admin->exchangeArray($data);
         $k = $this->getAdminTable()->checklogin($admin);
         //$session_user = new Container('user');
         //return $session_user;
         //echo "k ---";print_r($session_user);die;
         if ($k == 1 || $k == 2) {
             echo 'Incorrect Username or password ';
             die;
         }
         if ($k == 0) {
             echo '';
             die;
             //	$this->redirect()->toUrl(WEBPATH.'/admin');
         }
     } else {
         echo "Error!";
         die;
     }
 }
コード例 #5
0
 public function pageregisterAction()
 {
     $this->layout('layout/apoadminlogin');
     if ($this->request->isPost()) {
         $username = addslashes(trim($this->params()->fromPost('username')));
         $email = addslashes(trim($this->params()->fromPost('email')));
         $password = addslashes(trim($this->params()->fromPost('password')));
         $check_user = $this->getAdminTable()->checkuser($username);
         $check_email = $this->getAdminTable()->checkemail($email);
         if ($check_user) {
             $alert = 'This account already exists';
             return array('alert' => $alert);
         } else {
             if ($check_email) {
                 $alert = 'This Email already exists';
                 return array('alert' => $alert);
             } else {
                 $data_user = array('username' => $username, 'password' => $password, 'email' => $email);
                 $admin_model = new Admin();
                 $admin_model->exchangeArray($data_user);
                 $this->getAdminTable()->register($admin_model);
                 $alert = 'Account Registration success';
                 return array('alert' => $alert);
             }
         }
     }
 }