Example #1
0
 /**
  * Update users profile(password)
  *
  * @return \Framework\Response\Response|\Framework\Response\ResponseRedirect
  * @throws SecurityException
  */
 public function updateAction()
 {
     $route = Service::get('route');
     if (Service::get('security')->isAuthenticated()) {
         if ($this->getRequest()->isPost()) {
             $user = Service::get('session')->get('user');
             if ($user->password == $this->getRequest()->post('password') && $this->getRequest()->post('newpassword1') == $this->getRequest()->post('newpassword2')) {
                 try {
                     $us = new User();
                     $us->email = $user->email;
                     $us->password = md5($this->getRequest()->post('newpassword1'));
                     $us->role = $user->role;
                     $us->update('email', $user->email);
                     return $this->redirect($this->generateRoute('profile'), 'The password update successfully');
                 } catch (DatabaseException $e) {
                     $errors = array($e->getMessage());
                 }
             } else {
                 return $this->redirect($this->getRequest()->getUri(), 'Password mismatch', 'error');
             }
         } else {
             return $this->getAction();
         }
     } else {
         throw new SecurityException('Please, login', $route->buildRoute('login'));
     }
     return $this->render('updateprofile.html', array('errors' => $errors));
 }
 public function signinAction()
 {
     if (Service::get('security')->isAuthenticated()) {
         return new ResponseRedirect($this->generateRoute('home'));
     }
     $errors = array();
     if ($this->getRequest()->isPost()) {
         try {
             if ($user_mas = User::findByEmail($this->getRequest()->post('email'))) {
                 array_push($errors, 'This email is already register!');
                 return $this->render('signin.html', array('errors' => $errors));
             } else {
                 $user = new User();
                 $user->email = $this->getRequest()->post('email');
                 $user->password = $this->getRequest()->post('password');
                 $user->role = 'ROLE_USER';
                 $user->save();
                 $user_mas = User::findByEmail($this->getRequest()->post('email'));
                 Service::get('security')->setUser($user_mas);
                 return $this->redirect($this->generateRoute('home'));
             }
         } catch (DatabaseException $e) {
             $errors = array($e->getMessage());
         }
     }
     return $this->render('signin.html', array('errors' => $errors));
 }
Example #3
0
 public function install()
 {
     $post = new Post();
     $user = new User();
     $category = new Category();
     $postcategory = new PostCategory();
     Model::execute($category->install());
     Model::execute($user->install());
     Model::execute($post->install());
     Model::execute($postcategory->install());
 }
 /**
  * Serves for updating profile
  *
  * @route /profile
  * @return \Framework\Response\Response|\Framework\Response\ResponseRedirect
  */
 function updateAction()
 {
     if ($this->getRequest()->isPost()) {
         try {
             $user = new User();
             $user->id = (int) $this->getRequest()->post('id');
             $user->email = $this->getRequest()->post('email');
             $user->password = $this->getRequest()->post('password');
             $user->role = 'ROLE_USER';
             $user->save();
             Service::get('security')->clear();
             return $this->redirect($this->generateRoute('login'), 'The user data has been update successfully');
         } catch (DatabaseException $e) {
             $error = $e->getMessage();
         }
     }
     $currentUser = Service::get('security')->getUser();
     $userEmail = $currentUser->email;
     $user = User::findByEmail($userEmail);
     $segments = explode('@', $userEmail);
     $user->name = $segments[0];
     $date['updateUser'] = $user;
     $date['action'] = $this->generateRoute('profile');
     $date['errors'] = isset($error) ? $error : null;
     return $this->render('update.html', $date);
 }
 public function signinAction()
 {
     if (Service::get('security')->isAuthenticated()) {
         return new ResponseRedirect(Service::get('router')->buildRoute('home'));
     }
     $errors = array();
     if ($this->getRequest()->isPost()) {
         try {
             $user = new User();
             $user->email = $this->getRequest()->post('email');
             $user->password = $this->getRequest()->post('password');
             $user->role = 'ROLE_USER';
             $user->save();
             return $this->redirect($this->generateRoute('home'));
         } catch (DatabaseException $e) {
             $errors = array($e->getMessage());
         }
     }
     return $this->render('signin.html', array('errors' => $errors));
 }
