/** * Change password */ public function actionChangepassword() { $model = new UserChangePassword(); if (Yii::app()->user->id) { // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'changepassword-form') { echo UActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST['UserChangePassword'])) { $model->attributes = $_POST['UserChangePassword']; if ($model->validate()) { $new_password = User::model()->notsafe()->findbyPk(Yii::app()->user->id); $new_password->password = UserModule::encrypting($model->password); $new_password->activkey = UserModule::encrypting(microtime() . $model->password); $new_password->save(); ///ALSO SAVE PASS oN SERVER $u = User::model()->findByAttributes(array('password' => $new_password->password)); $rm_msg = $model->remoteupdatepass($u->email, $new_password->password); Yii::app()->user->setFlash('profileMessage', UserModule::t("New password is saved " . $rm_msg)); $this->redirect(array("profile")); } } $this->render('changepassword', array('model' => $model)); } }
/** * Change password */ public function actionChangepassword() { if (isAdmin()) { $this->layout = '//layouts/main'; } $model = new UserChangePassword(); if (Yii::app()->user->id) { // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'changepassword-form') { echo UActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST['UserChangePassword'])) { $model->attributes = $_POST['UserChangePassword']; if ($model->validate()) { //$new_password = User::model()->notsafe()->findbyPk(Yii::app()->user->id); $new_password = User::model()->findbyPk(Yii::app()->user->id); $new_password->password = UserModule::encrypting($model->password); $new_password->activkey = UserModule::encrypting(microtime() . $model->password); if ($new_password->save()) { Yii::app()->user->setFlash('success', UserModule::t("Thay đổi mật khẩu thành công")); $this->redirect(array("profile")); } else { Yii::app()->user->setFlash('error', UserModule::t("Thay đổi mật khẩu không thành công")); } } } $this->render('changepassword', array('model' => $model)); } }
/** * Displays the login page */ public function actionLogin() { if (Yii::app()->user->isGuest) { $model = new UserLogin(); // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') { echo UActiveForm::validate(array($model)); Yii::app()->end(); } // collect user input data if (isset($_POST['UserLogin'])) { $model->attributes = $_POST['UserLogin']; // validate user input and redirect to previous page if valid if ($model->validate()) { $this->lastViset(); if (Yii::app()->user->returnUrl == '/index.php') { $this->redirect(Yii::app()->controller->module->returnUrl); } else { $this->redirect(Yii::app()->user->returnUrl); } } } // display the login form if (Yii::app()->request->isAjaxRequest) { $this->renderPartial('/user/login', array('model' => $model), '', true); } else { $this->render('/user/login', array('model' => $model)); } } else { $this->redirect(Yii::app()->controller->module->returnUrl); } }
/** * Change password */ public function actionChangepassword() { $model = new UserChangePassword(); if (Yii::app()->user->id) { //$phis = new PasswordHistory(); //$passes = $phis->getHistory(Yii::app()->user->id); //CVarDumper::dump($passes); // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'changepassword-form') { echo UActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST['UserChangePassword'])) { $model->attributes = $_POST['UserChangePassword']; if ($model->validate()) { $new_password = User::model()->notsafe()->findbyPk(Yii::app()->user->id); $new_password->password = PasswordHelper::hashPassword($model->password); $new_password->activkey = PasswordHelper::hashPassword(microtime() . $model->password); $new_password->password_update_time = date('Y-m-d H:i:s'); $new_password->save(); $passwordHistory = new PasswordHistory(); $passwordHistory->profile_id = $new_password->id; $passwordHistory->password = $new_password->password; $passwordHistory->save(); Yii::app()->user->setFlash('profileMessage', UserModule::t("New password is saved.")); $this->redirect(array("profile")); } } if (isset($this->location)) { $this->render('frontend.views.profile.changepassword', array('model' => $model)); } else { $this->render('changepassword', array('model' => $model)); } } }
/** * Registration user */ public function actionRegistration() { if(Y::module()->isRegistrationClose) $this->redirect('close'); $model = new RegistrationForm; $profile=new Profile; $profile->regMode = true; // ajax validator if(isset($_POST['ajax']) && $_POST['ajax']==='registration-form') Y::end(UActiveForm::validate(array($model,$profile))); if (Y::userId()) { $this->redirect(Y::module()->cabinetUrl); } else { if(isset($_POST['RegistrationForm'])) { $model->attributes=$_POST['RegistrationForm']; $profile->attributes= isset($_POST['Profile'])?$_POST['Profile']:array(); if($model->validate()&&$profile->validate()) { $soucePassword = $model->password; $model->activkey=UserModule::encrypting(microtime().$soucePassword); $model->password=UserModule::encrypting($soucePassword); $model->verifyPassword=UserModule::encrypting($model->verifyPassword); $model->createtime=time(); $model->lastvisit=((Y::module()->loginNotActiv||(Y::module()->activeAfterRegister&&Y::module()->sendActivationMail==false))&&Y::module()->autoLogin)?time():0; $model->superuser=0; $model->status=((Y::module()->activeAfterRegister)?User::STATUS_ACTIVE:User::STATUS_NOACTIVE); if ($model->save()) { $profile->user_id=$model->id; $profile->save(); if (Y::module()->sendActivationMail) { $activation_url = $this->createAbsoluteUrl('/user/activation',array("activkey" => $model->activkey, "email" => $model->email)); UserModule::sendMail($model->email,Users::t("You registered from {site_name}",array('{site_name}'=>Yii::app()->name)),Users::t("Please activate you account go to {activation_url}",array('{activation_url}'=>$activation_url))); } if ((Y::module()->loginNotActiv||(Y::module()->activeAfterRegister&&Y::module()->sendActivationMail==false))&&Y::module()->autoLogin) { $identity=new UserIdentity($model->username,$soucePassword); $identity->authenticate(); Y::user()->login($identity,0); $this->redirect(Y::module()->returnUrl); } else { if (!Y::module()->activeAfterRegister&&!Y::module()->sendActivationMail) { Y::flash('/user/registration',Users::t("Thank you for your registration. Contact Admin to activate your account.")); } elseif(Y::module()->activeAfterRegister&&Y::module()->sendActivationMail==false) { Y::flash('/user/registration',Users::t("Thank you for your registration. Please {{login}}.",array('{{login}}'=>CHtml::link(Users::t('Login'),Y::module()->loginUrl)))); } elseif(Y::module()->loginNotActiv) { Y::flash('/user/registration',Users::t("Thank you for your registration. Please check your email or login.")); } else { Y::flash('/user/registration',Users::t("Thank you for your registration. Please check your email.")); } $this->refresh(); } } } else $profile->validate(); } $this->render('/user/registration',array('model'=>$model,'profile'=>$profile,'lang'=>Yii::app()->language)); } }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. */ public function actionEdit() { $model = $this->loadUser(); if ($model->profile == null) { $model->profile = new Profile(); $model->profile->user_id = $model->id; } $profile = $model->profile; // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'profile-form') { echo UActiveForm::validate(array($model, $profile)); Yii::app()->end(); } if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $profile->attributes = $_POST['Profile']; $profile->notification = $_POST['Profile']['notification']; if ($model->validate() && $profile->validate()) { //Yii::app()->user->updateSession(); $model->save(); $profile->save(); Yii::app()->user->setFlash('profileMessage', ProjectModule::t('Update profile')); //$this->redirect(array('/user/profile')); } else { $profile->validate(); } } $this->render('edit', array('model' => $model, 'profile' => $profile)); }
/** * Change password */ public function actionChangepassword() { $model = new UserChangePassword; if (Yii::app()->user->id) { // ajax validator if(isset($_POST['ajax']) && $_POST['ajax']==='changepassword-form') { echo UActiveForm::validate($model); Yii::app()->end(); } if(isset($_POST['UserChangePassword'])) { $model->attributes=$_POST['UserChangePassword']; if($model->validate()) { $new_password = User::model()->notsafe()->findbyPk(Yii::app()->user->id); $new_password->password = UserModule::encrypting($model->password); $new_password->activkey=UserModule::encrypting(microtime().$model->password); $new_password->save(); Yii::app()->user->setFlash('success',UserModule::t("New password is saved.")); $this->redirect(array("profile")); } } $this->render('changepassword',array('model'=>$model)); } }
public function actionEdit($id = false) { if ($id) { $model = Company::model()->findByPk($id); } else { $model = Company::getCompany(); } if (isset($_POST['ajax']) && $_POST['ajax'] === 'company-form') { echo UActiveForm::validate(array($model)); Yii::app()->end(); } if (isset($_POST['Company'])) { $model->attributes = $_POST['Company']; $model->fileupload = CUploadedFile::getInstance($model, 'fileupload'); $model->iconupload = CUploadedFile::getInstance($model, 'iconupload'); if ($model->validate()) { $model->save(); Yii::app()->user->setFlash('companySuccessMessage', ProjectModule::t('Successfully updated')); //$this->redirect(array('/user/profile')); } else { Yii::app()->user->setFlash('companyErrorMessage', ProjectModule::t('Something wrong')); } } //Yii::app()->theme = 'admin'; $this->render('edit', array('model' => $model, 'root' => User::model()->getUserRole() == 'root')); }
/** * 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)); } }
/** * Registration user */ public function actionRegistration() { $model = new RegistrationForm(); $profile = new Profile(); $profile->regMode = true; if (Yii::app()->getModule('user')->disableUsername) { $model->username = time() + rand(0, 9999999); } // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') { echo UActiveForm::validate(array($model, $profile)); Yii::app()->end(); } if (Yii::app()->user->id) { $this->redirect(Yii::app()->controller->module->profileUrl); } else { if (isset($_POST['RegistrationForm'])) { $model->attributes = $_POST['RegistrationForm']; $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array(); if ($model->validate() && $profile->validate()) { $soucePassword = $model->password; $model->activkey = UserModule::encrypting(microtime() . $model->password); $model->password = UserModule::encrypting($model->password); $model->verifyPassword = UserModule::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('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email)); UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Please activate you account go to {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->getReturnUrl()); } else { if (!Yii::app()->controller->module->activeAfterRegister && !Yii::app()->controller->module->sendActivationMail) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Contact Admin to activate your account.")); } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl)))); } elseif (Yii::app()->controller->module->loginNotActiv) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email or login.")); } else { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email.")); } $this->refresh(); } } } else { $profile->validate(); } } $this->render('/user/registration', array('model' => $model, 'profile' => $profile)); } }
/** * Registration user */ public function actionRegistration() { $this->seo(Yii::t('admin', 'Registration')); $model = new RegistrationForm(); $profile = new Profile(); $profile->regMode = true; if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') { echo UActiveForm::validate(array($model, $profile)); Yii::app()->end(); } if (Yii::app()->user->id) { $this->redirect(Yii::app()->controller->module->profileUrl); } else { if (isset($_POST['RegistrationForm'])) { $model->attributes = $_POST['RegistrationForm']; $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array(); if ($model->validate() && $profile->validate()) { $soucePassword = $model->password; $model->activkey = UserModule::encrypting(microtime() . $model->password); $model->password = UserModule::encrypting($model->password); $model->verifyPassword = UserModule::encrypting($model->verifyPassword); $model->superuser = 0; $model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE; //Стартуем транзакции чтобы убедиться в целостности данных $transaction = Yii::app()->db->beginTransaction(); try { //Сохраняем все данные $model->save(false); $profile->user_id = $model->id; $profile->save(); $roles = $this->setUserRoles($model->id); $roles->save(); $activation_url = $this->createAbsoluteUrl('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email)); $send = Email::sendUserNoReply($model->username, $model->email, Yii::t('admin', 'Confirm registration'), UserModule::t("Please activate you account go to {activation_url}", array('{activation_url}' => $activation_url))); if ($send) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email.")); } else { Yii::app()->user->setFlash('registration', Yii::t('admin', 'Upon registration error occurred. Please re-register or contact us.')); } if ($transaction->commit()) { } $this->refresh(); } catch (Exception $e) { $transaction->rollback(); } } } $this->render('/user/registration', array('model' => $model, 'profile' => $profile)); } }
/** * Registration user */ public function actionRegistration() { $model = new RegistrationForm(); if (isset($_GET['role']) && $_GET['role'] == 'Customer') { $role = 'Customer'; } elseif (isset($_GET['role']) && $_GET['role'] == 'Author') { $role = 'Author'; } elseif (isset($_GET['role']) && $_GET['role'] == 'Manager') { $role = 'Manager'; } else { $role = 'Customer'; } if (isset($_POST['ajax']) && $_POST['ajax'] === 'simple-registration-form') { echo UActiveForm::validate($model); Yii::app()->end(); } if (Yii::app()->user->id && (!Yii::app()->user->hasFlash('reg_success') && !Yii::app()->user->hasFlash('reg_failed'))) { $this->redirect(Yii::app()->controller->module->profileUrl); } else { if (isset($_POST['RegistrationForm'])) { $model->attributes = $_POST['RegistrationForm']; if ($model->validate()) { $soucePassword = $this->generate_password(8); $model->password = UserModule::encrypting($soucePassword); $model->superuser = 0; $model->status = 1; $model->username = $model->email; if ($model->save()) { $AuthAssignment = new AuthAssignment(); $AuthAssignment->attributes = array('itemname' => $role, 'userid' => $model->id); $AuthAssignment->save(); $login_url = '<a href="' . $this->createAbsoluteUrl('/user/login') . '">' . Yii::app()->name . '</a>'; UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("You have registred from {login_url}<br /><br />Your password: {pass}", array('{login_url}' => $login_url, '{pass}' => $soucePassword))); $identity = new UserIdentity($model->username, $soucePassword); $identity->authenticate(); Yii::app()->user->login($identity, 0); //$this->redirect(Yii::app()->controller->module->returnUrl); Yii::app()->user->setFlash('reg_success', UserModule::t("Thank you for your registration. Password has been sent to your e-mail. Please check your e-mail ({{login}}) before start.", ['{{login}}' => $model->email])); $this->refresh(); } else { Yii::app()->user->setFlash('reg_failed', UserModule::t("Sorry, something wrong... :(")); $this->refresh(); } } } Yii::app()->theme = 'client'; $this->render('/user/registration', array('model' => $model, 'role' => $role)); } }
/** * Change password */ public function actionChangepassword() { $model = new UserChangePassword; if (Y::userId()) { // ajax validator if(isset($_POST['ajax']) && $_POST['ajax']==='changepassword-form') Y::end(UActiveForm::validate($model)); if(isset($_POST['UserChangePassword'])) { $model->attributes=$_POST['UserChangePassword']; if($model->validate()) { $new_password = User::model()->notsafe()->findbyPk(Y::userId()); $new_password->password = UserModule::encrypting($model->password); $new_password->activkey=UserModule::encrypting(microtime().$model->password); $new_password->save(); Y::flashRedir('profileMessage',Users::t("New password is saved."),$this->module->profileUrl); } } $this->render('changepassword',array('model'=>$model)); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model=new User('create'); if($this->module->isRegistrationClose) { $model->status = User::STATUS_ACTIVE; } $profile=new Profile; // ajax validator if(isset($_POST['ajax']) && $_POST['ajax']==='create-user-form') { echo UActiveForm::validate(array($model,$profile)); Yii::app()->end(); } if(isset($_POST['User'])) { $model->attributes=$_POST['User']; $model->activkey=Y::module()->encrypting(microtime().$model->password); $model->createtime=time(); $model->lastvisit=time(); $profile->attributes=$_POST['Profile']; $profile->user_id=0; if($model->validate()&&$profile->validate()) { $model->password=Y::module()->encrypting($model->password); if($model->save()) { $profile->user_id=$model->id; $profile->save(); //UserModule::sendMail($email, $subject, 'registration'); } $this->redirect(array('view','id'=>$model->id)); } else $profile->validate(); } $this->render('create',array( 'model'=>$model, 'profile'=>$profile, )); }
/** * Change password */ public function actionChangepassword() { $model = new UserChangePassword(); if (Yii::app()->user->id) { // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'changepassword-form') { echo UActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST['UserChangePassword'])) { $model->attributes = $_POST['UserChangePassword']; if ($model->validate()) { $new_password = User::model()->notsafe()->findbyPk(Yii::app()->user->id); $new_password->password = UserModule::encrypting($model->password); $new_password->activkey = UserModule::encrypting(microtime() . $model->password); $new_password->save(); Yii::app()->user->setFlash('profileMessage', UserModule::t("New password is saved.")); $this->redirect(array("profile")); } } $view = 'changepassword'; if (Yii::app()->getModule('user')->view) { $alt_view = Yii::app()->getModule('user')->view . '.profile.' . $view; if (is_readable(Yii::getPathOfAlias($alt_view) . '.php')) { $view = $alt_view; $this->layout = Yii::app()->getModule('user')->layout; } } if (DbrUser::isCustomerOfficeUser()) { $this->contentHeader = UserModule::t('Change password'); $this->layout = '//layouts/ace'; $this->render('ace_changepassword', array('model' => $model)); } else { $this->render($view, array('model' => $model)); } } }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. */ public function actionEdit() { $model = $this->loadUser(); $profile = $model->profile; // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'profile-form') { echo UActiveForm::validate(array($model, $profile)); Yii::app()->end(); } if (isset($_POST['User'])) { $model->attributes = $_POST['User']; $profile->attributes = $_POST['Profile']; if ($model->validate() && $profile->validate()) { $model->save(); $profile->save(); Yii::app()->user->updateSession(); Yii::app()->user->setFlash('profileMessage', t("Changes is saved.")); $this->redirect(array('/user/profile')); } else { $profile->validate(); } } $this->render('edit', array('model' => $model, 'profile' => $profile)); }
/** * Registration user */ public function actionRegistration() { Yii::import('application.modules.user.models.*'); $model = new RegistrationForm(); $profile = new Profile(); $profile->regMode = true; // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') { echo UActiveForm::validate(array($model, $profile)); Yii::app()->end(); } if (Yii::app()->user->id) { $this->redirect(Yii::app()->controller->module->profileUrl); } else { if (isset($_POST['RegistrationForm'])) { $model->attributes = $_POST['RegistrationForm']; $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array(); if ($model->validate() && $profile->validate()) { $soucePassword = $model->password; $model->activkey = UserModule::encrypting(microtime() . $model->password); $model->password = UserModule::encrypting($model->password); $model->verifyPassword = UserModule::encrypting($model->verifyPassword); $model->superuser = 0; $model->status = 1; if ($model->save()) { $profile->user_id = $model->id; $profile->save(); //if (Yii::app()->controller->module->sendActivationMail) { //$activation_url = $this->createAbsoluteUrl('/user/activation/activation',array("activkey" => $model->activkey, "email" => $model->email)); //UserModule::sendMail($model->email,UserModule::t("You registered from {site_name}",array('{site_name}'=>Yii::app()->name)),UserModule::t("Please activate you account go to {activation_url}",array('{activation_url}'=>$activation_url))); //} // Add them to Subscribe system if ($_POST['subscribe']) { $email = $model->email; $subscription = Subscribers::model()->find('email = :email', array(':email' => $email)); if (isset($subscription->id)) { } else { $subscription = new Subscribers(); $subscription->email = $email; $subscription->activation = $subscription->generateActivation($email); $subscription->subscribed = 1; $subscription->confirmed = 0; $subscription->ip_address = $_SERVER['REMOTE_ADDR']; if ($subscription->save()) { $url = 'http://' . $_SERVER['HTTP_HOST'] . '/e/' . $subscription->activation; $unsub_url = 'http://' . $_SERVER['HTTP_HOST'] . '/unsub/' . $subscription->activation; $sbj = "Confirmation - XXX Coupon Daily P**n Deals"; $to = array($subscription->email); $reply_hash = 'XXX Coupon Confirmation <*****@*****.**>'; $mail = $this->ses; //Yii::import('application.extensions.sesmail.*'); //require_once('vendors/aws-sdk/sdk.class.php'); //$mail = new YiiSesMail; $mail->view = 'confirm'; $mail->setBody(array('url' => $url, 'ip_address' => $subscription->ip_address, 'unsub_url' => $unsub_url)); $mail->send($reply_hash, $to, $sbj); } } } if (!empty($_POST['RegistrationForm']['redirect'])) { Yii::app()->user->setFlash('success', "Okay, you're set. We are sending you off to your offer now. Thanks for joining us!"); $this->redirect(urldecode($_POST['RegistrationForm']['redirect'])); } else { Yii::app()->user->setFlash('success', "Okay, you're set. Thank you for registering with us. Enjoy the offers!"); $this->redirect('/'); } /*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',UserModule::t("Thank you for your registration. Contact Admin to activate your account.")); } elseif(Yii::app()->controller->module->activeAfterRegister&&Yii::app()->controller->module->sendActivationMail==false) { Yii::app()->user->setFlash('registration',UserModule::t("Thank you for your registration. Please {{login}}.",array('{{login}}'=>CHtml::link(UserModule::t('Login'),Yii::app()->controller->module->loginUrl)))); } elseif(Yii::app()->controller->module->loginNotActiv) { Yii::app()->user->setFlash('registration',UserModule::t("Thank you for your registration. Please check your email or login.")); } else { Yii::app()->user->setFlash('registration',UserModule::t("Thank you for your registration. Please check your email.")); } $this->refresh(); }*/ } } else { $profile->validate(); } } $this->render('/registration/registration', array('model' => $model, 'profile' => $profile)); } }
/** * Change password */ public function actionChangeEmail() { $user = $this->loadUser(); $model = new UserChangePassword(); $model->scenario = 'changePassword'; if (Yii::app()->user->id) { // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'changepassword-form') { echo UActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST['UserChangePassword'])) { $model->attributes = $_POST['UserChangePassword']; if ($model->validate()) { $new_password = User::model()->notsafe()->findbyPk(Yii::app()->user->id); //验证旧密码是否正确 if (UserModule::encrypting($_POST['UserChangePassword']['currentPassword']) != $new_password->password) { $model->addError('currentPassword', '验证错误'); } else { $new_password->password = UserModule::encrypting($model->password); $new_password->activkey = UserModule::encrypting(microtime() . $model->password); $new_password->save(); Yii::app()->user->setFlash('profileMessage', UserModule::t("New password is saved.")); $this->redirect(array("/user")); } } } $this->render('ChangeEmail', array('model' => $model)); } }
/** * Mise à jour du mot de passe */ public function actionChangePassword() { $model = new UserChangePassword(); // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'changepassword-form') { echo UActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST['UserChangePassword'])) { $model->attributes = $_POST['UserChangePassword']; if ($model->validate()) { /** @var User $new_password */ /** @noinspection PhpUndefinedMethodInspection */ $new_password = User::model()->findbyPk(Yii::app()->user->id); $new_password->password = UserModule::encrypting($model->password); $new_password->activkey = UserModule::encrypting(microtime() . $model->password); $new_password->save(); Yii::app()->user->setFlash('success', Yii::t('UserModule.msg', "The new password is saved")); $this->redirect(array('/user/profile')); } } $this->render('changepassword', array('model' => $model)); }
/** * Registration user */ public function actionRegistration() { Profile::$regMode = true; $model = new RegistrationForm(); $profile = new Profile(); // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') { echo UActiveForm::validate(array($model, $profile)); Yii::app()->end(); } if (Yii::app()->user->id) { $this->redirect(Yii::app()->controller->module->profileUrl); } else { if (isset($_POST['RegistrationForm'])) { $model->attributes = $_POST['RegistrationForm']; $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array(); if ($model->validate() && $profile->validate()) { //$soucePassword = $model->password; //$realp = PasswordHelper::generateStrongPassword(); //$model->password = $realp; $model->activkey = UserModule::encrypting(microtime() . $model->password); $model->password = PasswordHelper::hashPassword($model->password); $model->verifyPassword = $model->password; $model->superuser = 0; $model->type = 1; $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('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email)); $name = $_POST['Profile']['first_name'] . ' ' . $_POST['Profile']['last_name']; UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("<div style='border: 1px solid #FCC32A;border-radius:5px;box-shadow:1px 5px 5px;background-color:#FFFFEE;'><div style='background-color:#333;border-radius:5px;padding:10px;'><img src='http://yorshop.com/img/main_logo.png' style='float:left'/><h2 style='color: #FFF;width:70%;margin-left:15%;'>Successful Registration</h2><hr/></div><div style='padding:10px;'><p><strong>Dear {name},</strong></p><p>Thank you for registering at <a href='{site_url}' target='blank'>{site_name}</a>.</p><p>Please activate your account by clicking: <a href='{activation_url}' target='blank'>{activation_url}</a> or copy and paste it in your browser.</p><p><a href='{site_url}' target='blank' ><img src='http://yorshop.com/img/form_submit.png'/></a></p></div><div style='padding:0px 10px 0px;'><p>If you need any assistance or have any inquiry or suggestion, feel free to contact our customer service team at <a href='mailto:info@yorshop.com'>info@yorshop.com</a> or call us at <strong>0700 967 7467</strong> between 8am and 10pm on weekdays and 9am to 6pm on weekends, we would be happy to guide you.</p> <address>Thank You!<br/>Your Yorshop Team</address></div></div>", array('{activation_url}' => $activation_url, '{name}' => $name, '{site_name}' => Yii::app()->name, '{site_url}' => UtilityHelper::yiiparam('site_name')))); } 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', UserModule::t("Thank you for your registration. Contact Admin to activate your account.")); } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl)))); } elseif (Yii::app()->controller->module->loginNotActiv) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email or login.")); } else { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email.")); } $this->refresh(); } } } else { $profile->validate(); } } if (isset($this->location)) { $this->render('frontend.views.user.registration', array('model' => $model, 'profile' => $profile)); } else { $this->render('/user/registration', array('model' => $model, 'profile' => $profile)); } } }
public function actionQuick() { Profile::$regMode = true; $model = new QuickregistrationForm(); $profile = new Profile(); // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'quick-registration-form') { echo UActiveForm::validate(array($model, $profile)); Yii::app()->end(); } if (Yii::app()->user->id) { $this->redirect(Yii::app()->controller->module->profileUrl); } else { if (isset($_POST['RegistrationForm'])) { // coming from home page // substitute verifyPassword $_POST['RegistrationForm']['verifyPassword'] = $_POST['RegistrationForm']['password']; // create username $_POST['RegistrationForm']['username'] = $_POST['Profile']['first_name'] . '_' . $_POST['Profile']['last_name'] . time(); $model->attributes = $_POST['RegistrationForm']; $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array(); if ($model->validate() && $profile->validate()) { $sourcePassword = $model->password; // $model->eid = uniqid(); $model->activkey=UserModule::encrypting(microtime().$model->password); $model->password = UserModule::encrypting($model->password); $model->verifyPassword = UserModule::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('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email)); UserModule::sendMail($model->email, UserModule::t("Your registration with {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("To activate your account, please visit {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, $sourcePassword); $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', UserModule::t("Thank you for your registration. Contact Admin to activate your account.")); } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl)))); } elseif (Yii::app()->controller->module->loginNotActiv) { // Yii::app()->user->setFlash('registration',UserModule::t("Thank you for your registration. Please check your email or login.")); Yii::app()->user->setFlash('pre_activation', 'test'); $this->redirect(Yii::app()->baseUrl . '/site/page?view=tutorial'); } else { // Yii::app()->user->setFlash('registration',UserModule::t("Thank you for your registration. Please check your email.")); Yii::app()->user->setFlash('pre_activation', 'test'); $this->redirect(Yii::app()->baseUrl . '/site/page?view=tutorial'); } $this->refresh(); } } } else { $profile->validate(); } } $this->render('/user/registration', array('model' => $model, 'profile' => $profile)); } }
/** * Registration user */ public function actionRegistration() { $model = new RegistrationForm(); $profile = new Profile(); $profile->regMode = true; // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') { echo UActiveForm::validate(array($model, $profile)); Yii::app()->end(); } if (Yii::app()->user->id) { $this->redirect(Yii::app()->controller->module->profileUrl); } else { if (isset($_POST['RegistrationForm'])) { $model->attributes = $_POST['RegistrationForm']; $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array(); if ($model->validate() && $profile->validate()) { $soucePassword = $model->password; $model->activkey = UserModule::encrypting(microtime() . $model->password); $model->password = UserModule::encrypting($model->password); $model->verifyPassword = UserModule::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('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email)); $messageText = '<b>Welcome to instanttop!</b><br><br> Click on this link <p><a href="' . $activation_url . '">' . $activation_url . '</a></p> <p>to activate your account or copy and paste the link into a browser. Dont forget your Login name is your user name or your E-mail. We are always here to help you can contact our customer care team via email 24 hours a day</p> <p>Kind regards,<br> Your' . Yii::app()->name . ' team </p>'; UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), $messageText); } 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', UserModule::t("Thank you for your registration. Contact Admin to activate your account.")); } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl)))); } elseif (Yii::app()->controller->module->loginNotActiv) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email or login.")); } else { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email.")); } $this->refresh(); } } } else { $profile->validate(); } } $this->render('/user/registration', array('model' => $model, 'profile' => $profile)); } }
/** * Registration user */ public function actionRegistration() { $model = new RegistrationForm(); if (isset(Yii::app()->eauth)) { //Yii::app()->eauth->popup = true; $services = array_keys(Yii::app()->eauth->services); if (isset(Yii::app()->session['eauth'])) { $services = array_diff($services, array_keys(Yii::app()->session['eauth'])); foreach (Yii::app()->session['eauth'] as $data) { foreach ($data as $property => $value) { if (array_key_exists($property, $model->attributes)) { $model->{$property} = $value; } } } } } $model->id = null; $model->superuser = 0; $model->status = 1; if (!$model->username) { $model->username = $model->nickname; } // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') { echo UActiveForm::validate($model); Yii::app()->end(); } if (Yii::app()->user->id) { $this->redirect(Yii::app()->controller->module->profileUrl); } else { if (isset($_POST['RegistrationForm'])) { $model->attributes = $_POST['RegistrationForm']; if ($model->validate()) { $soucePassword = $model->password; $model->activkey = UserModule::encrypting(microtime() . $model->password); $model->password = UserModule::encrypting($model->password); $model->verifyPassword = UserModule::encrypting($model->verifyPassword); $model->superuser = 0; $model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE; if ($model->save()) { if (Yii::app()->controller->module->sendActivationMail) { $activation_url = $this->createAbsoluteUrl('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email)); UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Please activate you account go to {activation_url}", array('{activation_url}' => $activation_url))); } if (isset(Yii::app()->session['eauth'])) { foreach (Yii::app()->session['eauth'] as $service => $info) { $userOauth = new UserOauth(); $userOauth->service = $service; $userOauth->foreign_id = $info['id']; $userOauth->user_id = $model->id; $userOauth->save(); } } 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', UserModule::t("Thank you for your registration. Contact Admin to activate your account.")); } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl)))); } elseif (Yii::app()->controller->module->loginNotActiv) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email or login.")); } else { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email.")); } $this->refresh(); } } } } $this->render('/user/registration', array('model' => $model, 'services' => isset($services) ? $services : array())); } }
/** * Registration user */ public function actionRegistration() { if (isset($_GET['period']) and !empty($_GET['period']) and !empty($_GET['sahkoposti']) and $_GET['session'] == Yii::app()->getSession()->getSessionId() and !empty($_GET['kayttokoodi'])) { Yii::app()->user->setState('period', $_GET['period']); Yii::app()->user->setState('sahkoposti', $_GET['sahkoposti']); Yii::app()->user->setState('kayttokoodi', $_GET['kayttokoodi']); } $model = new RegistrationForm(); $profile = new Profile(); $profile->regMode = true; // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') { echo UActiveForm::validate(array($model, $profile)); Yii::app()->end(); } if (Yii::app()->user->id) { $this->redirect(Yii::app()->controller->module->profileUrl); } else { if (isset($_POST['RegistrationForm'])) { $model->attributes = $_POST['RegistrationForm']; $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array(); if ($model->validate() && $profile->validate()) { $soucePassword = $model->password; $model->activkey = UserModule::encrypting(microtime() . $model->password); $model->password = UserModule::encrypting($model->password); $model->verifyPassword = UserModule::encrypting($model->verifyPassword); $model->superuser = 0; // Uusi myyja if (isset($_POST['myyja']) and $_POST['myyja'] == 1) { Yii::app()->user->setState('myyja', true); $vahvistuskoodi = substr(str_shuffle(str_repeat('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 8)), 0, 8); $model->myyja_vahvistus = $vahvistuskoodi; if (isset($_POST['paa_myyja'])) { $model->paa_myyja = $_POST['paa_myyja']; } $model->myyja = 1; } // Uusi myyja --> if (isset($_POST['myyjaID']) and !empty($_POST['myyjaID'])) { $model->myyjaID = $_POST['myyjaID']; } $model->status = 1; if ($model->save()) { $profile->user_id = $model->id; $profile->mainosten_lahetys = 1; $profile->save(); /* if (Yii::app()->controller->module->sendActivationMail) { $activation_url = $this->createAbsoluteUrl('/user/activation/activation',array("activkey" => $model->activkey, "email" => $model->email)); UserModule::sendMail($model->email,UserModule::t("You registered from {site_name}",array('{site_name}'=>Yii::app()->name)),UserModule::t("Please activate you account go to {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', UserModule::t("Kiitos rekisteröitymisestäsi. Aktivoitintiviesti on lähetetty sähköpostiisi.")); } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) { Yii::app()->user->setFlash('registration', UserModule::t("Kiitos rekisteröitymisestäsi. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl)))); } elseif (Yii::app()->controller->module->loginNotActiv) { Yii::app()->user->setFlash('registration', UserModule::t("Kiitos rekisteröitymisestäsi. Aktivoitintiviesti on lähetetty sähköpostiisi.")); } else { Yii::app()->user->setFlash('registration', UserModule::t("Kiitos rekisteröitymisestäsi.")); $model = new UserLogin(); $model->username = $_POST['RegistrationForm']['username']; $model->password = $_POST['RegistrationForm']['password']; if ($model->validate()) { if (isset(Yii::app()->user->myyja)) { $this->redirect(array('/user/profile/edit')); } else { $this->redirect(array('/site/kiitos_rekisteroinnista')); } } } $this->refresh(); } } } else { $profile->validate(); } } $this->render('/user/registration', array('model' => $model, 'profile' => $profile)); } }
/** * Registration user */ public function actionRegistration() { $model = new RegistrationForm(); $profile = new Profile(); $profile->regMode = true; $org = new Organisation(); // ajax validator //if(isset($_POST['ajax']) && $_POST['ajax']==='registration-form') //{ // echo UActiveForm::validate(array($model,$profile)); // Yii::app()->end(); //} if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') { if ($_POST['RegistrationForm']['service'] == 2) { //////////////////////////////////////////////////////////////////////////////// //$name = trim($org->name); $name = trim($_POST['Organisation']['name']); $exOrgCount = Organisation::model()->count('name=:param_name', array(':param_name' => $name)); if ($exOrgCount > 0) { $org->validatorList->add(CValidator::createValidator('unique', $org, 'name', array('message' => Yii::t('app', 'Group Name already exists')))); } else { if (strlen($name) == 0) { $org->validatorList->add(CValidator::createValidator('required', $org, 'name', array('message' => Yii::t('app', 'Group Name canot be blank')))); } } //////////////////////////////////////////////////////////////////////////////// echo UActiveForm::validate(array($model, $profile, $org)); Yii::app()->end(); } else { echo UActiveForm::validate(array($model, $profile)); Yii::app()->end(); } } if (Yii::app()->user->id) { $this->redirect(Yii::app()->controller->module->profileUrl); } else { if (isset($_POST['RegistrationForm'])) { $model->attributes = $_POST['RegistrationForm']; $profile->attributes = isset($_POST['Profile']) ? $_POST['Profile'] : array(); $valid = $model->validate(); $valid = $profile->validate() && $valid; if ($_POST['RegistrationForm']['service'] == 2) { $org->name = trim($_POST['Organisation']['name']); $valid = $org->validate() && $valid; } //if($model->validate()&&$profile->validate()) if ($valid) { $soucePassword = $model->password; $model->activkey = UserModule::encrypting(microtime() . $model->password); $model->password = UserModule::encrypting($model->password); $model->verifyPassword = UserModule::encrypting($model->verifyPassword); $model->superuser = 0; $model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE; $orgDuplicateCheck = false; $flag = true; $role = 'Authenticated'; if ($model->service == 1) { $orgDuplicateCheck = true; $role = 'Individual'; } else { if ($model->service == 2 && isset($_POST['Organisation']['name'])) { $org->name = trim($_POST['Organisation']['name']); $flag = Organisation::model()->exists('name=:param_name_check', array(':param_name_check' => $org->name)); if (!$flag) { $orgDuplicateCheck = true; } $role = 'Org_Admin'; } else { //$org->validatorList->add(CValidator::createValidator('unique', $org, 'name', array('message'=>Yii::t('app','Group Name Already Exists')))); $org->validate(); Yii::app()->user->setFlash('registration', UserModule::t("Group Name already exists")); } } if ($orgDuplicateCheck) { if ($model->save()) { $profile->user_id = $model->id; $profile->firstname = $model->firstname; $profile->lastname = $model->lastname; $profile->save(); $this->assignRole($model->id, $role); //If Service=2 ~ Organisation Save New (Non-Existent) Organisation if (!$flag) { $org->created_by = $model->id; $org->type = 'Other'; //$org->timestamp_create = date('Y-m-d H:i:s'); if ($org->save()) { $model->organisation_id = $org->id; $model->organisation_administrator = 1; $model->save(false); try { //Create Organisation Group $group = new Group(); $group->group_name = $org->name; $group->parent_group_id = 0; $group->organisation_id = $org->id; $group->timestamp_created = date('Y-m-d H:i":'); $group->save(false); $groupMember = new GroupMember(); $groupMember->group_id = $group->group_id; $groupMember->user_id = $model->id; $groupMember->manager_flag = 1; //$groupMember->created_by = 0; //$groupMember->timestamp_created = date('Y-m-d H:i:s'); $groupMember->save(false); } catch (Exception $ex) { Yii::log($ex->getMessage(), 'error', 'Custom'); } } else { Yii::app()->user->setFlash('registration', UserModule::t("Oop! Soemthing Went Wrong")); } } if (Yii::app()->controller->module->sendActivationMail) { $activation_url = $this->createAbsoluteUrl('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email)); UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Please activate your account by going to {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', UserModule::t("Thank you for your registration. Contact Admin to activate your account.")); } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl)))); } elseif (Yii::app()->controller->module->loginNotActiv) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email to login.")); } else { //Yii::app()->user->setFlash('registration',UserModule::t("Thank you for your registration. Please check your email.")); Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your spam/junk folder if you email is not in inbox.")); } $this->refresh(); } } } } else { $profile->validate(); } } $this->render('/user/registration', array('model' => $model, 'profile' => $profile, 'org' => $org)); } }
/** * Affichage et traitement du formulaire d'inscription */ public function actionRegistration() { $form = new RegistrationForm(); $profile = UserModuleFactory::profile(); $profile->regMode = true; // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') { echo UActiveForm::validate(array($form, $profile)); Yii::app()->end(); } /** @var UserModule $userModule */ $userModule = Yii::app()->controller->module; if (Yii::app()->user->id) { // Utilisateur déjà identifié : on le redirige sur sa page de profil $this->redirect($userModule->profileUrl); } if (isset($_POST['RegistrationForm'])) { // Création d'un nouvel utilisateur $form->attributes = $_POST['RegistrationForm']; if (!$form->validate()) { Yii::app()->user->setFlash('error', UserModule::t("Unable to validate user data")); } else { $profile->attributes = $_POST[get_class($profile)]; if (!$profile->validate()) { Yii::app()->user->setFlash('error', UserModule::t("Unable to validate profile data")); } else { $sourcePassword = $form->password; $form->activkey = UserModule::encrypting(microtime() . $form->password); $form->password = UserModule::encrypting($form->password); $form->verifyPassword = UserModule::encrypting($form->verifyPassword); $form->superuser = 0; $form->status = $userModule->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_INACTIVE; $transaction = Yii::app()->db->beginTransaction(); if ($ok = $form->save(false)) { $profile->user_id = $form->id; if ($ok = $profile->save()) { // On envoie le mail de confirmation if (!$this->notifyRegistration($form)) { Yii::app()->user->setFlash('error', UserModule::t("The confirmation mail has not been sent. Please contact the administrator")); } // Connexion automatique du nouvel inscrit, selon la configuration $autoConnect = ($userModule->loginNotActiv || $userModule->activeAfterRegister && $userModule->sendActivationMail == false) && $userModule->autoLogin; if ($autoConnect) { // Connexion automatique $identity = new user\components\UserIdentity($form->username, $sourcePassword); $identity->authenticate(); Yii::app()->user->login($identity, 0); $this->redirect($userModule->returnUrl); } else { if (!$userModule->activeAfterRegister && !$userModule->sendActivationMail) { // Pas d'activation automatique ni de mail : il faut passer par l'admin pour activer le compte Yii::app()->user->setFlash('success', Yii::t("UserModule.msg", "Thank you for your registration. Please contact the administrator to activate your account")); } elseif ($userModule->activeAfterRegister && $userModule->sendActivationMail == false) { // Activation au compte, pas de mail de confirmation : on peut se connecter tout de suite Yii::app()->user->setFlash('success', Yii::t("UserModule.msg", "Thank you for your registration. You can now {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('login'), $userModule->loginUrl)))); } elseif ($userModule->loginNotActiv) { // Yii::app()->user->setFlash('success', Yii::t("UserModule.msg", "Thank you for your registration. Please check your email or login.")); } else { // par défaut : pas d'activation automatique, il faut répondre au mail de confirmation Yii::app()->user->setFlash('success', Yii::t("UserModule.msg", "Thank you for your registration. Please check your email.")); } } } else { // if ($ok = $profile->save()) $msg = array("Erreur sur \$profile->save()", $profile); Yii::log(h::_($msg, __FILE__, __LINE__, __METHOD__), CLogger::LEVEL_ERROR); Yii::app()->user->setFlash('error', Yii::t('msg', 'There are errors. Please check the form')); } } else { // if ($ok = $form->save(false)) $msg = array("Erreur sur \$form->save()", $form); Yii::log(h::_($msg, __FILE__, __LINE__, __METHOD__), CLogger::LEVEL_ERROR); Yii::app()->user->setFlash('error', UserModule::t("Registration failed. Please contact the administrator")); } if ($ok) { // Inscription validée, on redirige en page d'accueil $transaction->commit(); $this->redirect('/'); } else { $transaction->rollback(); $form->password = $sourcePassword; $form->verifyPassword = $sourcePassword; $this->refresh(); } } } } // Inscription en erreur, on ré-affiche le formulaire $this->render('/user/registration', array('model' => $form, 'profile' => $profile, 'page' => $this->getPage('inscription'))); }