Пример #1
0
 public function executePassword()
 {
     if ($this->getRequest()->getMethod() != sfRequest::POST) {
         return sfView::SUCCESS;
     }
     $email = $this->getRequestParameter('email');
     $c = new Criteria();
     $c->add(UserProfilePeer::EMAIL, $email);
     $profile = UserProfilePeer::doSelectOne($c);
     if (!$profile) {
         $this->getRequest()->setError('email', 'There is no user with this email.');
         return sfView::SUCCESS;
     }
     $sfGuardUser = $profile->getSfGuardUser();
     $password = substr(md5(rand(100000, 999999)), 0, 6);
     $sfGuardUser->setPassword($password);
     $this->getRequest()->setAttribute('full_name', $profile->getFullName());
     $this->getRequest()->setAttribute('email', $email);
     $this->getRequest()->setAttribute('username', $sfGuardUser->getUsername());
     $this->getRequest()->setAttribute('password', $password);
     $this->sendEmail('mail', 'forgotPassword');
     $sfGuardUser->save();
     $this->setFlash('info', 'A new password is sent to your email.');
     $this->forward('site', 'message');
 }
 public static function retrieveByConfirmation($key)
 {
     $c = new Criteria();
     $c->add(UserProfilePeer::CONFIRMATION, $key);
     return UserProfilePeer::doSelectOne($c);
 }
Пример #3
0
 public function executeEditProfile()
 {
     if ($this->getRequest()->getMethod() != sfRequest::POST) {
         $user = $this->getUser()->getProfile();
         $this->getRequest()->setParameter('email', $user->getEmail());
         $this->getRequest()->setParameter('first_name', $user->getFirstName());
         $this->getRequest()->setParameter('last_name', $user->getLastName());
         $this->getRequest()->setParameter('gender', $user->getGender());
         $this->getRequest()->setParameter('birthday', $user->getBirthday());
     } else {
         $c = new Criteria();
         $c->add(UserProfilePeer::EMAIL, $this->getRequestParameter('email'));
         $profile = UserProfilePeer::doSelectOne($c);
         if ($profile && $profile->getUserId() != $this->getUser()->getGuardUser()->getId()) {
             $this->getRequest()->setError('email', 'This email belongs to some other user.');
             return sfView::SUCCESS;
         }
         $c = new Criteria();
         $c->add(UserProfilePeer::USER_ID, $this->getUser()->getGuardUser()->getId());
         $profile = UserProfilePeer::doSelectOne($c);
         $profile->setEmail($this->getRequestParameter('email'));
         $profile->setFirstName($this->getRequestParameter('first_name'));
         $profile->setLastName($this->getRequestParameter('last_name'));
         $profile->setGender($this->getRequestParameter('gender'));
         $profile->setBirthday($this->getRequestParameter('birthday'));
         $profile->save();
         $this->setFlash('info', 'User profile saved.');
     }
 }