Advertisement
Guest User

Untitled

a guest
Nov 15th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. public function actionRegister()
  2. {
  3. $model = new RegisterForm;
  4. $msg = null;
  5. if ($model->load(Yii::$app->request->post()) && Yii::$app->request->isAjax)
  6. {
  7. Yii::$app->response->format = Response::FORMAT_JSON;
  8. return ActiveForm::validate($model);
  9. }
  10. if ($model->load(Yii::$app->request->post()))
  11. {
  12. if($model->validate())
  13. {
  14. $table = new Usuario;
  15. $table->username = $model->username;
  16. $table->email = $model->email;
  17. $table->password = crypt($model->password, Yii::$app->params["salt"]);
  18. $table->authKey = $this->randKey("abcdef0123456789", 200);
  19. $table->accessToken = $this->randKey("abcdef0123456789", 200);
  20.  
  21. //Si el registro es guardado correctamente
  22. if ($table->save())
  23. {
  24. $user = $table->find()->where(["email" => $model->email])->one();
  25. $id = urlencode($user->id);
  26. $authKey = urlencode($user->authKey);
  27. $subject = "Confirmar registro";
  28. $body = "<h1>Haga click en el siguiente enlace para finalizar tu registro</h1>";
  29. $body .= "<a href='http://localhost:8888/futbolpika/web/index.php/site/confirm?id=".$id."&authKey=".$authKey."'>Confirmar</a>";
  30. //Enviamos el correo
  31. Yii::$app->mailer->compose()
  32. ->setTo($user->email)
  33. ->setFrom([Yii::$app->params["adminEmail"] => Yii::$app->params["title"]])
  34. ->setSubject($subject)
  35. ->setHtmlBody($body)
  36. ->send();
  37. $model->username = null;
  38. $model->email = null;
  39. $model->password = null;
  40. $model->password_repeat = null;
  41.  
  42. $msg = "Ahora sólo falta que confirmes tu registro en tu cuenta de correo";
  43. }
  44. else
  45. {
  46. $msg = "Ha ocurrido un error al llevar a cabo tu registro";
  47. }
  48. }
  49. else
  50. {
  51. $model->getErrors();
  52. }
  53. }
  54. return $this->render("register", ["model" => $model, "msg" => $msg]);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement