Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function actionRegister()
- {
- $model = new RegisterForm;
- $msg = null;
- if ($model->load(Yii::$app->request->post()) && Yii::$app->request->isAjax)
- {
- Yii::$app->response->format = Response::FORMAT_JSON;
- return ActiveForm::validate($model);
- }
- if ($model->load(Yii::$app->request->post()))
- {
- if($model->validate())
- {
- $table = new Usuario;
- $table->username = $model->username;
- $table->email = $model->email;
- $table->password = crypt($model->password, Yii::$app->params["salt"]);
- $table->authKey = $this->randKey("abcdef0123456789", 200);
- $table->accessToken = $this->randKey("abcdef0123456789", 200);
- //Si el registro es guardado correctamente
- if ($table->save())
- {
- $user = $table->find()->where(["email" => $model->email])->one();
- $id = urlencode($user->id);
- $authKey = urlencode($user->authKey);
- $subject = "Confirmar registro";
- $body = "<h1>Haga click en el siguiente enlace para finalizar tu registro</h1>";
- $body .= "<a href='http://localhost:8888/futbolpika/web/index.php/site/confirm?id=".$id."&authKey=".$authKey."'>Confirmar</a>";
- //Enviamos el correo
- Yii::$app->mailer->compose()
- ->setTo($user->email)
- ->setFrom([Yii::$app->params["adminEmail"] => Yii::$app->params["title"]])
- ->setSubject($subject)
- ->setHtmlBody($body)
- ->send();
- $model->username = null;
- $model->email = null;
- $model->password = null;
- $model->password_repeat = null;
- $msg = "Ahora sólo falta que confirmes tu registro en tu cuenta de correo";
- }
- else
- {
- $msg = "Ha ocurrido un error al llevar a cabo tu registro";
- }
- }
- else
- {
- $model->getErrors();
- }
- }
- return $this->render("register", ["model" => $model, "msg" => $msg]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement