Advertisement
Guest User

AuthController

a guest
Dec 10th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.62 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Controller;
  4.  
  5. use Model\User;
  6.  
  7. class AuthController extends Controller
  8. {
  9.    
  10.     public function register()
  11.     {
  12.         return "auth/register";
  13.     }
  14.     public function login()
  15.     {
  16.         return "auth/login";
  17.     }
  18.     public function confirmation_notice()
  19.     {
  20.         return "auth/confirmation_notice";
  21.     }
  22.  
  23.     /**
  24.      * Store data from register form to database
  25.      * only if form is validated
  26.      */
  27.     public function store()
  28.     {
  29.  
  30.         if($this->formValidation()){
  31.             $user = new User($_POST["id"]);
  32.             $user->name = $_POST["name"];
  33.             $user->surname = $_POST["surname"];
  34.             $user->email = $_POST["email"];
  35.             $user->password = password_hash($_POST["password"], PASSWORD_BCRYPT);
  36.             $user->password_confirmation = $_POST["password_confirmation"];
  37.  
  38.             $this->getStorage()->store($user);
  39.             header("auth/confirmation_notice");
  40.  
  41.            // return "auth/confirmation_notice";
  42.         }
  43.         else {
  44.             header("auth/register");
  45.             // return "auth/register";
  46.         }
  47.     }
  48.  
  49.     /**
  50.      * Check from validation and show errors in view
  51.      * @return bool
  52.      */
  53.     public function formValidation()
  54.     {
  55.         $matchPassword = false;
  56.         $validationForm = true;
  57.  
  58.         if ($_POST["password"] == $_POST["password_confirmation"]) $matchPassword = true;
  59.         else  echo "<li class=\"error\"> The password confirmation filed does not match the password field </li>";
  60.  
  61.         if ($_POST["id"] == "") {
  62.             echo "<li class=\"error\">The id filed cannot be empty</li>";
  63.             $validationForm = false;
  64.         }
  65.         if ($_POST["name"] == "") {
  66.             echo "<li class=\"error\">The name filed cannot be empty</li>";
  67.             $validationForm = false;
  68.         }
  69.         if ($_POST["surname"] == "") {
  70.             echo "<li class=\"error\">The name filed cannot be empty</li>";
  71.             $validationForm = false;
  72.         }
  73.         if ($_POST["email"] == "") {
  74.             echo "<li class=\"error\">The email filed cannot be empty</li>";
  75.             $validationForm = false;
  76.         }
  77.         if ($_POST["password"] == "") {
  78.             echo "<li class=\"error\">The password filed cannot be empty</li>";
  79.             $validationForm = false;
  80.         }
  81.         if ($_POST["password_confirmation"] == "") {
  82.             echo "<li class=\"error\">The password confirmation filed cannot be empty</li>";
  83.             $validationForm = false;
  84.         }
  85.  
  86.         if ($validationForm && $matchPassword) return true;
  87.         else false;
  88.     }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement