1 | <?php |
||
37 | class RegistrationController extends Controller |
||
38 | { |
||
39 | use ContainerAwareTrait; |
||
40 | |||
41 | protected $userQuery; |
||
42 | protected $socialNetworkAccountQuery; |
||
43 | |||
44 | /** |
||
45 | * RegistrationController constructor. |
||
46 | * |
||
47 | * @param string $id |
||
48 | * @param Module $module |
||
49 | * @param UserQuery $userQuery |
||
50 | * @param SocialNetworkAccountQuery $socialNetworkAccountQuery |
||
51 | * @param array $config |
||
52 | */ |
||
53 | 5 | public function __construct( |
|
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | 5 | public function behaviors() |
|
88 | |||
89 | 3 | public function actionRegister() |
|
90 | { |
||
91 | 3 | if (!$this->module->enableRegistration) { |
|
92 | throw new NotFoundHttpException(); |
||
93 | } |
||
94 | /** @var RegistrationForm $form */ |
||
95 | 3 | $form = $this->make(RegistrationForm::class); |
|
96 | /** @var FormEvent $event */ |
||
97 | 3 | $event = $this->make(FormEvent::class, [$form]); |
|
98 | |||
99 | 3 | $this->make(AjaxRequestModelValidator::class, [$form])->validate(); |
|
100 | |||
101 | 3 | if ($form->load(Yii::$app->request->post()) && $form->validate()) { |
|
102 | 3 | $this->trigger(UserEvent::EVENT_BEFORE_REGISTER, $event); |
|
103 | /** @var User $user */ |
||
104 | 3 | $user = $this->make(User::class, [], $form->attributes); |
|
105 | 3 | $user->setScenario('register'); |
|
106 | 3 | $mailService = MailFactory::makeWelcomeMailerService($user); |
|
107 | |||
108 | 3 | if ($this->make(UserRegisterService::class, [$user, $mailService])->run()) { |
|
109 | 3 | Yii::$app->session->setFlash( |
|
110 | 3 | 'info', |
|
111 | 3 | Yii::t( |
|
112 | 3 | 'usuario', |
|
113 | 3 | 'Your account has been created and a message with further instructions has been sent to your email' |
|
114 | ) |
||
115 | ); |
||
116 | 3 | $this->trigger(UserEvent::EVENT_AFTER_REGISTER, $event); |
|
117 | |||
118 | 3 | return $this->render( |
|
119 | 3 | '/shared/message', |
|
120 | [ |
||
121 | 3 | 'title' => Yii::t('usuario', 'Your account has been created'), |
|
122 | 3 | 'module' => $this->module, |
|
123 | ] |
||
124 | ); |
||
125 | } |
||
126 | } |
||
127 | |||
128 | 3 | return $this->render( |
|
129 | 3 | 'register', |
|
130 | [ |
||
131 | 3 | 'model' => $form, |
|
132 | 3 | 'module' => $this->module, |
|
133 | ] |
||
134 | ); |
||
135 | } |
||
136 | |||
137 | public function actionConnect($code) |
||
138 | { |
||
139 | /** @var SocialNetworkAccount $account */ |
||
140 | $account = $this->socialNetworkAccountQuery->whereCode($code)->one(); |
||
141 | if ($account === null || $account->getIsConnected()) { |
||
142 | throw new NotFoundHttpException(); |
||
143 | } |
||
144 | |||
145 | /** @var User $user */ |
||
146 | $user = $this->make( |
||
147 | User::class, |
||
148 | [], |
||
149 | ['scenario' => 'connect', 'username' => $account->username, 'email' => $account->email] |
||
150 | ); |
||
151 | $event = $this->make(SocialNetworkConnectEvent::class, [$user, $account]); |
||
152 | |||
153 | $this->make(AjaxRequestModelValidator::class, [$user])->validate(); |
||
154 | |||
155 | if ($user->load(Yii::$app->request->post())) { |
||
156 | $this->trigger(SocialNetworkConnectEvent::EVENT_BEFORE_CONNECT, $event); |
||
157 | |||
158 | $mailService = MailFactory::makeWelcomeMailerService($user); |
||
159 | if ($this->make(UserCreateService::class, [$user, $mailService])->run()) { |
||
160 | $account->connect($user); |
||
161 | $this->trigger(SocialNetworkConnectEvent::EVENT_AFTER_CONNECT, $event); |
||
162 | |||
163 | Yii::$app->user->login($user, $this->module->rememberLoginLifespan); |
||
164 | |||
165 | return $this->goBack(); |
||
166 | } |
||
167 | } |
||
168 | |||
169 | return $this->render( |
||
170 | 'connect', |
||
171 | [ |
||
172 | 'model' => $user, |
||
173 | 'account' => $account, |
||
174 | ] |
||
175 | ); |
||
176 | } |
||
177 | |||
178 | 1 | public function actionConfirm($id, $code) |
|
213 | |||
214 | 1 | public function actionResend() |
|
273 | } |
||
274 |