Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Controller;
- use Model\User;
- class AuthController extends Controller
- {
- public function register()
- {
- return "auth/register";
- }
- public function login()
- {
- return "auth/login";
- }
- public function confirmation_notice()
- {
- return "auth/confirmation_notice";
- }
- /**
- * Store data from register form to database
- * only if form is validated
- */
- public function store()
- {
- if($this->formValidation()){
- $user = new User($_POST["id"]);
- $user->name = $_POST["name"];
- $user->surname = $_POST["surname"];
- $user->email = $_POST["email"];
- $user->password = password_hash($_POST["password"], PASSWORD_BCRYPT);
- $user->password_confirmation = $_POST["password_confirmation"];
- $this->getStorage()->store($user);
- header("auth/confirmation_notice");
- // return "auth/confirmation_notice";
- }
- else {
- header("auth/register");
- // return "auth/register";
- }
- }
- /**
- * Check from validation and show errors in view
- * @return bool
- */
- public function formValidation()
- {
- $matchPassword = false;
- $validationForm = true;
- if ($_POST["password"] == $_POST["password_confirmation"]) $matchPassword = true;
- else echo "<li class=\"error\"> The password confirmation filed does not match the password field </li>";
- if ($_POST["id"] == "") {
- echo "<li class=\"error\">The id filed cannot be empty</li>";
- $validationForm = false;
- }
- if ($_POST["name"] == "") {
- echo "<li class=\"error\">The name filed cannot be empty</li>";
- $validationForm = false;
- }
- if ($_POST["surname"] == "") {
- echo "<li class=\"error\">The name filed cannot be empty</li>";
- $validationForm = false;
- }
- if ($_POST["email"] == "") {
- echo "<li class=\"error\">The email filed cannot be empty</li>";
- $validationForm = false;
- }
- if ($_POST["password"] == "") {
- echo "<li class=\"error\">The password filed cannot be empty</li>";
- $validationForm = false;
- }
- if ($_POST["password_confirmation"] == "") {
- echo "<li class=\"error\">The password confirmation filed cannot be empty</li>";
- $validationForm = false;
- }
- if ($validationForm && $matchPassword) return true;
- else false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement