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)); }
/** * 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); }
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'))); }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aUser !== null) { if ($this->aUser->isModified() || $this->aUser->isNew()) { $affectedRows += $this->aUser->save($con); } $this->setUser($this->aUser); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } if ($this->postsScheduledForDeletion !== null) { if (!$this->postsScheduledForDeletion->isEmpty()) { PostQuery::create()->filterByPrimaryKeys($this->postsScheduledForDeletion->getPrimaryKeys(false))->delete($con); $this->postsScheduledForDeletion = null; } } if ($this->collPosts !== null) { foreach ($this->collPosts as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
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)); }
/** * 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)); }
{ 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); } for ($i = 0; $i <= 20; $i++) { $post = new Post();
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aUser !== null) { if ($this->aUser->isModified() || $this->aUser->isNew()) { $affectedRows += $this->aUser->save($con); } $this->setUser($this->aUser); } if ($this->aCategory !== null) { if ($this->aCategory->isModified() || $this->aCategory->isNew()) { $affectedRows += $this->aCategory->save($con); } $this->setCategory($this->aCategory); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } $this->alreadyInSave = false; } return $affectedRows; }