From 285f2dd0acfcf66ceb0fdbcc6cc6f5830ad135e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Sun, 21 Jun 2020 13:40:36 +0200 Subject: [PATCH] MAPG-69 login user when trying to sign up --- public/static/js/signup.js | 13 +++++++++---- src/Controller/LoginController.php | 18 ++++++++++++------ views/login/signup.php | 2 +- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/public/static/js/signup.js b/public/static/js/signup.js index 339713f..f97fa9e 100644 --- a/public/static/js/signup.js +++ b/public/static/js/signup.js @@ -10,6 +10,11 @@ MapGuesser.httpRequest('POST', form.action, function () { if (this.response.error) { + if (this.response.error === 'user_found') { + window.location.replace('/'); + return; + } + var errorText; switch (this.response.error) { case 'email_not_valid': @@ -21,12 +26,12 @@ case 'passwords_not_match': errorText = 'The given passwords do not match.' break; - case 'user_found': - errorText = 'There is a user already registered with the given email address. Please login here!'; - break; - case 'not_active_user_found': + case 'user_found_user_not_active': errorText = 'There is a user already registered with the given email address. Please check your email and click on the activation link!'; break; + case 'user_found_password_not_match': + errorText = 'There is a user already registered with the given email address, but the given password is wrong.' + break; } document.getElementById('loading').style.visibility = 'hidden'; diff --git a/src/Controller/LoginController.php b/src/Controller/LoginController.php index 5be2e92..dc280e6 100644 --- a/src/Controller/LoginController.php +++ b/src/Controller/LoginController.php @@ -190,22 +190,28 @@ class LoginController return new JsonContent($data); } - if (filter_var($this->request->post('email'), FILTER_VALIDATE_EMAIL) === false) { - $data = ['error' => 'email_not_valid']; - return new JsonContent($data); - } - $user = $this->userRepository->getByEmail($this->request->post('email')); if ($user !== null) { if ($user->getActive()) { + if (!$user->checkPassword($this->request->post('password'))) { + $data = ['error' => 'user_found_password_not_match']; + return new JsonContent($data); + } + + $this->request->setUser($user); + $data = ['error' => 'user_found']; } else { - $data = ['error' => 'not_active_user_found']; + $data = ['error' => 'user_found_user_not_active']; } return new JsonContent($data); } + if (filter_var($this->request->post('email'), FILTER_VALIDATE_EMAIL) === false) { + $data = ['error' => 'email_not_valid']; + return new JsonContent($data); + } if ($this->request->session()->has('tmp_user_data')) { $tmpUserData = $this->request->session()->get('tmp_user_data'); diff --git a/views/login/signup.php b/views/login/signup.php index 89dcba5..9f4e295 100644 --- a/views/login/signup.php +++ b/views/login/signup.php @@ -16,7 +16,7 @@ $jsFiles = [ - +