/**
  * Registration user
  */
 public function actionRegistration()
 {
     //var_dump("test");exit;
     $model = new RegistrationForm();
     $profile = new Profile();
     $profile->regMode = true;
     //var_dump($model);exit;
     // ajax validator
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') {
         echo UActiveForm::validate(array($model, $profile));
         Yii::app()->end();
     }
     //var_dump($_POST['ajax']);exit;
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->profileUrl);
     } else {
         if (isset($_POST['RegistrationForm'])) {
             //var_dump($_POST['RegistrationForm']);exit;
             $model->attributes = $_POST['RegistrationForm'];
             $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array();
             if ($model->validate() && $profile->validate()) {
                 $soucePassword = $model->password;
                 $model->activkey = AdminModule::encrypting(microtime() . $model->password);
                 $model->password = AdminModule::encrypting($model->password);
                 $model->verifyPassword = AdminModule::encrypting($model->verifyPassword);
                 $model->superuser = 0;
                 $model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
                 if ($model->save()) {
                     $profile->user_id = $model->id;
                     $profile->save();
                     if (Yii::app()->controller->module->sendActivationMail) {
                         $activation_url = $this->createAbsoluteUrl('/admin/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email));
                         AdminModule::sendMail($model->email, AdminModule::t("Anda registrasi dari {site_name}", array('{site_name}' => Yii::app()->name)), AdminModule::t("Silahkan Aktifkan akun anda melalui link {activation_url}", array('{activation_url}' => $activation_url)));
                     }
                     if ((Yii::app()->controller->module->loginNotActiv || Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) && Yii::app()->controller->module->autoLogin) {
                         $identity = new UserIdentity($model->username, $soucePassword);
                         $identity->authenticate();
                         Yii::app()->user->login($identity, 0);
                         $this->redirect(Yii::app()->controller->module->returnUrl);
                     } else {
                         if (!Yii::app()->controller->module->activeAfterRegister && !Yii::app()->controller->module->sendActivationMail) {
                             Yii::app()->user->setFlash('registration', AdminModule::t("Terima kasih anda sudah mendaftar. Hubungi Admin untuk mengaktifkan akun anda."));
                         } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) {
                             Yii::app()->user->setFlash('registration', AdminModule::t("Terima kasih anda sudah mendaftar. Silahkan {{login}}.", array('{{login}}' => CHtml::link(AdminModule::t('Login'), Yii::app()->controller->module->loginUrl))));
                         } elseif (Yii::app()->controller->module->loginNotActiv) {
                             Yii::app()->user->setFlash('registration', AdminModule::t("Terima kasih anda sudah mendaftar. Silahkan cek email anda atau login."));
                         } else {
                             Yii::app()->user->setFlash('registration', AdminModule::t("Terima kasih anda sudah mendaftar. Silahkan cek email anda."));
                         }
                         $this->refresh();
                     }
                 }
             } else {
                 $profile->validate();
             }
         }
         $this->render('/user/registration', array('model' => $model, 'profile' => $profile));
     }
 }
 /**
  * Recovery password
  */
 public function actionRecovery()
 {
     $form = new UserRecoveryForm();
     if (Yii::app()->user->id) {
         $this->redirect(Yii::app()->controller->module->returnUrl);
     } else {
         $email = isset($_GET['email']) ? $_GET['email'] : '';
         $activkey = isset($_GET['activkey']) ? $_GET['activkey'] : '';
         if ($email && $activkey) {
             $form2 = new UserChangePassword();
             $find = User::model()->notsafe()->findByAttributes(array('email' => $email));
             if (isset($find) && $find->activkey == $activkey) {
                 if (isset($_POST['UserChangePassword'])) {
                     $form2->attributes = $_POST['UserChangePassword'];
                     if ($form2->validate()) {
                         $find->password = Yii::app()->controller->module->encrypting($form2->password);
                         $find->activkey = Yii::app()->controller->module->encrypting(microtime() . $form2->password);
                         if ($find->status == 0) {
                             $find->status = 1;
                         }
                         $find->save();
                         Yii::app()->user->setFlash('recoveryMessage', AdminModule::t("New password is saved."));
                         $this->redirect(Yii::app()->controller->module->recoveryUrl);
                     }
                 }
                 $this->render('changepassword', array('form' => $form2));
             } else {
                 Yii::app()->user->setFlash('recoveryMessage', AdminModule::t("Incorrect recovery link."));
                 $this->redirect(Yii::app()->controller->module->recoveryUrl);
             }
         } else {
             if (isset($_POST['UserRecoveryForm'])) {
                 $form->attributes = $_POST['UserRecoveryForm'];
                 if ($form->validate()) {
                     $user = User::model()->notsafe()->findbyPk($form->user_id);
                     $activation_url = 'http://' . $_SERVER['HTTP_HOST'] . $this->createUrl(implode(Yii::app()->controller->module->recoveryUrl), array("activkey" => $user->activkey, "email" => $user->email));
                     $subject = AdminModule::t("You have requested the password recovery site {site_name}", array('{site_name}' => Yii::app()->name));
                     $message = AdminModule::t("You have requested the password recovery site {site_name}. To receive a new password, go to {activation_url}.", array('{site_name}' => Yii::app()->name, '{activation_url}' => $activation_url));
                     AdminModule::sendMail($user->email, $subject, $message);
                     Yii::app()->user->setFlash('recoveryMessage', AdminModule::t("Please check your email. An instructions was sent to your email address."));
                     $this->refresh();
                 }
             }
             $this->render('recovery', array('form' => $form));
         }
     }
 }