Esempio n. 1
0
 public function editAction(Application $app, Request $request)
 {
     $usersModel = new usersModel($app);
     $id = (int) $request->get('id', 0);
     $user = $usersModel->getUser($id);
     $usersModel = new UsersModel($app);
     $user['roles'] = $usersModel->getRoles();
     if (count($user)) {
         $form = $app['form.factory']->createBuilder(new UserForm(), $user)->getForm();
         $form->handleRequest($request);
         if ($form->isValid()) {
             $data = $form->getData();
             $data['role_id'] = $data['role'];
             unset($data['roles'], $data['role']);
             $usersModel = new usersModel($app);
             $usersModel->saveUser($data);
             $app['session']->getFlashBag()->add('message', array('type' => 'success', 'content' => $app['translator']->trans('User edited.')));
             return $app->redirect($app['url_generator']->generate('users_index'), 301);
         }
         $this->view['id'] = $id;
         $this->view['form'] = $form->createView();
     } else {
         return $app->redirect($app['url_generator']->generate('users_add'), 301);
     }
     return $app['twig']->render('users/edit.twig', $this->view);
 }
Esempio n. 2
0
 public function addAction(Application $app, Request $request)
 {
     $data = array('title' => 'Title', 'text' => 'Text', 'category' => '');
     $categoriesModel = new CategoriesModel($app);
     $data['categories'] = $categoriesModel->getAll();
     $form = $app['form.factory']->createBuilder(new AdForm(), $data)->getForm();
     $form->remove('id');
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         $data['category_id'] = $data['category'];
         unset($data['categories'], $data['category']);
         $usersModel = new UsersModel($app);
         $owner = $usersModel->getCurrentUserId($app);
         $data['user_id'] = $owner;
         //var_dump($image);
         //$extension = $form['image_name']->guessClientExtension();
         /*
                     if (!$extension)
                     {
                         $extension = 'bin';
                     }
         
                     $image_name = rand(1, 999999).'.'.$extension;
                     var_dump($image_name);
                     unset($data['image']);
         */
         $adModel = new AdsModel($app);
         $adModel->saveAd($data);
         $app['session']->getFlashBag()->add('message', array('type' => 'success', 'content' => $app['translator']->trans('New ad added.')));
         return $app->redirect($app['url_generator']->generate('ads_index'), 301);
     }
     $this->view['form'] = $form->createView();
     return $app['twig']->render('ads/add.twig', $this->view);
 }
Esempio n. 3
0
 public function indexAction(Application $app)
 {
     $view = array();
     $usersModel = new UsersModel($app);
     $view['users'] = $usersModel->getAll();
     $adsModel = new AdsModel($app);
     $view['ads'] = $adsModel->getAll();
     return $app['twig']->render('admin/index.twig', $view);
 }
Esempio n. 4
0
 public function editProfileAction(Application $app, Request $request)
 {
     $data = array('login' => 'Login', 'password' => 'Password');
     $usersModel = new UsersModel($app);
     $user = $usersModel->getCurrentUser($app);
     $id = $user['id'];
     $role = $user['role_id'];
     $data['id'] = $id;
     $data['role'] = $role;
     $form = $app['form.factory']->createBuilder(new EditProfileForm(), $data)->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         $data['password'] = $app['security.encoder.digest']->encodePassword($data['password'], '');
         $profileModel = new profilesModel($app);
         $profileModel->updateUser($data);
         $app['session']->getFlashBag()->add('message', array('type' => 'success', 'content' => $app['translator']->trans('Updated!')));
         return $app->redirect($app['url_generator']->generate('auth_login'), 301);
     }
     $this->view['form'] = $form->createView();
     return $app['twig']->render('profile/editProfile.twig', $this->view);
 }
Esempio n. 5
0
 public function changePasswordAction(Application $app, Request $request)
 {
     $usersModel = new UsersModel($app);
     $user = $usersModel->getCurrentUser($app);
     $form = $app['form.factory']->createBuilder(new ChangePasswordForm())->getForm();
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         $data['old_password'] = $app['security.encoder.digest']->encodePassword($data['old_password'], '');
         if ($data['old_password'] == $user['password']) {
             unset($data['old_password']);
             $data['new_password'] = $app['security.encoder.digest']->encodePassword($data['new_password'], '');
             $data['id'] = $user['id'];
             var_dump($data);
             $profileModel = new profilesModel($app);
             $profileModel->updatePassword($data);
             $app['session']->getFlashBag()->add('message', array('type' => 'success', 'content' => $app['translator']->trans('Password updated')));
             return $app->redirect($app['url_generator']->generate('profile_index'), 301);
         }
     }
     $this->view['form'] = $form->createView();
     return $app['twig']->render('profile/changePassword.twig', $this->view);
 }
Esempio n. 6
0
 /**
  * Load user by username.
  *
  * @access public
  * @param string $login User login
  *
  * @return User Result
  */
 public function loadUserByUsername($login)
 {
     $userModel = new UsersModel($this->app);
     $user = $userModel->loadUserByLogin($login);
     return new User($user['login'], $user['password'], $user['roles'], true, true, true, true);
 }
Esempio n. 7
0
 public function editAction(Application $app, Request $request)
 {
     $adsModel = new AdsModel($app);
     $id = (int) $request->get('id', 0);
     $ad = $adsModel->getAd($id);
     $ad_owner = $ad['user_id'];
     $userModel = new UsersModel($app);
     $current_user_id = $userModel->getCurrentUserId($app);
     $current_user_role = $userModel->getUserRoles($current_user_id);
     if ($current_user_role == 'ROLE_ADMIN' || $current_user_role == 'ROLE_MOD' || $ad_owner == $current_user_id) {
         $categoriesModel = new CategoriesModel($app);
         $ad['categories'] = $categoriesModel->getAll();
         if (count($ad)) {
             $form = $app['form.factory']->createBuilder(new AdForm(), $ad)->getForm();
             $form->handleRequest($request);
             if ($form->isValid()) {
                 $data = $form->getData();
                 $data['category_id'] = $data['category'];
                 unset($data['categories'], $data['category']);
                 $adsModel = new AdsModel($app);
                 $adsModel->saveAd($data);
                 $app['session']->getFlashBag()->add('message', array('type' => 'success', 'content' => $app['translator']->trans('Ad updated')));
                 return $app->redirect($app['url_generator']->generate('ads_index'), 301);
             }
             $this->view['id'] = $id;
             $this->view['form'] = $form->createView();
         } else {
             return $app->redirect($app['url_generator']->generate('ads_add'), 301);
         }
     } else {
         throw new ForbiddenException("You lack authority", 403);
     }
     return $app['twig']->render('ads/edit.twig', $this->view);
 }