示例#1
0
 /**
  * Zend_Auth_Result
  *
  * @param string $login
  * @param string $password
  *
  * @return  bool
  */
 public static function authenticate($login, $password)
 {
     $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter(), 'users', 'login', 'password', 'MD5(CONCAT(salt, ?)) AND ' . 'status = "' . Users_Model_User::STATUS_ACTIVE . '"');
     $auth = Zend_Auth::getInstance();
     // set the input credential values to authenticate against
     $authAdapter->setIdentity($login);
     $authAdapter->setCredential($password);
     // do the authentication
     $result = $auth->authenticate($authAdapter);
     if ($result->isValid()) {
         // success: store database row to auth's storage system
         $users = new Users_Model_User_Table();
         $auth->getStorage()->write($users->getByLogin($login));
         return true;
     }
     return false;
 }
示例#2
0
 /**
  * View blog author
  */
 public function authorAction()
 {
     if (!($login = $this->_getParam('login'))) {
         throw new Zend_Controller_Action_Exception('Page not found');
     }
     $users = new Users_Model_User_Table();
     if (!($row = $users->getByLogin($login))) {
         throw new Zend_Controller_Action_Exception('Blog not found');
     }
     $post = new Blog_Model_Post_Table();
     $source = $post->getSelect(null, $row->id);
     $paginator = Zend_Paginator::factory($source);
     $paginator->getView()->route = 'blogauthor';
     $paginator->setItemCountPerPage($this->_itemsPerPage);
     $paginator->setCurrentPageNumber($this->_getParam('page'));
     $this->view->paginator = $paginator;
     $this->view->author = $row;
     $this->render('index');
 }
 /**
  * Oauth Connect
  *
  */
 public function oauthAction()
 {
     $namespace = $this->_getOauthStorage();
     $info = $namespace->info;
     $users = new Users_Model_User_Table();
     if (empty($info->email)) {
         $row = $users->getByTwitterid($info->twitterId);
     } else {
         $row = $users->getByEmail($info->email);
         if (!$row) {
             if (self::OAUTH_FACEBOOK == $this->_getParam('type')) {
                 $row = $users->getByFacebookid($info->facebookId);
             } elseif (self::OAUTH_GOOGLE == $this->_getParam('type')) {
                 $row = $users->getByGoogleid($info->googleId);
             }
         }
     }
     if (!$row) {
         $loginFilter = new Zend_Filter_Alnum();
         $info->login = $loginFilter->filter($info->login);
         if ($users->getByLogin($info->login)) {
             $form = new Users_Form_Auth_RegisterLogin();
             if ($this->getRequest()->isPost() && $form->isValid($this->_getAllParams())) {
                 $info->login = $form->getValue('login');
             } else {
                 $this->view->login = $info->login;
                 $this->view->form = $form;
                 return;
             }
         }
         $row = $users->createRow($info->getArrayCopy());
         $row->role = Users_Model_User::ROLE_USER;
         $row->status = Users_Model_User::STATUS_ACTIVE;
         $row->save();
     }
     $row->login();
     $namespace->unsetAll();
     $this->_helper->flashMessenger->addMessage('Now You\'re Logging!');
     $this->_helper->redirector(false, false, false);
 }
示例#4
0
 /**
  * @param array $authData
  * @throws Zend_Controller_Action_Exception
  */
 private function _oauthLogin($authData)
 {
     if (isset($authData['auth']['uid'])) {
         $users = new Users_Model_User_Table();
         switch ($authData['auth']['provider']) {
             case 'Facebook':
                 $serviceFieldName = 'facebookId';
                 $row = $users->getByFacebookid($authData['auth']['uid']);
                 if (!$row) {
                     if (isset($authData['auth']['info']['email'])) {
                         //If exist user's email
                         $row = $users->getByEmail($authData['auth']['info']['email']);
                         if ($row) {
                             $row->facebookId = $authData['auth']['uid'];
                             $row->save();
                         }
                     }
                 }
                 break;
             case 'Twitter':
                 $serviceFieldName = 'twitterId';
                 $row = $users->getByTwitterid($authData['auth']['uid']);
                 break;
             case 'Google':
                 $serviceFieldName = 'googleId';
                 $row = $users->getByGoogleid($authData['auth']['uid']);
                 if (!$row) {
                     if (isset($authData['auth']['info']['email'])) {
                         $authData['auth']['info']['nickname'] = $authData['auth']['info']['email'];
                         //If exist user's email
                         $row = $users->getByEmail($authData['auth']['info']['email']);
                         if ($row) {
                             $row->googleId = $authData['auth']['uid'];
                             $row->save();
                         }
                     }
                 }
                 break;
             default:
                 throw new Zend_Controller_Action_Exception('Incorrect provider.');
                 break;
         }
         //Create user
         if (!$row) {
             if ($users->getByLogin($authData['auth']['info']['nickname'])) {
                 //Is not allow nickname
                 throw new Zend_Controller_Action_Exception('Login is occupied.');
             } else {
                 //Is allow nickname
                 $row = $users->createRow();
                 //Insert user data if exist
                 if (isset($authData['auth']['info']['nickname'])) {
                     $row->login = $authData['auth']['info']['nickname'];
                 }
                 if (isset($authData['auth']['info']['email'])) {
                     $row->email = $authData['auth']['info']['email'];
                 }
                 if (isset($authData['auth']['info']['first_name'])) {
                     $row->firstname = $authData['auth']['info']['first_name'];
                 }
                 if (isset($authData['auth']['info']['last_name'])) {
                     $row->lastname = $authData['auth']['info']['last_name'];
                 }
                 //service userId
                 $row->{$serviceFieldName} = $authData['auth']['uid'];
                 $row->role = Users_Model_User::ROLE_USER;
                 $row->status = Users_Model_User::STATUS_ACTIVE;
                 $row->save();
             }
         }
         $row->login();
         $this->_helper->flashMessenger->addMessage('Now You\'re Logging!');
         $this->_helper->redirector(false, false, false);
     } else {
         throw new Zend_Controller_Action_Exception('Invalid auth response.');
     }
 }
示例#5
0
 /**
  * Author's blog rss
  *
  * @throws Zend_Controller_Action_Exception
  */
 public function authorAction()
 {
     $limit = 10;
     if (!($login = $this->_getParam('login'))) {
         throw new Zend_Controller_Action_Exception('Page not found');
     }
     $users = new Users_Model_User_Table();
     if (!($user = $users->getByLogin($login))) {
         throw new Zend_Controller_Action_Exception('Page not found');
     }
     $url = $this->_helper->url;
     $serverUrl = $this->_request->getScheme() . '://' . $this->_request->getHttpHost();
     $title = ucfirst($user->login) . "'s Blog Rss Feed";
     $link = $url->url(array('login' => $user->login), 'blogauthor');
     $feed = new Zend_Feed_Writer_Feed();
     $feed->setTitle($title);
     $feed->setLink($serverUrl . $link);
     $feed->setFeedLink('http://www.example.com/atom', 'atom');
     $feed->addAuthor(array('name' => 'Blog Owner Name', 'email' => $user->email, 'uri' => $serverUrl));
     $posts = new Blog_Model_Post_Table();
     $select = $posts->getSelect(null, $user->id);
     $feed->setDateModified(time());
     foreach ($posts->fetchAll($select->limit($limit)) as $i => $row) {
         if (0 == $i) {
             $feed->setDateModified(strtotime($row->updated));
         }
         $postUrl = $url->url(array('alias' => $row->alias), 'blogpost');
         $entry = $feed->createEntry();
         $entry->setTitle($row->title);
         $entry->setLink($serverUrl . $postUrl);
         $entry->addAuthor($row->login, null, null);
         $entry->setDateModified(strtotime($row->updated));
         $entry->setDateCreated(strtotime($row->published));
         $entry->setDescription($row->teaser);
         $feed->addEntry($entry);
     }
     echo $feed->export('atom');
 }