Example #6
0
 public function indexAction()
 {
     $posts = Post::find('all');
     $out_posts = array();
     foreach ($posts as $post) {
         $user = User::findById($post->users_id);
         $post->name = $user->name ? $user->name : 'NoNaMe person';
         $out_posts[] = $post;
     }
     return $this->render('index.html', array('posts' => $out_posts));
 }
Example #7
0
 /**
  * Update action
  *
  * @return ResponseRedirect|\Framework\Response\Response|\Framework\Response\ResponseRedirect
  */
 public function updateAction()
 {
     $errors = array();
     if ($this->getRequest()->isPost()) {
         try {
             $user = new User();
             $user->id = $this->getRequest()->post('id');
             $user->name = $this->getRequest()->post('name');
             $user->email = $this->getRequest()->post('email');
             $user->password = md5($this->getRequest()->post('password'));
             $user->role = $this->getRequest()->post('user_role');
             if ($user->save()) {
                 Service::get('security')->setUser($user);
             }
             return $this->render('profile.html', array('success' => 'The post has been updated successfully!'));
         } catch (DatabaseException $e) {
             $errors = array($e->getMessage());
         }
     }
     return $this->render('profile.html', array('errors' => $errors));
 }
 /**
  * Edits user profile
  * @return \Framework\Response\ResponseRedirect
  */
 public function updateAction()
 {
     $errors = array();
     if ($this->getRequest()->isPost()) {
         try {
             $user = User::find($this->getRequest()->post('id'));
             $user->role = $this->getRequest()->post('role');
             $user->email = $this->getRequest()->post('email');
             $user->save();
             Service::get('security')->setUser($user);
         } catch (DatabaseException $e) {
             $errors = array($e->getMessage());
         }
     }
     return $this->redirect($this->generateRoute('profile'));
 }
 /**
  * @return \Framework\Response\Response|\Framework\Response\ResponseRedirect
  * @throws \Framework\Exception\DatabaseException
  * @throws \Framework\Exception\ServiceException
  */
 public function updateAction()
 {
     $isEmailUpdated = false;
     $isPasswordUpdated = false;
     $updateMessage = '';
     try {
         $user = Service::get('security')->getUser();
         $oldUser = User::find($user->id);
         $newPassword = $this->getRequest()->post('newPassword');
         $newEmail = $this->getRequest()->post('newEmail');
         if (!empty($newEmail) && $newEmail != $oldUser->email) {
             $user->email = $newEmail;
             $isEmailUpdated = true;
             $updateMessage .= 'email ';
         }
         if (!empty($newPassword) && !Service::get('security')->isPasswordMatch($newPassword, $oldUser)) {
             $soplPass = Service::get('security')->getSoltedPassword($newPassword);
             $user->password = $soplPass['soltedPassword'];
             $user->solt = $soplPass['solt'];
             $isPasswordUpdated = true;
             if (!empty($updateMessage)) {
                 $updateMessage .= 'and ';
             }
             $updateMessage .= 'password ';
         }
         if (!$isEmailUpdated && !$isPasswordUpdated) {
             return $this->redirect($this->generateRoute('home'), 'You don\' change data.');
         } else {
             if (!$isEmailUpdated) {
                 unset($user->email);
             } else {
                 if (!$isPasswordUpdated) {
                     unset($user->password);
                     unset($user->solt);
                 }
             }
         }
         Service::get('security')->setUser($oldUser);
         $user->save();
         return $this->redirect($this->generateRoute('logout'), 'Data: ' . $updateMessage . 'has been changet succesfully. Please login again.');
     } catch (DatabaseException $e) {
         $error = $e->getMessage();
         return $this->render('update.html', array('user' => $oldUser, 'errors' => isset($error) ? $error : null, 'action' => $this->generateRoute('update_profile'), 'src' => array('src' => 'Blog', 'controller' => 'Security')));
     }
 }
Example #10
0
 function updateAction()
 {
     if ($this->getRequest()->isPost()) {
         try {
             $user = new User();
             $user->id = (int) $this->getRequest()->post('id');
             $user->email = $this->getRequest()->post('email');
             $user->password = $this->getRequest()->post('password');
             $user->role = 'ROLE_USER';
             $user->save();
             Service::get('security')->clear();
             return $this->redirect($this->generateRoute('home'), 'The user data has been update successfully <br>Please login again!');
         } catch (DatabaseException $e) {
             $error = $e->getMessage();
         }
     }
     $user = User::findByEmail(Service::get('session')->userEmail);
     return $this->render('update.html', array('updateUser' => $user, 'action' => $this->generateRoute('profile')));
 }
Example #11
0
 public function updateAction()
 {
     if (!Service::get('request')->isPost()) {
         throw new \Exception('Hack attempt');
     }
     if (!Service::get('security')->isAuthenticated()) {
         return $this->redirect('login', 'Please Login');
     }
     $errors = [];
     $userId = (int) $this->getRequest()->post('id');
     try {
         User::where(['id' => $userId])->update(['email' => $this->getRequest()->post('email'), 'password' => $this->getRequest()->post('password')]);
     } catch (DatabaseException $e) {
         $errors[] = $e->getMessage();
     }
     $userId = Service::get('security')->getUser()->id;
     $user = User::find((int) $userId);
     Service::get('security')->setUser($user);
     return $this->render('profile.html', ['user' => $user, 'action' => $this->generateRoute('update_profile'), 'errors' => isset($errors) ? $errors : null]);
 }
 /**
  * Filter the query by a related User object
  *
  * @param     User|PropelCollection $user The related object(s) to use as filter
  * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return    PostQuery The current query, for fluid interface
  */
 public function filterByUser($user, $comparison = null)
 {
     if ($user instanceof User) {
         return $this->addUsingAlias(PostPeer::USER_ID, $user->getId(), $comparison);
     } elseif ($user instanceof PropelCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(PostPeer::USER_ID, $user->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByUser() only accepts arguments of type User or PropelCollection');
     }
 }
 /**
  * Exclude object from result
  *
  * @param     User $user Object to remove from the list of results
  *
  * @return    UserQuery The current query, for fluid interface
  */
 public function prune($user = null)
 {
     if ($user) {
         $this->addUsingAlias(UserPeer::ID, $user->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
// init Propel
Propel::init(__DIR__ . '/config/conf/Blog-conf.php');
function writeln($object)
{
    echo sprintf('Created "%s" with id "%s"', get_class($object), $object->getId()) . PHP_EOL;
}
// create data resolver provider instance
$provider = new DataResolverProvider();
$provider->addDataResolver(new UserResolver());
$provider->addDataResolver(new PostResolver());
$provider->addDataResolver(new CategoryResolver());
// create action manager instance
$actionManager = new ActionManager($provider);
// create fixtures
foreach (array('john', 'tobi', 'adam') as $id => $username) {
    $user = new User();
    $user->setUsername($username);
    // save user
    $user->save();
    writeln($user);
}
foreach (array('Web', 'Life', 'Open Source', 'PHP') as $value) {
    $category = new Category();
    $category->setName($value);
    $user = UserQuery::create()->findPk(rand(1, 3));
    $category->setUser($user);
    // save category
    $category->save();
    // create action
    $actionManager->createAction($category->getUser(), Category::CREATE_CATEGORY, $category);
    writeln($category);
 /**
  * Declares an association between this object and a User object.
  *
  * @param      User $v
  * @return     Post The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setUser(User $v = null)
 {
     if ($v === null) {
         $this->setUserId(NULL);
     } else {
         $this->setUserId($v->getId());
     }
     $this->aUser = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the User object, it will not be re-added.
     if ($v !== null) {
         $v->addPost($this);
     }
     return $this;
 }
Example #16
0
 /**
  * Show user all posts
  *
  * @param $id
  * @return \Framework\Response\ResponseRedirect
  * @throws HttpNotFoundException
  */
 public function showUserPostsAction($id)
 {
     if ($posts = Post::findByUsers_id((int) $id, 50)) {
         $user = User::findById((int) $id);
         $name = $user->name ? $user->name : 'NoNaMe person';
         foreach ($posts as $post) {
             $post->name = $name;
         }
         return $this->render('index.html', array('posts' => $posts));
     } else {
         throw new HttpNotFoundException('Page Not Found!');
     }
 }