Example #1
0
 public function indexAction()
 {
     // TODO Auto-generated {0}::indexAction() default action
     $form = new Admin_Form_Login();
     $this->view->form = $form;
     if ($this->_request->isPost()) {
         if ($form->isValid($_POST)) {
             //1.Goi ket noi voi Zend Db
             $db = Zend_Registry::get('connectDB');
             //2. Khoi tao Zend Auth
             $auth = Zend_Auth::getInstance();
             //3. Khai bao bang va 2 cot se su dung so sanh trong qua trinh login
             $authAdapter = new Zend_Auth_Adapter_DbTable($db);
             $authAdapter->setTableName('nguoi_dung')->setIdentityColumn('ten_dang_nhap')->setCredentialColumn('mat_khau');
             //4. Lay gia tri duoc gui qua tu FORM
             $uname = $form->getValue('Username');
             $paswd = md5($form->getValue('Password'));
             //5. Dua vao so sanh voi du lieu khai bao o muc 3
             $authAdapter->setIdentity($uname);
             $authAdapter->setCredential($paswd);
             //6. Kiem tra trang thai cua user neu trang_thai = 1 moi duoc login
             $select = $authAdapter->getDbSelect();
             $select->where('trang_thai = 1');
             //7. Lay ket qua truy van
             $result = $auth->authenticate($authAdapter);
             if ($result->isValid()) {
                 //8. Lay nhung du lieu can thiet trong bang users neu login thanh cong
                 $data = $authAdapter->getResultRowObject(null, array('mat_khau'));
                 //9. Luu  nhung du lieu cua member vao session
                 $auth->getStorage()->write($data);
                 //Update lan dang nhap cuoi
                 $user = Khcn_Api::_()->getItem('default_nguoi_dung', $auth->getStorage()->read()->id);
                 $user->lan_dang_nhap_cuoi = date('Y-m-d H:i:s');
                 $user->save();
                 $this->_redirect('/admin/index/index');
             } else {
                 $this->view->message = 'Tên đăng nhập hoặc mật khẩu không đúng';
             }
         } else {
             $this->view->form = $form;
         }
     } else {
         $this->view->form = $form;
     }
 }
 public function indexAction()
 {
     $form = new Admin_Form_Login();
     $this->view->form = $form;
     if ($this->getRequest()->isPost()) {
         $formData = $this->getRequest()->getPost();
         if ($form->isValid($formData)) {
             $adapter = new Rph_Auth_Adapter($form->getValue('login'), sha1($form->getValue('senha')));
             $result = Zend_Auth::getInstance()->authenticate($adapter);
             if (Zend_Auth::getInstance()->hasIdentity()) {
                 return $this->_helper->redirector('index', 'index', 'admin');
             } else {
                 $this->_helper->FlashMessenger(implode(' ', $result->getMessages()));
             }
         } else {
             $form->populate($formData);
         }
     }
 }
Example #3
0
 public function loginAction()
 {
     $this->_helper->layout()->setLayout("borrower/layout_login");
     $oFormLogin = new Admin_Form_Login();
     $oFacebook = new Facebook_Facebook();
     if (!$this->_oAuth->hasIdentity() && $oFacebook->getUser()) {
         $oFacebook->destroySession();
     }
     $aPostData = array();
     if ($this->_request->isPost()) {
         $aPostData = $this->_request->getPost();
         if ($oFormLogin->isValid($aPostData)) {
             $sEmailAddress = $oFormLogin->getValue("user_email_address") != "" ? $oFormLogin->getValue("user_email_address") : "";
             $sPassword = $oFormLogin->getValue("user_password");
             $oResult = $this->_oAuth->auth($sEmailAddress, $sPassword);
             if ($oResult->isValid()) {
                 $this->_redirect("/admin");
             }
         }
     }
     $oFormLogin->populate($aPostData);
     $this->view->oFormLogin = $oFormLogin;
 }