Skip to content

Commit

Permalink
Merge branch 'master' into IDAM-626-Bump-Client-app-dependencies-to-c…
Browse files Browse the repository at this point in the history
…lear-dependabot-PRs
  • Loading branch information
mgallagher1980 authored Jan 7, 2025
2 parents 6427dad + 5ac7624 commit 550be50
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class ForgotPassword extends React.Component {
super(props)
this.auth = new AuthApi()
this.state = {
email: null,
message: (props.location && props.location.state && props.location.state?.message) || null,
value: (props.location && props.location.state && props.location.state?.email) || null,
errors: {
email: false
},
Expand All @@ -23,7 +24,12 @@ class ForgotPassword extends React.Component {

forgotPassword = (event) => {
if (event) event.preventDefault();

if(this.state.value)
{
const simulatedEvent = { target: document.getElementById('email') };
this.handleChange(simulatedEvent);
}

this.setState(function(state) {
const tests = validateRegisterFields(this.state);
const email = !state.email || tests.email();
Expand Down Expand Up @@ -112,14 +118,19 @@ class ForgotPassword extends React.Component {
};

render() {
const { serverSideError, errors, loading, email, isAD } = this.state;
const { serverSideError, errors, loading, email, isAD, message } = this.state;

return (
<div>
<h2>Reset your password</h2>
{message &&
<p class="alert alert--error">Our password policy has been updated. You will need to provide a password that is at least 14 characters in length and contains at least 3 of the following 4 types of characters: lower case letters (a-z), upper case letters (A-Z), numbers (i.e. 0-9) and special characters (e.g. !@#$%^&*). <br/><br/>Click the reset button below and we'll send you an email with a link to help you reset your password.</p>
}
{!this.state.value && (
<p className="lead">
Enter the email address you registered with in the box below and click the reset button. We'll send you an email with a link to help you reset your password.
</p>
)}
<form className="">
{serverSideError && (
<Alert type="error">{serverSideError}</Alert>
Expand Down
5 changes: 3 additions & 2 deletions custom-pages/universal-login/src/components/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Login extends Component {
console.log(JSON.stringify(err))
);

if (this.validate()){
if (this.validate()){
try {
this.setState({ loading: true, serverSideError: null }, () => {
const { username, password, connection } = this.state
Expand All @@ -112,7 +112,8 @@ class Login extends Component {
username,
password,
requestErrorCallback,
isResumingAuthState
isResumingAuthState,
this.props.history || null
)
})
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe('Login components', () => {
password,
expect.any(Function),
null,
null
)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class Register extends Component {

const errorMessages = {
email: !email ? `Email - ${requiredMessage}` : 'Email address is in an invalid format',
password: !password ? `Password - ${requiredMessage}` : 'Please provide a password with least 8 characters in length, contain at least 3 of the following 4 types of characters: lower case letters (a-z), upper case letters (A-Z), numbers (i.e. 0-9) and special characters (e.g. !@#$%^&*)',
password: !password ? `Password - ${requiredMessage}` : 'Please provide a password with at least 14 characters in length, contains at least 3 of the following 4 types of characters: lower case letters (a-z), upper case letters (A-Z), numbers (i.e. 0-9) and special characters (e.g. !@#$%^&*)',
confirmPassword: !confirmPassword ? `Confirm password - ${requiredMessage}` : 'Password doesn\'t match',
name: !name ? `First name - ${requiredMessage}` : 'First name should contain letters and should not exceed 100 characters',
surname: !surname ? `Last name - ${requiredMessage}` : 'Last name should contain letters and should not exceed 100 characters',
Expand Down Expand Up @@ -453,4 +453,4 @@ class Register extends Component {
}
}

export default Register
export default Register
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe('Register components', () => {
instance.requestErrorCallback = functionSignature;
props = {
email: '[email protected]',
password: 'Password01!',
confirmPassword: 'Password01!',
password: 'P@ssw0rd1234!&A',
confirmPassword: 'P@ssw0rd1234!&A',
name: 'Bruce',
surname: 'Wayne',
tAndC: 'false',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class ResetPassword extends React.Component {
label="Password"
onChange={this.handleChange}
error={errors.password}
errorMessage="Please provide a password with least 8 characters in length, contain at least 3 of the following 4 types of characters: lower case letters (a-z), upper case letters (A-Z), numbers (i.e. 0-9) and special characters (e.g. !@#$%^&*)"
errorMessage="Please provide a password with at least 14 characters in length, contains at least 3 of the following 4 types of characters: lower case letters (a-z), upper case letters (A-Z), numbers (i.e. 0-9) and special characters (e.g. !@#$%^&*)"
onBlur={this.validate}
onFocus={this.clearError}
aria-describedby="password-error"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('ResetPassword components', () => {
})

it('should call the AuthApi forgotPAssword when login is invoked', () => {
const password = 'Password01!'
const password = 'P@ssw0rd1234!&A'
const history = undefined;
el.setState({
password,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('validateFields ', () => {
})
it('should return tests.password => falsey with valid password', () => {
const passwordValidation = validateRegisterFields({
password: 'Password01!'
password: 'P@ssw0rd1234!&A'
}).password()
expect(passwordValidation).toBe(false)
})
Expand All @@ -52,8 +52,8 @@ describe('validateFields ', () => {
})
it('should return tests.confirmPassword => true for invalid confirmPassword', () => {
const confirmPasswordValidation = validateRegisterFields({
password: 'PAssword01!',
confirmPassword: 'Password01!'
password: 'P@ssw0rd1234!&A',
confirmPassword: 'P@ssw0rd1234!&'
}).confirmPassword()
expect(confirmPasswordValidation).toBe(true)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const validateRegisterFields = ({
return email && !emailRegex.test(email.toLowerCase())
},
password: () => {
// At least 8 characters in length↵* Contain at least 3 of the following 4 types of characters:↵ * lower case letters (a-z)↵ * upper case letters (A-Z)↵ * numbers (i.e. 0-9)↵ * special characters (e.g. !@#$%^&*)
const passwordRegex = /(?=.{8,})((?=.*\d)(?=.*[a-z])(?=.*[A-Z])|(?=.*\d)(?=.*[a-zA-Z])(?=.*[\W!@#$%^&*])|(?=.*[a-z])(?=.*[A-Z])(?=.*[\W!@#$%^&*])).*/
// At least 14 characters in length↵* Contain at least 3 of the following 4 types of characters:↵ * lower case letters (a-z)↵ * upper case letters (A-Z)↵ * numbers (i.e. 0-9)↵ * special characters (e.g. !@#$%^&*)
const passwordRegex = /(?=.{14,})((?=.*\d)(?=.*[a-z])(?=.*[A-Z])|(?=.*\d)(?=.*[a-zA-Z])(?=.*[\W!@#$%^&*])|(?=.*[a-z])(?=.*[A-Z])(?=.*[\W!@#$%^&*])).*/
return password && !passwordRegex.test(password)
},
confirmPassword: () =>
Expand All @@ -29,4 +29,4 @@ export const validateRegisterFields = ({
tAndC: () => password && email && name && surname && !tAndC
});

export default validateRegisterFields
export default validateRegisterFields
128 changes: 68 additions & 60 deletions custom-pages/universal-login/src/services/AuthApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Auth0 from 'auth0-js'
import qs from 'qs'
import { auth as authOpts, urls } from './constants'
import { ensureTrailingSlash } from '../helpers'
import { validateRegisterFields } from '../helpers';

const __DEV__ = global.__DEV__ || false
export default class AuthApi {
Expand Down Expand Up @@ -78,72 +79,79 @@ export default class AuthApi {
return acc
}, {})

login(connection, username, password, errorCallback, resumeAuthState) {
try {
const redirectUri = window.config.extraParams.redirectURI;
const tempCid = this.getCookie('_tempCid');
let options
let method
if (connection === authOpts.connection) {
options = {
...this.params,
realm: connection,
username,
password,
temp_cid: tempCid
}
method = 'login'
} else {
options = {
...this.params,
connection,
username,
sso: true,
login_hint: username,
response_mode: 'form_post'
}
method = 'authorize'
}
if (redirectUri) {
options.redirect_uri = redirectUri
}
if (!resumeAuthState) {
this.instance[method](options, (err) => {
if (err) {
if (errorCallback) {
setTimeout(() => errorCallback(err))
}
console.log(JSON.stringify(err))
login(connection, username, password, errorCallback, resumeAuthState, history) {
const tests = validateRegisterFields({password: password})
const oldpasswordPolicy = tests.password()
if(oldpasswordPolicy)
{
history.push('/forgotPassword', { message: true, email: username});
} else {
try {
const redirectUri = window.config.extraParams.redirectURI;
const tempCid = this.getCookie('_tempCid');
let options
let method
if (connection === authOpts.connection) {
options = {
...this.params,
realm: connection,
username,
password,
temp_cid: tempCid
}
})
} else {
const GETOptions = qs.stringify(
{ ...options, state: resumeAuthState },
{ addQueryPrefix: true }
)
fetch(`/continue${GETOptions}`, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
method = 'login'
} else {
options = {
...this.params,
connection,
username,
sso: true,
login_hint: username,
response_mode: 'form_post'
}
})
.then((res) => {
if (res.status === 200) {
document.location = redirectUri
} else if (errorCallback) {
setTimeout(() => errorCallback(res))
method = 'authorize'
}
if (redirectUri) {
options.redirect_uri = redirectUri
}
if (!resumeAuthState) {
this.instance[method](options, (err) => {
if (err) {
if (errorCallback) {
setTimeout(() => errorCallback(err))
}
console.log(JSON.stringify(err))
}
})
.catch((err) => {
if (errorCallback) {
setTimeout(() => errorCallback(err))
} else {
const GETOptions = qs.stringify(
{ ...options, state: resumeAuthState },
{ addQueryPrefix: true }
)
fetch(`/continue${GETOptions}`, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
})
.then((res) => {
if (res.status === 200) {
document.location = redirectUri
} else if (errorCallback) {
setTimeout(() => errorCallback(res))
}
})
.catch((err) => {
if (errorCallback) {
setTimeout(() => errorCallback(err))
}
})
}
} catch (err) {
console.log(JSON.stringify(err))
}
} catch (err) {
console.log(JSON.stringify(err))
}
}
}

submitWSForm = (responseForm) => {
Expand Down Expand Up @@ -283,4 +291,4 @@ export default class AuthApi {
console.log(`something has gone wrong when getting the cookie - ${regx}`);
}
}
}
}

6 comments on commit 550be50

@NICE-TeamCity
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Identity and Access Management / Identity - Hosted pages Build 2102 is now running

@NICE-TeamCity
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Identity and Access Management / Identity - Hosted pages Build 2102-IDAM-626-Bump-Client outcome was FAILURE
Summary: Tests failed: 11, passed: 35 Build time: 00:01:22

Failed tests

__tests__/Login.test.js: Generic test suite failure: <no details avaliable>

__tests__/ResetPassword.test.js: Generic test suite failure: <no details avaliable>

__tests__/Register.test.js: Generic test suite failure: <no details avaliable>

__tests__/ForgotPassword.test.js: Generic test suite failure: <no details avaliable>

__tests__/App.test.js: Generic test suite failure: <no details avaliable>

__tests__/ForgotPasswordSuccess.test.js: Generic test suite failure: <no details avaliable>

__tests__/ResetPasswordSuccess.test.js: Generic test suite failure: <no details avaliable>

__tests__/RegisterSuccess.test.js: Generic test suite failure: <no details avaliable>

__tests__/NotFound.test.js: Generic test suite failure: <no details avaliable>

__tests__/Header.test.js: Generic test suite failure: <no details avaliable>

__tests__/constants.test.js: Generic test suite failure: <no details avaliable>


##### there are 1 more failed tests, see build details

@NICE-TeamCity
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Identity and Access Management / Identity - Hosted pages Build 2103 is now running

@NICE-TeamCity
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Identity and Access Management / Identity - Hosted pages Build 2103-IDAM-626-Bump-Client outcome was FAILURE
Summary: Tests failed: 11, passed: 35 Build time: 00:01:18

Failed tests

__tests__/Login.test.js: Generic test suite failure: <no details avaliable>

__tests__/ResetPassword.test.js: Generic test suite failure: <no details avaliable>

__tests__/Register.test.js: Generic test suite failure: <no details avaliable>

__tests__/ForgotPassword.test.js: Generic test suite failure: <no details avaliable>

__tests__/App.test.js: Generic test suite failure: <no details avaliable>

__tests__/ForgotPasswordSuccess.test.js: Generic test suite failure: <no details avaliable>

__tests__/ResetPasswordSuccess.test.js: Generic test suite failure: <no details avaliable>

__tests__/RegisterSuccess.test.js: Generic test suite failure: <no details avaliable>

__tests__/NotFound.test.js: Generic test suite failure: <no details avaliable>

__tests__/Header.test.js: Generic test suite failure: <no details avaliable>

__tests__/constants.test.js: Generic test suite failure: <no details avaliable>


##### there are 1 more failed tests, see build details

@NICE-TeamCity
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Identity and Access Management / Identity - Hosted pages Build 2104 is now running

@NICE-TeamCity
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Identity and Access Management / Identity - Hosted pages Build 2104-IDAM-626-Bump-Client outcome was FAILURE
Summary: Tests failed: 11, passed: 35 Build time: 00:01:12

Failed tests

__tests__/Login.test.js: Generic test suite failure: <no details avaliable>

__tests__/ResetPassword.test.js: Generic test suite failure: <no details avaliable>

__tests__/Register.test.js: Generic test suite failure: <no details avaliable>

__tests__/ForgotPassword.test.js: Generic test suite failure: <no details avaliable>

__tests__/App.test.js: Generic test suite failure: <no details avaliable>

__tests__/ForgotPasswordSuccess.test.js: Generic test suite failure: <no details avaliable>

__tests__/ResetPasswordSuccess.test.js: Generic test suite failure: <no details avaliable>

__tests__/RegisterSuccess.test.js: Generic test suite failure: <no details avaliable>

__tests__/NotFound.test.js: Generic test suite failure: <no details avaliable>

__tests__/Header.test.js: Generic test suite failure: <no details avaliable>

__tests__/constants.test.js: Generic test suite failure: <no details avaliable>


##### there are 1 more failed tests, see build details

Please sign in to comment.