Skip to content

Commit c3b8750

Browse files
Merge branch 'IDAM-626-Bump-Client-app-dependencies-to-clear-dependabot-PRs' of https://github.com/nice-digital/identity-hostedpages into IDAM-626-Bump-Client-app-dependencies-to-clear-dependabot-PRs
2 parents 2d4af0a + 550be50 commit c3b8750

File tree

10 files changed

+98
-77
lines changed

10 files changed

+98
-77
lines changed

custom-pages/universal-login/src/components/ForgotPassword/ForgotPassword.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class ForgotPassword extends React.Component {
1111
super(props)
1212
this.auth = new AuthApi()
1313
this.state = {
14-
email: null,
14+
message: (props.location && props.location.state && props.location.state?.message) || null,
15+
value: (props.location && props.location.state && props.location.state?.email) || null,
1516
errors: {
1617
email: false
1718
},
@@ -23,7 +24,12 @@ class ForgotPassword extends React.Component {
2324

2425
forgotPassword = (event) => {
2526
if (event) event.preventDefault();
26-
27+
if(this.state.value)
28+
{
29+
const simulatedEvent = { target: document.getElementById('email') };
30+
this.handleChange(simulatedEvent);
31+
}
32+
2733
this.setState(function(state) {
2834
const tests = validateRegisterFields(this.state);
2935
const email = !state.email || tests.email();
@@ -112,14 +118,19 @@ class ForgotPassword extends React.Component {
112118
};
113119

114120
render() {
115-
const { serverSideError, errors, loading, email, isAD } = this.state;
121+
const { serverSideError, errors, loading, email, isAD, message } = this.state;
116122

117123
return (
118124
<div>
119125
<h2>Reset your password</h2>
126+
{message &&
127+
<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>
128+
}
129+
{!this.state.value && (
120130
<p className="lead">
121131
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.
122132
</p>
133+
)}
123134
<form className="">
124135
{serverSideError && (
125136
<Alert type="error">{serverSideError}</Alert>

custom-pages/universal-login/src/components/Login/Login.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class Login extends Component {
9797
console.log(JSON.stringify(err))
9898
);
9999

100-
if (this.validate()){
100+
if (this.validate()){
101101
try {
102102
this.setState({ loading: true, serverSideError: null }, () => {
103103
const { username, password, connection } = this.state
@@ -112,7 +112,8 @@ class Login extends Component {
112112
username,
113113
password,
114114
requestErrorCallback,
115-
isResumingAuthState
115+
isResumingAuthState,
116+
this.props.history || null
116117
)
117118
})
118119
} catch (err) {

custom-pages/universal-login/src/components/Login/__tests__/Login.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ describe('Login components', () => {
6969
password,
7070
expect.any(Function),
7171
null,
72+
null
7273
)
7374
})
7475

custom-pages/universal-login/src/components/Register/Register.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ class Register extends Component {
220220

221221
const errorMessages = {
222222
email: !email ? `Email - ${requiredMessage}` : 'Email address is in an invalid format',
223-
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. !@#$%^&*)',
223+
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. !@#$%^&*)',
224224
confirmPassword: !confirmPassword ? `Confirm password - ${requiredMessage}` : 'Password doesn\'t match',
225225
name: !name ? `First name - ${requiredMessage}` : 'First name should contain letters and should not exceed 100 characters',
226226
surname: !surname ? `Last name - ${requiredMessage}` : 'Last name should contain letters and should not exceed 100 characters',
@@ -453,4 +453,4 @@ class Register extends Component {
453453
}
454454
}
455455

456-
export default Register
456+
export default Register

custom-pages/universal-login/src/components/Register/__tests__/Register.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ describe('Register components', () => {
2222
instance.requestErrorCallback = functionSignature;
2323
props = {
2424
25-
password: 'Password01!',
26-
confirmPassword: 'Password01!',
25+
password: 'P@ssw0rd1234!&A',
26+
confirmPassword: 'P@ssw0rd1234!&A',
2727
name: 'Bruce',
2828
surname: 'Wayne',
2929
tAndC: 'false',

custom-pages/universal-login/src/components/ResetPassword/ResetPassword.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export class ResetPassword extends React.Component {
110110
label="Password"
111111
onChange={this.handleChange}
112112
error={errors.password}
113-
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. !@#$%^&*)"
113+
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. !@#$%^&*)"
114114
onBlur={this.validate}
115115
onFocus={this.clearError}
116116
aria-describedby="password-error"

custom-pages/universal-login/src/components/ResetPassword/__tests__/ResetPassword.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('ResetPassword components', () => {
4242
})
4343

4444
it('should call the AuthApi forgotPAssword when login is invoked', () => {
45-
const password = 'Password01!'
45+
const password = 'P@ssw0rd1234!&A'
4646
const history = undefined;
4747
el.setState({
4848
password,

custom-pages/universal-login/src/helpers/__tests__/validateRegisterFields.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('validateFields ', () => {
3535
})
3636
it('should return tests.password => falsey with valid password', () => {
3737
const passwordValidation = validateRegisterFields({
38-
password: 'Password01!'
38+
password: 'P@ssw0rd1234!&A'
3939
}).password()
4040
expect(passwordValidation).toBe(false)
4141
})
@@ -52,8 +52,8 @@ describe('validateFields ', () => {
5252
})
5353
it('should return tests.confirmPassword => true for invalid confirmPassword', () => {
5454
const confirmPasswordValidation = validateRegisterFields({
55-
password: 'PAssword01!',
56-
confirmPassword: 'Password01!'
55+
password: 'P@ssw0rd1234!&A',
56+
confirmPassword: 'P@ssw0rd1234!&'
5757
}).confirmPassword()
5858
expect(confirmPasswordValidation).toBe(true)
5959
})

custom-pages/universal-login/src/helpers/validateRegisterFields.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export const validateRegisterFields = ({
1414
return email && !emailRegex.test(email.toLowerCase())
1515
},
1616
password: () => {
17-
// 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. !@#$%^&*)
18-
const passwordRegex = /(?=.{8,})((?=.*\d)(?=.*[a-z])(?=.*[A-Z])|(?=.*\d)(?=.*[a-zA-Z])(?=.*[\W!@#$%^&*])|(?=.*[a-z])(?=.*[A-Z])(?=.*[\W!@#$%^&*])).*/
17+
// 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. !@#$%^&*)
18+
const passwordRegex = /(?=.{14,})((?=.*\d)(?=.*[a-z])(?=.*[A-Z])|(?=.*\d)(?=.*[a-zA-Z])(?=.*[\W!@#$%^&*])|(?=.*[a-z])(?=.*[A-Z])(?=.*[\W!@#$%^&*])).*/
1919
return password && !passwordRegex.test(password)
2020
},
2121
confirmPassword: () =>
@@ -29,4 +29,4 @@ export const validateRegisterFields = ({
2929
tAndC: () => password && email && name && surname && !tAndC
3030
});
3131

32-
export default validateRegisterFields
32+
export default validateRegisterFields

custom-pages/universal-login/src/services/AuthApi.js

Lines changed: 68 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Auth0 from 'auth0-js'
44
import qs from 'qs'
55
import { auth as authOpts, urls } from './constants'
66
import { ensureTrailingSlash } from '../helpers'
7+
import { validateRegisterFields } from '../helpers';
78

89
const __DEV__ = global.__DEV__ || false
910
export default class AuthApi {
@@ -78,72 +79,79 @@ export default class AuthApi {
7879
return acc
7980
}, {})
8081

81-
login(connection, username, password, errorCallback, resumeAuthState) {
82-
try {
83-
const redirectUri = window.config.extraParams.redirectURI;
84-
const tempCid = this.getCookie('_tempCid');
85-
let options
86-
let method
87-
if (connection === authOpts.connection) {
88-
options = {
89-
...this.params,
90-
realm: connection,
91-
username,
92-
password,
93-
temp_cid: tempCid
94-
}
95-
method = 'login'
96-
} else {
97-
options = {
98-
...this.params,
99-
connection,
100-
username,
101-
sso: true,
102-
login_hint: username,
103-
response_mode: 'form_post'
104-
}
105-
method = 'authorize'
106-
}
107-
if (redirectUri) {
108-
options.redirect_uri = redirectUri
109-
}
110-
if (!resumeAuthState) {
111-
this.instance[method](options, (err) => {
112-
if (err) {
113-
if (errorCallback) {
114-
setTimeout(() => errorCallback(err))
115-
}
116-
console.log(JSON.stringify(err))
82+
login(connection, username, password, errorCallback, resumeAuthState, history) {
83+
const tests = validateRegisterFields({password: password})
84+
const oldpasswordPolicy = tests.password()
85+
if(oldpasswordPolicy)
86+
{
87+
history.push('/forgotPassword', { message: true, email: username});
88+
} else {
89+
try {
90+
const redirectUri = window.config.extraParams.redirectURI;
91+
const tempCid = this.getCookie('_tempCid');
92+
let options
93+
let method
94+
if (connection === authOpts.connection) {
95+
options = {
96+
...this.params,
97+
realm: connection,
98+
username,
99+
password,
100+
temp_cid: tempCid
117101
}
118-
})
119-
} else {
120-
const GETOptions = qs.stringify(
121-
{ ...options, state: resumeAuthState },
122-
{ addQueryPrefix: true }
123-
)
124-
fetch(`/continue${GETOptions}`, {
125-
method: 'GET',
126-
headers: {
127-
Accept: 'application/json',
128-
'Content-Type': 'application/json'
102+
method = 'login'
103+
} else {
104+
options = {
105+
...this.params,
106+
connection,
107+
username,
108+
sso: true,
109+
login_hint: username,
110+
response_mode: 'form_post'
129111
}
130-
})
131-
.then((res) => {
132-
if (res.status === 200) {
133-
document.location = redirectUri
134-
} else if (errorCallback) {
135-
setTimeout(() => errorCallback(res))
112+
method = 'authorize'
113+
}
114+
if (redirectUri) {
115+
options.redirect_uri = redirectUri
116+
}
117+
if (!resumeAuthState) {
118+
this.instance[method](options, (err) => {
119+
if (err) {
120+
if (errorCallback) {
121+
setTimeout(() => errorCallback(err))
122+
}
123+
console.log(JSON.stringify(err))
136124
}
137125
})
138-
.catch((err) => {
139-
if (errorCallback) {
140-
setTimeout(() => errorCallback(err))
126+
} else {
127+
const GETOptions = qs.stringify(
128+
{ ...options, state: resumeAuthState },
129+
{ addQueryPrefix: true }
130+
)
131+
fetch(`/continue${GETOptions}`, {
132+
method: 'GET',
133+
headers: {
134+
Accept: 'application/json',
135+
'Content-Type': 'application/json'
141136
}
142137
})
138+
.then((res) => {
139+
if (res.status === 200) {
140+
document.location = redirectUri
141+
} else if (errorCallback) {
142+
setTimeout(() => errorCallback(res))
143+
}
144+
})
145+
.catch((err) => {
146+
if (errorCallback) {
147+
setTimeout(() => errorCallback(err))
148+
}
149+
})
150+
}
151+
} catch (err) {
152+
console.log(JSON.stringify(err))
143153
}
144-
} catch (err) {
145-
console.log(JSON.stringify(err))
146-
}
154+
}
147155
}
148156

149157
submitWSForm = (responseForm) => {
@@ -283,4 +291,4 @@ export default class AuthApi {
283291
console.log(`something has gone wrong when getting the cookie - ${regx}`);
284292
}
285293
}
286-
}
294+
}

0 commit comments

Comments
 (0)