/** * 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(); }
public function setUp() { parent::setUp(); $this->_fixture['post'] = array('id' => 45, 'title' => 'title', 'body' => 'text', 'categoryId' => 33, 'userId' => 75, 'status' => 'active'); $this->_fixture['category'] = array('id' => 33, 'title' => 'title', 'description' => 'descr', 'parentId' => 0, 'alias' => 'title'); $users = new Users_Model_User_Table(); $user = $users->createRow(array('id' => 75, 'login' => 'asdasd', 'email' => '*****@*****.**', 'password' => '123456')); $user->save(); }
public function setUp() { parent::setUp(); $this->_fixture['post'] = array('id' => 55, 'title' => 'title', 'body' => 'text', 'categoryId' => 43, 'alias' => 'test1', 'userId' => 75, 'status' => 'published'); $this->_fixture['post2'] = array('id' => 56, 'title' => 'title2', 'body' => 'text2', 'categoryId' => 44, 'alias' => 'test2', 'userId' => 75, 'status' => 'published'); $this->_fixture['category'] = array('id' => 43, 'title' => 'title', 'description' => 'descr', 'parentId' => 0, 'alias' => 'title'); $this->_fixture['category2'] = array('id' => 44, 'title' => 'title2', 'description' => 'descr2', 'parentId' => 0, 'alias' => 'title2'); $this->_fixture['user'] = array('id' => 75, 'login' => 'test_login', 'password' => '123456', 'email' => '*****@*****.**'); $users = new Users_Model_User_Table(); $users->delete(' id = ' . $this->_fixture['user']['id']); $user = $users->createRow($this->_fixture['user']); $user->save(); }
/** * 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); }
/** * @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.'); } }