public function actionActivation($guid = '')
 {
     $formActivation = new UserActivationForm();
     if (empty($guid) && isset($_POST['UserActivationForm'])) {
         $formActivation->attributes = $_POST['UserActivationForm'];
         if (!$formActivation->validate()) {
             //haven't passed validators
             Yii::app()->user->setFlash('error', Yii::t('AuthModule.main', 'Incorrect data in activation form'));
             $this->redirect(array('user/activation'));
             return;
         }
         $guid = $formActivation->guid;
     }
     if (!empty($guid)) {
         $user_id = $this->getValidationByGuid($guid, self::VALIDATOR_ACTIVATE);
         if ($user_id == null) {
             Yii::app()->user->setFlash('error', Yii::t('AuthModule.main', 'ID not found'));
             $this->redirect(array('user/activation'));
             return;
         }
         $modelUser = $this->LoadModel($user_id);
         if ($modelUser->activated) {
             Yii::app()->user->setFlash('warning', Yii::t('AuthModule.main', 'User already activated'));
             $this->redirect(array('user/login'));
             return;
         }
         $licenceKey = AuthCommon::generateLicenceKey();
         $modelUser->licence_key = $licenceKey;
         $modelUser->activated = true;
         $modelUser->setScenario('activation');
         if ($modelUser->saveModel()) {
             Yii::app()->user->setFlash('success', Yii::t('AuthModule.main', 'User successfully activated'));
             $this->deleteRestoreGuid($guid, self::VALIDATOR_ACTIVATE);
             $loginForm = new LoginForm();
             $loginForm->username = $modelUser->username;
             $this->redirect(array('user/login'), array('model' => $loginForm));
             return;
         }
     } else {
         $formActivation->guid = $guid;
         $this->render('activation', array('model' => $formActivation));
     }
 }
Exemplo n.º 2
0
 public function executeGetPassword(sfWebRequest $request)
 {
     $this->forward404Unless($this->user = $this->getRoute()->getObject());
     $form = new UserActivationForm();
     //$this->user = $this->getRoute()->getObject();
     new User();
     $form->bind($request->getParameter($form->getName()));
     if ($form->isValid()) {
         $data = $form->getValues();
         if ($data['login_check'] == $this->user->getLogin()) {
             if ($this->user->getActivationCode() == '') {
                 $this->redirect('@homepage');
             }
             $this->password = $this->user->generatePassword();
             $this->user->setPassword($this->password);
             $this->user->setActivationCode('');
             $this->user->setActive(true);
             // Generate Image
             $this->user->generateImg();
             $this->user->save();
             // Init Image URL
             $this->imgUrl = sfConfig::get('app_secret_img_url_dir') . '/' . $this->user->getImgFileName() . '?p=' . rand(1, 990000);
         } else {
             $this->redirect('@homepage');
         }
     } else {
         $this->redirect('@homepage');
     }
 }