Ejemplo n.º 1
0
 public function createAction()
 {
     //if($this->getRequest()->isPost()){
     //Récupération des données
     $user = new Application_Model_User();
     $user->setIdUser('1')->setEmailUser('*****@*****.**')->setNomUser('wallace')->setPrenomUser('grommit')->setAdresse1User('1 rue Albert')->setAdresse2User('')->setZipUser('69380')->setPasswordUser('0000')->setNbMaxEmpruntUser('3')->setDelaisEmpruntUser('24')->setServiceUser('')->setDateInscription('27/01/2014')->setBureauUser('')->setParutionIdParution('')->setActifUser('')->setValidMailUser('')->setActivationUser('');
     //Instance du Mapper
     $userMapper = new Application_Model_UserMapper();
     //Save des données
     $userMapper->save($user);
     //Réponse à la vue
     $this->view->success = 'Enregistrement effectué';
     //}
 }
Ejemplo n.º 2
0
 public function regAction()
 {
     $request = $this->getRequest();
     $form = new Application_Form_UserRegistration();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($request->getPost())) {
             $user = new Application_Model_User($form->getValues());
             $user->setUserReg(date('Y-m-d H:i:s', time()))->setUserLastLogin(date('Y-m-d H:i:s', time()));
             $userMapper = new Application_Model_UserMapper();
             $userMapper->save($user);
             return $this->_helper->redirector('index,', 'index');
         }
     }
     $this->view->form = $form;
 }
Ejemplo n.º 3
0
 /**
  * @param Application_Model_User $user The user to save.
  * @return int Either uid of new user or -1
  */
 public function save(Application_Model_UserComplete $user)
 {
     $userArray = array('uid' => -1, 'uname' => $user->__get('Uname'), 'publicKey' => $user->__get('PublicKey'), 'password' => $user->__get('Password'));
     $userDataArray = array('uid' => '', 'forename' => $user->__get('Forename'), 'surname' => $user->__get('Surname'), 'organization' => $user->__get('Organization'), 'email' => $user->__get('Email'), 'streetnr' => $user->__get('Streetnr'), 'zip' => $user->__get('Zip'), 'city' => $user->__get('City'), 'ccode' => $user->__get('Ccode'));
     $user = new Application_Model_User($userArray);
     $userMapper = new Application_Model_UserMapper();
     $uid = $userMapper->save($user);
     // Check if there was any user data given
     $checkEmptyVal = implode('', $userDataArray);
     if (empty($checkEmptyVal)) {
         return;
     }
     $userDataArray['uid'] = $uid;
     $userData = new Application_Model_UserData($userDataArray);
     $userDataMapper = new Application_Model_UserDataMapper();
     $userDataMapper->save($userData);
 }
 public function activateAction()
 {
     if (!$this->getRequest()->getParam('activation_key')) {
         return $this->_redirect('/');
     }
     // check if the activation key is valid
     $user_activation_mapper = new Application_Model_UserActivationMapper();
     $user_activation = $user_activation_mapper->findByActivation_key($this->getRequest()->getParam('activation_key'));
     if ($user_activation) {
         $user_activation = $user_activation[0];
         /**
          * Check if the activation key has not expired (24 hours have not
          * passed)
          */
         $now = date('Y-m-d H:i:s');
         $time_elapsed = abs(strtotime($now) - strtotime($user_activation->getCreated()));
         $time_elapsed = (int) ($time_elapsed / 86400);
         if ($time_elapsed) {
             /**
              * Redirect the user back to the confirmation page to generate a
              * fresh activation key
              */
             return $this->_redirect('/registration/confirm/id' . $user_activation->getUser_id());
         }
         // Check if the user associated with the activation key exists
         $user_mapper = new Application_Model_UserMapper();
         $user = $user_mapper->find($user_activation->getUser_id());
         if (!$user) {
             $user_activation_mapper->delete($user_activation->getId());
             return $this->_redirect('/');
         }
         // Activate the account and delete the obsolete activation key
         $user->setActive(1);
         $user_mapper->save($user);
         $user_activation_mapper->delete($user_activation->getId());
     } else {
         return $this->_redirect('/');
     }
 }
Ejemplo n.º 5
0
 public function resetPasswordAction()
 {
     if (!$this->getRequest()->getParam('password_reset_key')) {
         return $this->_redirect('/auth/forgot-password');
     }
     // check if the reset key is valid
     $password_reset_mapper = new Application_Model_PasswordResetMapper();
     $password_reset = $password_reset_mapper->findByPassword_reset_key($this->getRequest()->getParam('password_reset_key'));
     if ($password_reset) {
         $password_reset = $password_reset[0];
         /**
          * Check if the activation key has not expired (24 hours have not
          * passed)
          */
         $now = date('Y-m-d H:i:s');
         $time_elapsed = abs(strtotime($now) - strtotime($password_reset->getCreated()));
         $time_elapsed = (int) ($time_elapsed / 86400);
         if ($time_elapsed) {
             /**
              * Redirect the user back to the form to generate a fresh reset
              * key
              */
             return $this->_redirect('/auth/forgot-password');
         }
         // check if the user associated with the reset key exists
         $user_mapper = new Application_Model_UserMapper();
         $user = $user_mapper->find($password_reset->getUser_id());
         if (!$user) {
             $password_reset_mapper->delete($password_reset->getId());
             return $this->_redirect('/');
         }
         // process the form
         $form = new Application_Form_PasswordReset();
         if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
             if ($form->getValue('password') == $form->getValue('password_confirm')) {
                 // Hash the password with a random salt
                 $user->setPassword_salt(mcrypt_create_iv(64));
                 $user->setPassword_hash(hash('sha256', $user->getPassword_salt() . $form->getValue('password')));
                 // Save the new password
                 $user_mapper->save($user);
                 $password_reset_mapper->delete($password_reset->getId());
                 print 'Your password has been successfully reset.';
             } else {
                 print "The password was not confirmed.";
                 $form->password_reset_key->setValue($this->getRequest()->getParam('password_reset_key'));
                 $this->view->form = $form;
             }
         } else {
             $form->password_reset_key->setValue($this->getRequest()->getParam('password_reset_key'));
             $this->view->form = $form;
         }
     } else {
         return $this->_redirect('/');
     }
 }
Ejemplo n.º 6
0
 public function editAction()
 {
     $request = $this->getRequest();
     $user_id = get_user_id();
     $user_mapper = new Application_Model_UserMapper();
     $user = $user_mapper->find($user_id);
     $this->view->user = $user;
     if ($request->isPost()) {
         $username = $request->getParam("username");
         $password = $request->getParam("password");
         $about = $request->getParam("about");
         $place = $request->getParam('place');
         if (strlen($username) < 4) {
             $this->_redirect("/user/edit");
         }
         $user_model = new Application_Model_User();
         $user_model->_fields['id'] = $user_id;
         $user_model->_fields['username'] = $username;
         $user_model->_fields['about'] = $about;
         $user_model->_fields['place'] = $place;
         $user_model->_fields['password'] = $password;
         $user_mapper->save($user_model);
         if (isset($_FILES['profile_pic'])) {
             if (is_uploaded_file($_FILES['profile_pic']['tmp_name'])) {
                 if (!move_uploaded_file($_FILES['profile_pic']['tmp_name'], APPLICATION_PATH . "/../public/profile_pic/" . $user_id . '.png')) {
                     $this->_redirect("/user/edit");
                 }
             }
         }
         if (isset($_FILES['cover_pic'])) {
             if (!is_uploaded_file($_FILES['cover_pic']['tmp_name'])) {
                 $this->_redirect("/profile/profile");
             }
             if (!move_uploaded_file($_FILES['cover_pic']['tmp_name'], APPLICATION_PATH . "/../public/cover_pic/" . $user_id . '.png')) {
                 $this->_redirect("/user/edit");
             }
         }
         $this->_redirect("/profile/profile");
     }
 }
Ejemplo n.º 7
0
 /**
  * 
  * Change password 
  */
 public function updateAction()
 {
     // display form
     $request = $this->getRequest();
     $form = new Application_Form_Update();
     // process form
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $userMapper = new Application_Model_UserMapper();
             $auth = Zend_Auth::getInstance();
             $user = new Application_Model_User(get_object_vars($auth->getIdentity()));
             $user->setPassword($form->getValue('password'));
             $userMapper->save($user);
             $form = null;
             $this->view->msg = "Your password has been updated.";
         }
     }
     $this->view->form = $form;
 }
Ejemplo n.º 8
0
 public function editAction()
 {
     if (!Zend_Auth::getInstance()->hasIdentity()) {
         return $this->_redirect('/');
     }
     $user = new Zend_Session_Namespace('user');
     // process the form
     $form = new Application_Form_UserEdit();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($_POST)) {
             /**
              * Because some fields are excluded from the form, they will be
              * set manually
              */
             $id = $user->user['id'];
             $username = $user->user['username'];
             $password_salt = $user->user['password_salt'];
             $password_hash = $user->user['password_hash'];
             if ($form->getValue('password') == $form->getValue('password_confirm')) {
                 /**
                  * Check if the user changed the email to one that is
                  * already in use
                  */
                 $user_mapper = new Application_Model_UserMapper();
                 $email = $user_mapper->findByEmail($form->getValue('email'));
                 $duplicate = false;
                 if ($email) {
                     $email = $email[0];
                     if ($id != $email->getId()) {
                         $duplicate = true;
                     }
                 }
                 if (!$duplicate) {
                     // update the user
                     $values = $form->getValues();
                     $user_mapper = new Application_Model_UserMapper();
                     $user = new Application_Model_User($values);
                     $user->setId($id);
                     $user->setUsername($username);
                     $user->setPassword_salt($password_salt);
                     $user->setPassword_hash($password_hash);
                     $user->setActive(1);
                     $user_mapper->save($user);
                     // update the session
                     $session = new Zend_Session_Namespace('user');
                     $session->user = $user->get_array();
                     $this->_helper->FlashMessenger('Successful Update');
                     return $this->_redirect('/user');
                 } else {
                     print "A user with this email already exists.";
                 }
             } else {
                 print "The password was not confirmed.";
             }
         } else {
             print 'Invalid form';
         }
     }
     // populate the form with the user's information
     $elements = $form->getElements();
     unset($elements['submit']);
     foreach ($elements as $key => $row) {
         $form->{$key}->setValue($user->user[$key]);
     }
     $this->view->form = $form;
 }