public function putAction() { // Getting parameters $params = $this->_helper->param(); // Convert data collection array if not $collection = $this->_helper->array()->isCollection($params['data']) ? $params['data'] : $this->_helper->array()->convertRecordtoCollection($params['data']); // Updating status Doctrine_Manager::connection()->beginTransaction(); try { // Doctrine foreach ($collection as $record) { $user = new Model_Entity_User(); $user->assignIdentifier($record['id']); if (array_key_exists('active', $record)) { $user->set('active', $record['active']); } if (array_key_exists('status', $record)) { $user->set('status', $record['status']); } $user->save(); } Doctrine_Manager::connection()->commit(); unset($user); // Response $this->_helper->response(true, 202)->getResponse(); } catch (Zend_Exception $e) { Doctrine_Manager::connection()->rollback(); throw $e; } catch (Doctrine_Exception $e) { Doctrine_Manager::connection()->rollback(); throw $e; } }
/** * @return void */ public function putAction() { // Params $params = $this->_helper->param(); $userSessionId = Zend_Auth::getInstance()->getIdentity()->id; // Validation $oldPassword = Doctrine_Core::getTable('Model_Entity_User')->find($userSessionId)->password; if ($oldPassword != md5($params['oldPassword'])) { $this->_helper->response()->addError('oldPassword', 'Eski şifreniz yanlış.')->getResponse(); } // Params $userPassword = $params['newPassword']; $userPasswordConfirm = $params['newPasswordConfirm']; // Filter $userPassword = is_null($userPassword) ? null : md5($userPassword); $userPasswordConfirm = is_null($userPasswordConfirm) ? null : md5($userPasswordConfirm); if (!is_null($userPassword) && !is_null($userPasswordConfirm) && $userPasswordConfirm == $userPassword) { $user = new Model_Entity_User(); $user->assignIdentifier($userSessionId); $user->password = $userPassword; $user->save(); $this->_helper->response(true)->addNotification(Kebab_Notification::INFO, 'Password successfully changed.')->getResponse(); } else { $this->_helper->response()->addNotification(Kebab_Notification::ERR, 'Could not change password.')->getResponse(); } }
public function putAction() { // Param $params = $this->_helper->param(); $userSessionId = Zend_Auth::getInstance()->getIdentity()->id; // Validation $fullName = $params['fullName']; $email = $params['email']; $language = $params['language']; //KBBTODO move DQL to model class Doctrine_Manager::connection()->beginTransaction(); try { $userExistsWithEmail = Doctrine_Query::create()->from('Model_Entity_User user')->where('user.email = ?', $email)->andWhere('user.id != ?', $userSessionId)->useQueryCache(Kebab_Cache_Query::isEnable())->fetchOne(); if (is_object($userExistsWithEmail)) { // Another User exists with entered email $this->_helper->response(false, 201)->set('email', 'Another User with email exists.')->getResponse(); } // DQL $profile = new Model_Entity_User(); $profile->assignIdentifier($userSessionId); $profile->fullName = $fullName; $profile->email = $email; $profile->language = $language; $profile->save(); Doctrine_Manager::connection()->commit(); // Reset Session Kebab_Authentication::signOut(); Kebab_Authentication::signIn($profile->userName, $profile->password, false, false); // Response $this->_helper->response(true, 201)->addData(array('userName' => $profile->userName, 'fullName' => $profile->fullName))->getResponse(); unset($profile); } catch (Zend_Exception $e) { Doctrine_Manager::connection()->rollback(); throw $e; } catch (Doctrine_Exception $e) { Doctrine_Manager::connection()->rollback(); throw $e; } }
public static function activate($userName, $password, $fullName, $key) { $retVal = false; Doctrine_Manager::connection()->beginTransaction(); try { $id = Doctrine_Core::getTable('Model_Entity_User')->findOneByactivationKey($key)->id; $user = new Model_Entity_User(); $user->assignIdentifier($id); $user->userName = $userName; $user->fullName = $fullName; $user->password = md5($password); $user->activationKey = NULL; $user->status = 'approved'; $user->active = 1; $user->save(); $userRole = new Model_Entity_UserRole(); $userRole->role_id = 1; $userRole->user_id = $user->id; $userRole->save(); $retVal = Doctrine_Manager::connection()->commit() ? $user : false; unset($userRole); unset($id); } catch (Zend_Exception $e) { Doctrine_Manager::connection()->rollback(); throw $e; } catch (Doctrine_Exception $e) { Doctrine_Manager::connection()->rollback(); throw $e; } return $retVal; }