Advertisement
Guest User

Untitled

a guest
Dec 10th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 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. }
  35. else
  36. return "auth/register";
  37. }
  38. else
  39. return "auth/register";
  40. }
  41.  
  42. public function confirmation_notice()
  43. {
  44. return "auth/confirmation_notice";
  45. }
  46.  
  47. public function store()
  48. {
  49. $user = new User($_POST["id"]);
  50. $user->name = $_POST["name"];
  51. $user->surname = $_POST["surname"];
  52. $user->email = $_POST["email"];
  53. $user->password = password_hash($_POST["password"],PASSWORD_BCRYPT);
  54. $user->password_confirmation = $_POST["password_confirmation"];
  55. $user->token = bin2hex(openssl_random_pseudo_bytes(16));
  56.  
  57. $this->getStorage()->store($user);
  58. header("location: /auth/confirmation_notice");
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement