Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 55 additions & 8 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
use App\ModelSerializers\SerializerRegistry;
use Auth\Exceptions\AuthenticationException;
use Auth\Exceptions\UnverifiedEmailMemberException;
use App\Services\Auth\IUserService as AuthUserService;
use Exception;
use Illuminate\Http\Request as LaravelRequest;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redirect;
Expand Down Expand Up @@ -86,6 +88,10 @@ final class UserController extends OpenIdController
* @var IUserService
*/
private $user_service;
/**
* @var AuthUserService
*/
private $auth_user_service;
/**
* @var IUserActionService
*/
Expand Down Expand Up @@ -132,6 +138,7 @@ final class UserController extends OpenIdController
* @param ITrustedSitesService $trusted_sites_service
* @param DiscoveryController $discovery
* @param IUserService $user_service
* @param AuthUserService $auth_user_service
* @param IUserActionService $user_action_service
* @param IClientRepository $client_repository
* @param IApiScopeRepository $scope_repository
Expand All @@ -150,6 +157,7 @@ public function __construct
ITrustedSitesService $trusted_sites_service,
DiscoveryController $discovery,
IUserService $user_service,
AuthUserService $auth_user_service,
IUserActionService $user_action_service,
IClientRepository $client_repository,
IApiScopeRepository $scope_repository,
Expand All @@ -160,15 +168,14 @@ public function __construct
LoginHintProcessStrategy $login_hint_process_strategy
)
{


$this->openid_memento_service = $openid_memento_service;
$this->oauth2_memento_service = $oauth2_memento_service;
$this->auth_service = $auth_service;
$this->server_configuration_service = $server_configuration_service;
$this->trusted_sites_service = $trusted_sites_service;
$this->discovery = $discovery;
$this->user_service = $user_service;
$this->auth_user_service = $auth_user_service;
$this->user_action_service = $user_action_service;
$this->client_repository = $client_repository;
$this->scope_repository = $scope_repository;
Expand Down Expand Up @@ -258,14 +265,16 @@ public function getAccount()

$user = $this->auth_service->getUserByUsername($email);

if (is_null($user) || !$user->canLogin())
if (is_null($user))
throw new EntityNotFoundException();

return $this->ok(
[
'is_active' => $user->isActive(),
'is_verified' => $user->isEmailVerified(),
'pic' => $user->getPic(),
'full_name' => $user->getFullName(),
'has_password_set' => $user->hasPasswordSet()
'has_password_set' => $user->hasPasswordSet(),
]
);
} catch (ValidationException $ex) {
Expand Down Expand Up @@ -350,9 +359,41 @@ public function emitOTP()
}
}

/**
* @return \Illuminate\Http\JsonResponse|mixed
*/
public function resendVerificationEmail(LaravelRequest $request)
{
try {
$payload = $request->all();
$validator = Validator::make($payload, [
'email' => 'required|string|email|max:255'
]);

if (!$validator->passes()) {
return $this->error412($validator->getMessageBag()->getMessages());
}
$this->auth_user_service->resendVerificationEmail($payload);
return $this->ok();
}
catch (ValidationException $ex) {
Log::warning($ex);
return $this->error412($ex->getMessages());
}
catch (EntityNotFoundException $ex) {
Log::warning($ex);
return $this->error404();
}
catch (Exception $ex) {
Log::error($ex);
return $this->error500($ex);
}
}

public function postLogin()
{
$max_login_attempts_2_show_captcha = $this->server_configuration_service->getConfigValue("MaxFailed.LoginAttempts.2ShowCaptcha");
$max_login_failed_attempts = intval($this->server_configuration_service->getConfigValue("MaxFailed.Login.Attempts"));
$login_attempts = 0;
$username = '';
$user = null;
Expand Down Expand Up @@ -439,13 +480,15 @@ public function postLogin()
(
[
'max_login_attempts_2_show_captcha' => $max_login_attempts_2_show_captcha,
'max_login_failed_attempts' => $max_login_failed_attempts,
'login_attempts' => $login_attempts,
'error_message' => $ex->getMessage(),
'user_fullname' => !is_null($user) ? $user->getFullName() : "",
'user_pic' => !is_null($user) ? $user->getPic(): "",
'user_verified' => true,
'username' => $username,
'flow' => $flow
'flow' => $flow,
'user_is_active' => !is_null($user) ? ($user->isActive() ? 1 : 0) : 0
]
);
}
Expand All @@ -455,6 +498,7 @@ public function postLogin()
// validator errors
$response_data = [
'max_login_attempts_2_show_captcha' => $max_login_attempts_2_show_captcha,
'max_login_failed_attempts' => $max_login_failed_attempts,
'login_attempts' => $login_attempts,
'validator' => $validator,
];
Expand All @@ -466,7 +510,8 @@ public function postLogin()
if(!is_null($user)){
$response_data['user_fullname'] = $user->getFullName();
$response_data['user_pic'] = $user->getPic();
$response_data['user_verified'] = true;
$response_data['user_verified'] = 1;
$response_data['user_is_active'] = $user->isActive() ? 1 : 0;
}

return $this->login_strategy->errorLogin
Expand All @@ -481,9 +526,10 @@ public function postLogin()

$response_data = [
'max_login_attempts_2_show_captcha' => $max_login_attempts_2_show_captcha,
'max_login_failed_attempts' => $max_login_failed_attempts,
'login_attempts' => $login_attempts,
'username' => $username,
'error_message' => $ex1->getMessage()
'error_message' => $ex1->getMessage(),
];

if (is_null($user) && isset($data['username'])) {
Expand All @@ -493,7 +539,8 @@ public function postLogin()
if(!is_null($user)){
$response_data['user_fullname'] = $user->getFullName();
$response_data['user_pic'] = $user->getPic();
$response_data['user_verified'] = true;
$response_data['user_verified'] = 1;
$response_data['user_is_active'] = $user->isActive() ? 1 : 0;
}

return $this->login_strategy->errorLogin
Expand Down
8 changes: 6 additions & 2 deletions app/Services/Auth/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,18 @@ public function registerUser(array $payload, ?OAuth2OTP $otp = null):User
* @param string $token
* @return User
* @throws EntityNotFoundException
* @throws ValidationException
* @throws ValidationException|\Exception
*/
public function verifyEmail(string $token): User
{
return $this->tx_service->transaction(function () use ($token) {
$user = $this->user_repository->getByVerificationEmailToken($token);
if (is_null($user))

if (is_null($user) || !$user->isActive()) {
Log::warning(sprintf("UserService::verifyEmail user with id %s is not active", $user->getId()));
throw new EntityNotFoundException();
}

$user->verifyEmail();

try {
Expand Down
2 changes: 1 addition & 1 deletion app/Services/SecurityPolicies/LockUserCounterMeasure.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function trigger(array $params = [])
$user_id = $params["user_id"];
$user = $this->repository->getById($user_id);
$max_login_failed_attempts = intval($this->server_configuration->getConfigValue("MaxFailed.Login.Attempts"));
if (!is_null($user) && $user instanceof User) {
if ($user instanceof User) {
//apply lock policy
if (intval($user->getLoginFailedAttempt()) < $max_login_failed_attempts) {
$this->user_service->updateFailedLoginAttempts($user->getId());
Expand Down
1 change: 0 additions & 1 deletion app/libs/Auth/Factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Auth\Group;
use Auth\User;
use Illuminate\Support\Facades\Auth;

Expand Down
3 changes: 3 additions & 0 deletions app/libs/Auth/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,8 @@ public function activate():void {
if(!$this->active) {
$this->active = true;
$this->spam_type = self::SpamTypeHam;
// reset it
$this->login_failed_attempt = 0;
Event::dispatch(new UserSpamStateUpdated(
$this->getId()
)
Expand Down Expand Up @@ -1886,6 +1888,7 @@ public function verifyEmail(bool $send_email_verified_notice = true)
$this->spam_type = self::SpamTypeHam;
$this->active = true;
$this->lock = false;
$this->login_failed_attempt = 0;
$this->email_verified_date = new \DateTime('now', new \DateTimeZone('UTC'));

if($send_email_verified_notice)
Expand Down
22 changes: 22 additions & 0 deletions resources/js/components/custom_snackbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { Snackbar } from '@material-ui/core';
import MuiAlert from '@material-ui/lab/Alert';

function Alert(props) {
return <MuiAlert elevation={6} variant="filled" {...props} />;
}

const CustomSnackbar = ({ message, severity = 'info', onClose }) => {
return (
<Snackbar
open={message !== null}
autoHideDuration={8000}
onClose={onClose}
anchorOrigin={{ vertical: 'top', horizontal: 'center' }}>
<Alert onClose={onClose} severity={severity}>
{message}
</Alert>
</Snackbar>
);
};
export default CustomSnackbar;
8 changes: 8 additions & 0 deletions resources/js/login/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,11 @@ export const emitOTP = (email, token, connection = 'email', send='code') => {

return postRawRequest(window.EMIT_OTP_ENDPOINT)(params, {'X-CSRF-TOKEN': token});
}

export const resendVerificationEmail = (email, token) => {
const params = {
email: email
};

return postRawRequest(window.RESEND_VERIFICATION_EMAIL_ENDPOINT)(params, {'X-CSRF-TOKEN': token});
}
Loading
Loading