Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Controller;
  4.  
  5. use Model\User;
  6.  
  7. class AuthController extends Controller
  8. {
  9. public function register()
  10. {
  11. if(isset($_POST["submit"]))
  12. {
  13. if($_POST["id"]=='')
  14. echo '<li class="error">The id filed cannot be empty</li>';
  15. if($_POST["name"]=='')
  16. echo '<li class="error">The name filed cannot be empty</li>';
  17. if($_POST["surname"]=='')
  18. echo '<li class="error">The surname filed cannot be empty</li>';
  19. if($_POST["email"]=='')
  20. echo '<li class="error">The email filed cannot be empty</li>';
  21. if($_POST["password"]=='')
  22. echo '<li class="error">The password filed cannot be empty</li>';
  23. if($_POST["password_confirmation"]=='')
  24. echo '<li class="error">The password confirmation filed cannot be empty</li>';
  25. if($_POST["password"] != $_POST["password_confirmation"])
  26. echo '<li class="error">The password confirmation filed does not match the password field</li>';
  27.  
  28. if($_POST["id"]!='' && $_POST["name"]!='' && $_POST["surname"]!='' && $_POST["email"]!='' && $_POST["password"]!='' && $_POST["password_confirmation"]!='')
  29. {
  30. if($_POST["password"] == $_POST["password_confirmation"])
  31. {
  32. $this->store();
  33. }
  34. else
  35. return "auth/register";
  36. }
  37. else
  38. return "auth/register";
  39. }
  40. else
  41. return "auth/register";
  42. }
  43.  
  44. public function confirmation_notice()
  45. {
  46. return "auth/confirmation_notice";
  47. }
  48.  
  49. public function store()
  50. {
  51. $user = new User($_POST["id"]);
  52. $user->name = $_POST["name"];
  53. $user->surname = $_POST["surname"];
  54. $user->email = $_POST["email"];
  55. $user->password = password_hash($_POST["password"],PASSWORD_BCRYPT);
  56. $user->password_confirmation = $_POST["password_confirmation"];
  57. $user->token = bin2hex(openssl_random_pseudo_bytes(16));
  58.  
  59. $this->getStorage()->store($user);
  60. header("location: /auth/confirmation_notice");
  61. }
  62.  
  63. // public function confirm()
  64. // {
  65. // $token = 0;
  66. // $users = $this->getStorage()->load("model_user_*");
  67. // foreach ($users as $user)
  68. // {
  69. // if($user->token == $token)
  70. // {
  71. // $user->confirmed = true;
  72. // }
  73. // else
  74. // {
  75. // echo '<li class="error">Provided token is invalid!</li>';
  76. // }
  77. // }
  78. //
  79. // header("Location: /");
  80. // }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement