Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
RegistrationController.php
1 <?php
2 
4 {
5  public $defaultAction = 'registration';
6 
7 
8  /**
9  * Declares class-based actions.
10  */
11  public function actions()
12  {
13  return (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') ? array() : array(
14  'captcha' => array(
15  'class' => 'CCaptchaAction',
16  'backColor' => 0xFFFFFF,
17  'fixedVerifyCode' => YII_DEBUG ? 'polomo' : null
18  ),
19  );
20  }
21 
22  /**
23  * Registration user
24  */
25  public function actionRegistration()
26  {
27  if (Yii::app()->user->id) {
28  $this->redirect(Yii::app()->controller->module->homePageUrl);
29  } else {
30  $registrationForm = new RegistrationForm;
31  $profile = new Profile;
32  $profile->regMode = true;
33  // ajax validator
34  if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') {
35  echo CActiveForm::validate(array($registrationForm, $profile));
36  Yii::app()->end();
37  }
38 
39  if (isset($_POST['RegistrationForm'])) {
40  $registrationForm->attributes = $_POST['RegistrationForm'];
41  $profile->attributes = @$_POST['Profile'];
42  $rv = $registrationForm->validate();
43  $pv = $profile->validate();
44  if ($rv && $pv) {
45  $sourcePassword = $registrationForm->password;
46  $registrationForm->activkey = UserModule::encrypting(microtime() . $registrationForm->password);
47  $registrationForm->password = UserModule::encrypting($registrationForm->password);
48  $registrationForm->verifyPassword = UserModule::encrypting($registrationForm->verifyPassword);
49  $registrationForm->lastvisit =
50  ((Yii::app()->controller->module->loginNotActiv || (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false)) && Yii::app()->controller->module->autoLogin) ?
51  time() :
52  null;
53  // $model->superuser = 0;
54  $registrationForm->status = ((Yii::app()->controller->module->activeAfterRegister) ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE);
55 
56  if ($registrationForm->save()) {
57  $profile->user_id = $registrationForm->id;
58  $profile->save();
59  if(Yii::app()->getModule('user')->registrationNotifyAdminEmail !== NULL){
60  $this->onRegisterNewUser($registrationForm, $profile);
61  }
62 
63  Yii::app()->user->setState('RegistrationForm', null);
64  Yii::app()->user->setState('Profile', null);
65 
66  if (Yii::app()->controller->module->sendActivationMail) {
67 
68  if (isset($_GET['return_url'])) {
69  $activation_url = $this->createAbsoluteUrl(
70  AppHelper::addParamsToUrl($_GET['return_url'], array("activkey" => $registrationForm->activkey, "email" => $registrationForm->email))
71  );
72  } else {
73  $activation_url = $this->createAbsoluteUrl(
74  '/user/activation/activation',
75  array("activkey" => $registrationForm->activkey, "email" => $registrationForm->email)
76  );
77  }
78 
79  $subject = UserModule::t(Yii::app()->controller->module->activationMailSubject, array('{site_name}' => Yii::app()->name));
80  $message = $this->renderMail('/mail_templates/activation_mail', $subject, array('activation_url' => $activation_url));
81  $notification = new Notification(
82  $subject,
83  $message,
84  array(new EmailRecipient($registrationForm->email, Yii::app()->getModule('user')->activationEmail, '', true))
85  );
86  Yii::app()->notificationManager->notifyAbout($notification);
87  }
88 
89  if ((Yii::app()->controller->module->loginNotActiv || (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false)) && Yii::app()->controller->module->autoLogin) {
90  $identity = new UserIdentity($registrationForm->username, $sourcePassword);
91  $identity->authenticate();
92  Yii::app()->user->login($identity, 0);
93  $this->redirect(Yii::app()->controller->module->returnUrl);
94  } else {
95  if (!Yii::app()->controller->module->activeAfterRegister && !Yii::app()->controller->module->sendActivationMail) {
96  Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Contact Admin to activate your account."));
97  } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) {
98  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))));
99  } elseif (Yii::app()->controller->module->loginNotActiv) {
100  Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email or login."));
101  } else {
102  Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email."));
103  }
104  if (isset($_GET['return_url'])) {
105  $this->redirect($_GET['return_url']);
106  } else {
107  $this->refresh();
108  }
109  }
110  }
111  } elseif (!isset($_POST['ajax'])) {
112  $registrationForm->password = null;
113  $registrationForm->verifyPassword = null;
114  Yii::app()->user->setState('RegistrationForm', array('attributes' => $registrationForm->attributes, 'errors' => $registrationForm->getErrors()));
115  Yii::app()->user->setState('Profile', array('attributes' => $profile->attributes, 'errors' => $profile->getErrors()));
116  }
117  }
118 
119  if (isset($_GET['return_url'])) {
120  $this->redirect($_GET['return_url']);
121  } else {
122  $this->render('/user/registration', array('model' => $registrationForm, 'profile' => $profile));
123  }
124  }
125  }
126 
127  public function onRegisterNewUser($form, $profile)
128  {
129  $subject = UserModule::t("New user '{$form->email}' was registered");
130  $message = Yii::app()->controller->renderMail('user.views.mail_templates.'.Yii::app()->getModule('user')->registrationNotifyAdminTemplate, $subject, array('form' => $form,'profile' => $profile),true);
131 
132  $notification = new Notification(
133  $subject,
134  $message,
135  array(new EmailRecipient(Yii::app()->getModule('user')->registrationNotifyAdminEmail, Yii::app()->getModule('user')->activationEmail, '', true))
136  );
137  Yii::app()->notificationManager->notifyAbout($notification);
138  }
139 }