Skip to content
Snippets Groups Projects
Unverified Commit 6486fee7 authored by Ahmad Farhat's avatar Ahmad Farhat Committed by GitHub
Browse files

Changes to local accounts (#5489)

* Changes to local accounts

* rspec

* esf
parent ae6ef9c3
No related branches found
No related tags found
No related merge requests found
...@@ -81,6 +81,7 @@ ...@@ -81,6 +81,7 @@
"account_info": "Account Info", "account_info": "Account Info",
"delete_account": "Delete Account", "delete_account": "Delete Account",
"change_password": "Change Password", "change_password": "Change Password",
"set_password": "Set Your New Password",
"reset_password": "Reset Password", "reset_password": "Reset Password",
"update_account_info": "Update Account Info", "update_account_info": "Update Account Info",
"current_password": "Current Password", "current_password": "Current Password",
...@@ -358,6 +359,7 @@ ...@@ -358,6 +359,7 @@
"user_updated": "The user has been updated.", "user_updated": "The user has been updated.",
"user_deleted": "The user has been deleted.", "user_deleted": "The user has been deleted.",
"avatar_updated": "The avatar has been updated.", "avatar_updated": "The avatar has been updated.",
"password_changed": "Successfully updated your password. Please sign in again.",
"password_updated": "The password has been updated.", "password_updated": "The password has been updated.",
"account_activated": "Your account has been activated.", "account_activated": "Your account has been activated.",
"activation_email_sent": "An email that contains the instructions to activate your account has been sent.", "activation_email_sent": "An email that contains the instructions to activate your account has been sent.",
......
...@@ -90,8 +90,10 @@ module Api ...@@ -90,8 +90,10 @@ module Api
end end
# Checks if external authentication is enabled (currently only OIDC is implemented) # Checks if external authentication is enabled (currently only OIDC is implemented)
def external_authn_enabled? def external_auth?
ENV['OPENID_CONNECT_ISSUER'].present? return ENV['OPENID_CONNECT_ISSUER'].present? if ENV['LOADBALANCER_ENDPOINT'].blank?
!Tenant.exists?(name: current_provider, client_secret: 'local')
end end
end end
end end
......
...@@ -25,7 +25,7 @@ module Api ...@@ -25,7 +25,7 @@ module Api
# Returns basic NON-CONFIDENTIAL information on the environment variables # Returns basic NON-CONFIDENTIAL information on the environment variables
def index def index
render_data data: { render_data data: {
EXTERNAL_AUTH: ENV['OPENID_CONNECT_ISSUER'].present?, # currently only OIDC is implemented EXTERNAL_AUTH: external_auth?,
HCAPTCHA_KEY: ENV.fetch('HCAPTCHA_SITE_KEY', nil), HCAPTCHA_KEY: ENV.fetch('HCAPTCHA_SITE_KEY', nil),
VERSION_TAG: ENV.fetch('VERSION_TAG', ''), VERSION_TAG: ENV.fetch('VERSION_TAG', ''),
CURRENT_PROVIDER: current_provider, CURRENT_PROVIDER: current_provider,
......
...@@ -45,6 +45,12 @@ module Api ...@@ -45,6 +45,12 @@ module Api
# Will return an error if the user is NOT from the current provider and if the user is NOT a super admin # Will return an error if the user is NOT from the current provider and if the user is NOT a super admin
return render_error if user.provider != current_provider && !user.super_admin? return render_error if user.provider != current_provider && !user.super_admin?
# Password is not set (local user migrated from v2)
if user.external_id.blank? && user.password_digest.blank?
token = user.generate_reset_token!
return render_error data: token, errors: 'PasswordNotSet'
end
# TODO: Add proper error logging for non-verified token hcaptcha # TODO: Add proper error logging for non-verified token hcaptcha
if user.authenticate(session_params[:password]) if user.authenticate(session_params[:password])
return render_error data: user.id, errors: Rails.configuration.custom_error_msgs[:unverified_user] unless user.verified? return render_error data: user.id, errors: Rails.configuration.custom_error_msgs[:unverified_user] unless user.verified?
......
...@@ -39,7 +39,7 @@ module Api ...@@ -39,7 +39,7 @@ module Api
# POST /api/v1/users.json # POST /api/v1/users.json
# Creates and saves a new user record in the database with the provided parameters # Creates and saves a new user record in the database with the provided parameters
def create def create
return render_error status: :forbidden if external_authn_enabled? return render_error status: :forbidden if external_auth?
# Check if this is an admin creating a user # Check if this is an admin creating a user
admin_create = current_user && PermissionsChecker.new(current_user:, permission_names: 'ManageUsers', current_provider:).call admin_create = current_user && PermissionsChecker.new(current_user:, permission_names: 'ManageUsers', current_provider:).call
......
...@@ -17,11 +17,13 @@ ...@@ -17,11 +17,13 @@
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import Card from 'react-bootstrap/Card'; import Card from 'react-bootstrap/Card';
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import useVerifyToken from '../../../hooks/mutations/users/useVerifyToken'; import useVerifyToken from '../../../hooks/mutations/users/useVerifyToken';
import ResetPwdForm from './forms/ResetPwdForm'; import ResetPwdForm from './forms/ResetPwdForm';
import Logo from '../../shared_components/Logo'; import Logo from '../../shared_components/Logo';
export default function ResetPassword() { export default function ResetPassword() {
const { t } = useTranslation();
const { token } = useParams(); const { token } = useParams();
const verifyTokenAPI = useVerifyToken(token); const verifyTokenAPI = useVerifyToken(token);
...@@ -37,6 +39,7 @@ export default function ResetPassword() { ...@@ -37,6 +39,7 @@ export default function ResetPassword() {
<Logo /> <Logo />
</div> </div>
<Card className="col-xl-5 col-lg-6 col-md-8 col-10 mx-auto p-4 border-0 card-shadow"> <Card className="col-xl-5 col-lg-6 col-md-8 col-10 mx-auto p-4 border-0 card-shadow">
<Card.Title className="text-center pb-2"> { t('user.account.set_password') } </Card.Title>
<ResetPwdForm token={token} /> <ResetPwdForm token={token} />
</Card> </Card>
</div> </div>
......
...@@ -49,6 +49,8 @@ export default function useCreateSession() { ...@@ -49,6 +49,8 @@ export default function useCreateSession() {
toast.error(t('toast.error.users.banned')); toast.error(t('toast.error.users.banned'));
} else if (err.response.data.errors === 'UnverifiedUser') { } else if (err.response.data.errors === 'UnverifiedUser') {
navigate(`/verify?id=${err.response.data.data}`); navigate(`/verify?id=${err.response.data.data}`);
} else if (err.response.data.errors === 'PasswordNotSet') {
navigate(`/reset_password/${err.response.data.data}`);
} else { } else {
toast.error(t('toast.error.session.invalid_credentials')); toast.error(t('toast.error.session.invalid_credentials'));
} }
......
...@@ -28,7 +28,7 @@ export default function useResetPwd() { ...@@ -28,7 +28,7 @@ export default function useResetPwd() {
(user) => axios.post('/reset_password/reset.json', { user }), (user) => axios.post('/reset_password/reset.json', { user }),
{ {
onSuccess: () => { onSuccess: () => {
toast.success(t('toast.success.user.password_updated')); toast.success(t('toast.success.user.password_changed'));
navigate('/signin'); navigate('/signin');
}, },
onError: () => { onError: () => {
......
...@@ -25,7 +25,7 @@ RSpec.describe Api::V1::UsersController, type: :controller do ...@@ -25,7 +25,7 @@ RSpec.describe Api::V1::UsersController, type: :controller do
before do before do
ENV['SMTP_SERVER'] = 'test.com' ENV['SMTP_SERVER'] = 'test.com'
allow(controller).to receive(:external_authn_enabled?).and_return(false) allow(controller).to receive(:external_auth?).and_return(false)
request.headers['ACCEPT'] = 'application/json' request.headers['ACCEPT'] = 'application/json'
end end
...@@ -280,7 +280,7 @@ RSpec.describe Api::V1::UsersController, type: :controller do ...@@ -280,7 +280,7 @@ RSpec.describe Api::V1::UsersController, type: :controller do
context 'External AuthN enabled' do context 'External AuthN enabled' do
before do before do
allow(controller).to receive(:external_authn_enabled?).and_return(true) allow(controller).to receive(:external_auth?).and_return(true)
end end
it 'returns :forbidden without creating the user account' do it 'returns :forbidden without creating the user account' do
...@@ -472,9 +472,9 @@ RSpec.describe Api::V1::UsersController, type: :controller do ...@@ -472,9 +472,9 @@ RSpec.describe Api::V1::UsersController, type: :controller do
end end
context 'private methods' do context 'private methods' do
describe '#external_authn_enabled?' do describe '#external_auth??' do
before do before do
allow(controller).to receive(:external_authn_enabled?).and_call_original allow(controller).to receive(:external_auth?).and_call_original
end end
context 'OPENID_CONNECT_ISSUER is present?' do context 'OPENID_CONNECT_ISSUER is present?' do
...@@ -483,7 +483,7 @@ RSpec.describe Api::V1::UsersController, type: :controller do ...@@ -483,7 +483,7 @@ RSpec.describe Api::V1::UsersController, type: :controller do
end end
it 'returns true' do it 'returns true' do
expect(controller).to be_external_authn_enabled expect(controller).to be_external_auth
end end
end end
...@@ -493,7 +493,7 @@ RSpec.describe Api::V1::UsersController, type: :controller do ...@@ -493,7 +493,7 @@ RSpec.describe Api::V1::UsersController, type: :controller do
end end
it 'returns false' do it 'returns false' do
expect(controller).not_to be_external_authn_enabled expect(controller).not_to be_external_auth
end end
end end
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment