/**
  * Validate form param by ajax
  *
  */
 public function validateAction()
 {
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $table = new Users_Model_User_Table();
     $row = null;
     if ($id = $this->_getParam('id')) {
         $row = $table->getById($id);
     }
     if (!$row) {
         $row = $table->createRow();
         $form = new Users_Form_Users_Create();
     } else {
         $form = new Users_Form_Users_Edit();
         $form->populate($row->toArray());
     }
     $form->populate($this->_getAllParams());
     if ($field = $this->_getParam('validateField')) {
         $element = $form->getElement($field);
         $response = array('success' => $element->isValid($this->_getParam($field)), 'message' => $this->view->formErrors($element->getMessages()));
     } else {
         $response = array('success' => $form->isValid($this->_getAllParams()), 'message' => $this->view->formErrors($form->getMessages()));
     }
     if (APPLICATION_ENV != 'production') {
         $response['params'] = $this->_getAllParams();
     }
     echo $this->_helper->json($response);
 }
 /**
  * Setup TestCase
  */
 public function setUp()
 {
     parent::setUp();
     $this->_fixture = array('login' => 'admin' . time(), 'email' => '*****@*****.**', 'role' => Users_Model_User::ROLE_ADMIN, 'status' => Users_Model_User::STATUS_ACTIVE, 'password' => '123456');
     $manager = new Users_Model_User_Table();
     $this->_user = $manager->createRow($this->_fixture);
     $this->_user->save();
 }
示例#3
0
 /**
  * Get comments select by commentAlias row
  *
  * @param Comments_Model_CommentAlias $commentAlias
  * @param                             $userId
  * @param int                         $key
  * @return Zend_Db_Select
  */
 public function getSelect(Comments_Model_CommentAlias $commentAlias, $userId, $key = 0)
 {
     $users = new Users_Model_User_Table();
     $select = $this->getDbTable()->select(true);
     $select->setIntegrityCheck(false)->joinLeft(array('u' => $users->info('name')), 'userId = u.id', array('login', 'avatar', 'email', 'firstname', 'lastname'))->where('aliasId = ?', $commentAlias->id)->where('comments.status = "' . Comments_Model_Comment::STATUS_ACTIVE . '"' . ' OR (comments.status != "' . Comments_Model_Comment::STATUS_ACTIVE . '"' . ' AND comments.userId = ?)', $userId);
     if ($commentAlias->isKeyRequired()) {
         $select->where('comments.key = ?', $key);
     }
     $select->order('created ASC');
     return $select;
 }
示例#4
0
 /**
  * User Combobox
  *
  * @return Zend_Form_Element_Select
  */
 protected function _user()
 {
     $users = new Users_Model_User_Table();
     $res = array();
     foreach ($users->fetchAll() as $row) {
         $res[$row->id] = $row->login;
     }
     $element = new Zend_Form_Element_Select('userId');
     $element->setLabel('Author')->setRequired(true)->setAttribs(array('class' => 'span2'))->addMultioptions($res);
     return $element;
 }
示例#5
0
 /**
  * Get posts
  *
  * @param integer $categoryId
  * @return Zend_Db_Table_Select
  */
 public function getPostsSelect($categoryId = null)
 {
     $users = new Users_Model_User_Table();
     $select = $this->select()->from(array('p' => $this->_name), array('*'));
     $select->setIntegrityCheck(false)->joinLeft(array('u' => $users->info('name')), 'userId=u.id', array('author' => 'login'));
     $select->order('p.created DESC');
     $select->group('p.id');
     $select->where('p.status=?', Forum_Model_Post::STATUS_ACTIVE);
     if ($categoryId) {
         $select->where('categoryId=?', $categoryId);
     }
     return $select;
 }
 /**
  * The default action - show the home page
  */
 public function editAction()
 {
     $identity = Zend_Auth::getInstance()->getIdentity();
     $users = new Users_Model_User_Table();
     $row = $users->getById($identity->id);
     $form = new Users_Form_Users_Profile();
     $form->setUser($row);
     if ($this->_request->isPost() && $form->isValid($this->_getAllParams())) {
         $row->setFromArray($form->getValues());
         $row->save();
         $row->login(false);
         $this->_helper->flashMessenger('Profile Updated');
         $this->_helper->redirector('index');
     }
     $this->view->form = $form;
 }
示例#7
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;
 }
示例#8
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');
 }
示例#9
0
 /**
  * View post
  *
  * @throws Zend_Controller_Action_Exception
  */
 public function indexAction()
 {
     if (!($postId = $this->_getParam('id'))) {
         $this->_forwardNotFound();
         return;
     }
     $posts = new Forum_Model_Post_Table();
     if (!($post = $posts->getById($postId))) {
         $this->_forwardNotFound();
         return;
     }
     $users = new Users_Model_User_Table();
     $this->view->author = $users->getById($post->userId);
     $categories = new Categories_Model_Category_Table();
     $this->view->category = $categories->getById($post->categoryId);
     /** update count view */
     $post->incViews();
     $this->view->post = $post;
 }
示例#10
0
 /**
  * View post
  *
  * @throws Zend_Controller_Action_Exception
  */
 public function indexAction()
 {
     if (!($alias = $this->_getParam('alias'))) {
         $this->_forwardNotFound();
         return;
     }
     $posts = new Blog_Model_Post_Table();
     if (!($row = $posts->getByAlias($alias))) {
         $this->_forwardNotFound();
         return;
     }
     $users = new Users_Model_User_Table();
     $this->view->user = $users->getById($row->userId);
     $categories = new Categories_Model_Category_Table();
     $this->view->category = $categories->getById($row->categoryId);
     /** update count view */
     $row->incViews();
     $this->view->row = $row;
     $this->view->page = $this->_getParam('page');
 }
示例#11
0
 /**
  * Get Zend_Db_Table_Select
  *
  * @param object|integer $category
  * @param integer $author
  * @param string  $date
  * @return Zend_Db_Table_Select
  */
 public function getSelect($category = null, $author = null, $date = 'NOW')
 {
     $users = new Users_Model_User_Table();
     $categories = new Categories_Model_Category_Table();
     $select = $this->select()->setIntegrityCheck(false);
     $select->from(array('p' => $this->_name), array('*'))->joinLeft(array('u' => $users->info('name')), 'p.userId = u.id', array('login'))->joinLeft(array('c' => $categories->info('name')), 'c.id = p.categoryId', array('categoryTitle' => 'title', 'categoryAlias' => 'alias'))->group('p.id')->where('p.status=?', Blog_Model_Post::STATUS_PUBLISHED)->order('published DESC');
     if ($date) {
         if ('NOW' == $date) {
             $date = date('Y-m-d H:i:s');
         }
         $select->where('published <=?', $date);
     }
     if ($category) {
         if (!$category instanceof Zend_Db_Table_Row_Abstract) {
             $manager = new Blog_Model_Category_Manager();
             $category = $manager->getById($category);
         }
         //$separator = Categories_Model_Category::PATH_SEPARATOR;
         $select->where('c.path LIKE ?', '%' . $category->alias . '%');
     }
     return $select;
 }
示例#12
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');
 }
 /**
  * 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);
 }
 /**
  * Migrations Action
  */
 public function migrationsAction()
 {
     $config = $this->_store->config->production->resources->db;
     $db = Zend_Db::factory($config);
     Zend_Db_Table_Abstract::setDefaultAdapter($db);
     $options = array('projectDirectoryPath' => APPLICATION_PATH . '/..', 'modulesDirectoryPath' => APPLICATION_PATH . '/modules');
     $manager = new Core_Migration_Manager($options);
     $manager->up();
     $pathToModules = APPLICATION_PATH . '/modules/';
     foreach ($this->_store->modules as $module => $value) {
         //up installed modules migrations
         if ($value === false) {
             $pathToModule = $pathToModules . $module;
             if (is_dir($pathToModules) && is_writable($pathToModules) && is_dir($pathToModule)) {
                 rename($pathToModule, APPLICATION_PATH . '/modules/.' . $module);
             }
         } else {
             $manager->up($module);
             if ($module === 'menu') {
                 $this->_store->config->production->resources->navigation->source->default = 'db';
             }
         }
     }
     unset($this->_store->modules);
     $usersTable = new Users_Model_User_Table();
     //update or create admin
     if (!$usersTable->update($this->_store->user, 'login = "******"')) {
         $usersTable->insert($this->_store->user);
     }
     unset($this->_store->user);
     $this->_helper->flashMessenger('Migrations rolled up');
     $this->_store->progress['install-index-migrations'] = true;
     $this->_helper->redirector('index');
     $this->view->currentPage = 'install-index-migrations';
 }
示例#15
0
 public function tearDown()
 {
     $table = new Blog_Model_Post_Table();
     $table->delete('1');
     $table = new Categories_Model_Category_Table();
     $table->delete(' id = 43');
     $table = new Users_Model_User_Table();
     $table->delete(' id = ' . $this->_fixture['user']['id']);
 }
示例#16
0
 public function tearDown()
 {
     $table = new Users_Model_User_Table();
     $table->delete('1');
     /* delete all */
     $table = new Forum_Model_Post_Table();
     $table->delete('1');
     /* delete all */
     //        $table = new Comments_Model_Comment_Table();
     //        $table->delete('1'); /* delete all */
     $table = new Categories_Model_Category_Table();
     $table->delete('id = 33');
     parent::tearDown();
 }
示例#17
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.');
     }
 }