HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
RegistrationController.php
Go to the documentation of this file.
1 <?php
2 
4 {
5  public $defaultAction = 'registration';
6 
10  public function actions()
11  {
12  return array(
13  'captcha' => array(
14  'class' => 'CCaptchaAction',
15  'backColor' => 0xFFFFFF,
16  ),
17  );
18  }
22  public function actionRegistration()
23  {
24  $model = new RegistrationForm();
25  $profile = new Profile();
26  $profile->regMode = true;
27 
28  // ajax validator
29  if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') {
30  echo UActiveForm::validate(array($model, $profile));
31  Yii::app()->end();
32  }
33 
34  if (Yii::app()->user->id && !UserModule::isUserTemp()) {
35  $this->redirect(Yii::app()->controller->module->profileUrl);
36  } else {
37  if (isset($_POST['RegistrationForm'])) {
38  $model->attributes = $_POST['RegistrationForm'];
39  $profile->attributes = ((isset($_POST['Profile']) ? $_POST['Profile'] : array()));
40 
41  if ($model->validate() && $profile->validate()) {
42  $soucePassword = $model->password;
43  $model->activkey = UserModule::encrypting(microtime().$model->password);
44  $model->password = UserModule::encrypting($model->password);
45  $model->verifyPassword = UserModule::encrypting($model->verifyPassword);
46  $model->superuser = 0;
47  $model->status = ((Yii::app()->controller->module->activeAfterRegister) ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE);
48 
49  if ($model->save()) {
50  $profile->user_id = $model->id;
51  $profile->save();
52 
53  // Set default user assignments (role / account type)
54  $model->setDefaultUserAssignments($model->id);
55 
56  if (Yii::app()->controller->module->sendActivationMail) {
57  $activation_url = $this->createAbsoluteUrl('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email));
58  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)));
59  }
60 
61  if ((Yii::app()->controller->module->loginNotActiv || (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false)) && Yii::app()->controller->module->autoLogin) {
62  $identity = new UserIdentity($model->username, $soucePassword);
63  $identity->authenticate();
64  Yii::app()->user->login($identity, 0);
65  $this->redirect(Yii::app()->controller->module->returnUrl);
66  } else {
67  if (!Yii::app()->controller->module->activeAfterRegister && !Yii::app()->controller->module->sendActivationMail) {
68  Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Contact Admin to activate your account."));
69  } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) {
70  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))));
71  } elseif (Yii::app()->controller->module->loginNotActiv) {
72  Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email or login."));
73  } else {
74  Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email."));
75  }
76  $this->refresh();
77  }
78  }
79  } else {
80  $profile->validate();
81  }
82  }
83  $this->render('/user/registration', array('model' => $model, 'profile' => $profile));
84  }
85  }
86 }