PageRenderTime 26ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/www/cnt_plugin_register.php

https://bitbucket.org/wayfarer/verse
PHP | 117 lines | 96 code | 11 blank | 10 comment | 19 complexity | be67658059308e2238af4c8130ce705b MD5 | raw file
Possible License(s): ISC, AGPL-3.0, LGPL-2.1, BSD-3-Clause, LGPL-3.0
  1. <?php
  2. // members, self-register page plugin
  3. include "cnt_plugin_main.php";
  4. function process_content($content, $state) {
  5. global $domain_id, $domain_name, $db;
  6. $ret = "";
  7. switch ($state["action"]) {
  8. default:
  9. $ret = process_tags($content["content1"]);
  10. if ($ret) {
  11. // user entered registration form
  12. // add form tag only if not there
  13. if (strpos($ret, "<form") === false) {
  14. $ret = '<form method="post">' . $ret . '</form>';
  15. }
  16. }
  17. else {
  18. // default registration form
  19. $ret = file_get_contents("templates/helpers/registration_form.html");
  20. }
  21. break;
  22. case "signup":
  23. // validation
  24. $error_count = 0;
  25. if (strlen($state["name"]) < 2) {
  26. $error_count++;
  27. verse_set_message("Please, enter your name", "error");
  28. }
  29. if (strlen($state["login"]) < 2) {
  30. $error_count++;
  31. verse_set_message("Please, enter your username", "error");
  32. }
  33. if (strlen($state["password"]) < 2) {
  34. $error_count++;
  35. verse_set_message("Please, enter your password", "error");
  36. }
  37. if ($state["password"] != $state["password2"]) {
  38. $error_count++;
  39. verse_set_message("Passwords must be the same", "error");
  40. }
  41. if (!check_email($state["email"])) {
  42. $error_count++;
  43. verse_set_message("Please, specify valid email address", "error");
  44. }
  45. if (!$error_count) {
  46. if (!isset($state["debug"])) {
  47. // read data
  48. $login = $state["login"];
  49. $password = $state["password"];
  50. $name = $state["name"];
  51. $emailto = $state["email"];
  52. // validate params
  53. $query = "SELECT email FROM sms_domain WHERE domain_id='" . $GLOBALS["domain_id"] . "'";
  54. $emailfrom = $GLOBALS["db"]->getOne($query);
  55. $emailfromname = $GLOBALS["domain_name"];
  56. $subject = "$domain_name registration confirmation";
  57. $text = file_get_contents("templates/helpers/registration_email.txt");
  58. $hash = substr(md5(uniqid(rand())), 0, 16);
  59. $confirm_url = "http://$domain_name/subscribe.php?action=confirm-registration&id=$hash";
  60. $text = str_replace(array("{confirm_url}"), array($confirm_url), $text);
  61. $p = array();
  62. $p["domain_id"] = $domain_id;
  63. $p["login"] = in($login);
  64. $p["password"] = in($password);
  65. $p["name"] = in($name);
  66. $p["email"] = $emailto;
  67. $p["hash"] = $hash;
  68. $query = "INSERT cms_access_user SET " . make_set_clause($p) . ", created_at=now()";
  69. $ret = $db->query($query);
  70. if ($db->affectedRows() > 0) {
  71. if (check_email($emailto)) {
  72. // confirmation for the user if valid email entered
  73. send_email($emailto, $subject, $emailfrom, $emailfromname, $text);
  74. }
  75. // notification for the admin if enabled
  76. // fetch notification email for new user signup
  77. $query = "SELECT value FROM cms_config WHERE param='member_signup_notification_email' AND domain_id='$domain_id'";
  78. $notification_email = $db->getOne($query);
  79. if (check_email($notification_email)) {
  80. $subject = "$domain_name: new user have signed up";
  81. $text = file_get_contents("templates/helpers/registration_notification.txt");
  82. $text = str_replace(array("{name}", "{url}"), array($name, "http://$domain_name/members.php"), $text);
  83. send_email($notification_email, $subject, $emailfrom, $emailfromname, $text);
  84. }
  85. }
  86. else {
  87. verse_set_message("The system cannot register you. Probably your email address already registered. Please try to register with another e-mail addess, or use forget password function to restore access to your account", "error");
  88. header("Location: /?p=" . $_GET["p"]);
  89. exit;
  90. }
  91. }
  92. if ($content["content2"]) return process_tags($content["content2"]);
  93. else return "<div>Please, check your e-mail to confirm registration</div>";
  94. }
  95. else {
  96. header("Location: /?p=" . $_GET["p"]);
  97. exit;
  98. }
  99. break;
  100. }
  101. return $ret;
  102. }
  103. function send_email($emailto, $subject, $emailfrom, $emailfromname, $text) {
  104. global $domain_name;
  105. return mail($emailto, $subject, $text, "From: $emailfromname <$emailfrom>");
  106. }