Esempio n. 1
0
 public function loginAction()
 {
     if (Service::get('security')->isAuthenticated()) {
         $redirect = new ResponseRedirect($this->generateRoute('home'));
         $redirect->send();
     }
     $errors = array();
     if ($this->getRequest()->isPost()) {
         if ($user = User::findByEmail($this->getRequest()->post('email'))) {
             if ($user->password == md5($this->getRequest()->post('password'))) {
                 Service::get('security')->setUser($user);
                 $returnUrl = Service::get('session')->getReturnUrlAndRemove();
                 if ($user->role == 'ROLE_USER') {
                     $about_access = 'view and create posts';
                 } elseif ($user->role == 'ROLE_ADMIN') {
                     $about_access = 'view, create, delete posts';
                 } else {
                     $about_access = 'view posts';
                 }
                 return $this->redirect(!empty($returnUrl) ? $returnUrl : $this->generateRoute('home'), 'info', 'Hello ' . $user->name . '. Now you can ' . $about_access . '.');
             }
         }
         array_push($errors, 'Invalid username or password');
     }
     return $this->render('login.html', array('errors' => $errors));
 }
 public function loginAction()
 {
     if (Service::get('security')->isAuthenticated()) {
         $redirect = new ResponseRedirect($this->generateRoute('home'));
         $redirect->send();
     }
     $errors = array();
     if ($this->getRequest()->isPost()) {
         if ($user = User::findByEmail($this->getRequest()->post('email'))) {
             if ($user->password == md5($this->getRequest()->post('password'))) {
                 Service::get('security')->setUser($user);
                 if ($user->name == 'Guest') {
                     $returnUrl = Service::get('session')->returnUrl;
                     unset(Service::get('session')->returnUrl);
                     return $this->redirect(!is_null($returnUrl) ? $returnUrl : $this->generateRoute('home'), 'info', 'You are login in as ' . $user->name . '. You can only view the posts!');
                 }
                 $returnUrl = Service::get('session')->returnUrl;
                 unset(Service::get('session')->returnUrl);
                 return $this->redirect(!is_null($returnUrl) ? $returnUrl : $this->generateRoute('home'), 'info', 'You are login in as ' . $user->name . '. You can view, add, edit and delete the posts!');
             }
         }
         array_push($errors, 'Invalid username or password');
     }
     return $this->render('login.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));
 }
 /**
  * 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);
 }
Esempio n. 5
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')));
 }
Esempio n. 6
0
 public function loginAction()
 {
     if (Service::get('security')->isAuthenticated()) {
         return new ResponseRedirect($this->generateRoute('home'));
     }
     $errors = array();
     if ($this->getRequest()->isPost()) {
         if ($user = User::findByEmail($this->getRequest()->post('email'))) {
             if ($user->password == $this->getRequest()->post('password')) {
                 Service::get('security')->setUser($user);
                 $returnUrl = Service::get('session')->returnUrl;
                 unset(Service::get('session')->returnUrl);
                 return $this->redirect(!is_null($returnUrl) ? $returnUrl : $this->generateRoute('home'));
             }
         }
         array_push($errors, 'Invalid username or password');
     }
     return $this->render('login.html', array('errors' => $errors));
 }