Skip to content
This repository was archived by the owner on Mar 28, 2022. It is now read-only.

Commit 0549d5d

Browse files
authored
Merge pull request #115 from seknox/fix-#111
Fix for #111 and #112
2 parents 6854eed + b5ef883 commit 0549d5d

File tree

5 files changed

+94
-31
lines changed

5 files changed

+94
-31
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { configure, mount } from 'enzyme';
2+
import Adapter from 'enzyme-adapter-react-16';
3+
import React from 'react';
4+
import { SetPasswordComponent } from './PasswordSetupReset';
5+
6+
7+
jest.setTimeout(30000);
8+
9+
configure({ adapter: new Adapter() });
10+
11+
const cPassData = {
12+
password: 'cH@ng3meNever1#a',
13+
cpassword: 'cH@ng3meNever1#a',
14+
};
15+
16+
17+
describe('Test change password component', () => {
18+
19+
20+
test('submit button should be enabled by default', () => {
21+
const page = mount(<SetPasswordComponent update={false} token={'12345'} />);
22+
23+
24+
expect(page.find('super')).toBeTruthy();
25+
26+
const button = page.find('button').first()
27+
expect(button.props().disabled).toBe(false);
28+
29+
30+
});
31+
32+
33+
34+
35+
36+
37+
});

dashboard/src/pages/Publicpages/PasswordSetupReset.tsx

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
FirstTimePasswordSetup does two things. validate user setPassword token.
2+
FirstTimePasswordSetup does two things. validate user setPassword token.
33
If the token is validated, present change password card or display invalid token alert.
44
55
*/
@@ -24,30 +24,31 @@ const useStyles = makeStyles((theme) => ({
2424
root: {
2525
flexGrow: 1,
2626
marginTop: '5%',
27-
marginLeft: '30%',
27+
marginLeft: '40%',
2828
},
2929
checkInbox: {
3030
fontSize: 15,
3131
color: 'green',
3232
},
3333
// //card
3434
card: {
35-
minWidth: 275,
36-
// marginLeft: '50%',
35+
minWidth: 250,
36+
maxWidth: 300,
37+
3738
},
3839
textFieldRoot: {
3940
padding: 1,
4041
'label + &': {
4142
marginTop: theme.spacing(3),
4243
},
44+
maxWidth: '200px'
4345
},
4446
textFieldInputBig: {
4547
borderRadius: 4,
4648
backgroundColor: theme.palette.common.white,
4749
border: '1px solid #ced4da',
4850
fontSize: 16,
49-
// padding: '10px 100px',
50-
// width: 'calc(100% - 4px)',
51+
5152
transition: theme.transitions.create(['border-color', 'box-shadow']),
5253
'&:focus': {
5354
borderColor: '#80bdff',
@@ -64,6 +65,7 @@ const useStyles = makeStyles((theme) => ({
6465
fontWeight: 'bold',
6566
fontFamily: 'Open Sans ,Rajdhani',
6667
},
68+
6769
}));
6870

6971
type ValidatesetPasswordTokenProps = {
@@ -96,15 +98,14 @@ export default function ValidatesetPasswordToken(props: ValidatesetPasswordToken
9698

9799
return (
98100
<div>
99-
<div>
100-
{/* Herein starts inner comopnents. we add create user component and user view component */}
101+
101102

102103
{showSetPasswordCard ? (
103104
<SetPasswordComponent update={false} token={token} />
104105
) : (
105-
' Aww Snap. Good guess but your token is invalid '
106-
)}
107-
</div>
106+
' Aww Snap. Good guess but your token is invalid '
107+
)}
108+
108109
</div>
109110
);
110111
}
@@ -128,6 +129,8 @@ export function SetPasswordComponent(props: SetPasswordComponentProps) {
128129
// const [password, setPassword] = useState('');
129130
const [zscore, setZScore] = useState<zxcvbn.ZXCVBNScore>(0);
130131

132+
133+
131134
const classes = useStyles();
132135

133136
const zxcvbnscore = () => {
@@ -137,17 +140,26 @@ export function SetPasswordComponent(props: SetPasswordComponentProps) {
137140
};
138141

139142
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
140-
// const email = e.target.value;
141-
// setState({data});
143+
142144
setData({ ...data, [event.target.name]: event.target.value });
145+
zxcvbnscore()
146+
143147

144-
// setState({country: event.target.value});
145-
if (event.target.name === 'cpassword') {
146-
zxcvbnscore();
147-
}
148148
};
149149

150150
const handleSubmit = (event: React.FormEvent<{}>) => {
151+
if (data.password !== data.cpassword) {
152+
alert('Your passwords does not match')
153+
return
154+
155+
}
156+
157+
if (zscore < 2) {
158+
alert('Please enter strong password (the password strength should indicate "Good")')
159+
return
160+
}
161+
162+
151163
setLoader(true);
152164
const reqData = data;
153165
event.preventDefault();
@@ -192,19 +204,20 @@ export function SetPasswordComponent(props: SetPasswordComponentProps) {
192204
Good to Login! <br />
193205
</Typography>
194206
) : (
195-
''
196-
)}
207+
''
208+
)}
197209

198210
<br />
199211
<form onSubmit={handleSubmit}>
200212
<Grid container spacing={2} alignItems="center" direction="row" justify="center">
201-
<Grid item xs={6}>
213+
<Grid item xs={12} >
202214
<TextField
203215
fullWidth
204216
label="Password"
205217
onChange={handleChange}
206218
name="password"
207219
type="password"
220+
autoFocus
208221
value={data.password}
209222
InputProps={{
210223
disableUnderline: true,
@@ -219,11 +232,10 @@ export function SetPasswordComponent(props: SetPasswordComponentProps) {
219232
}}
220233
/>
221234
<div>
222-
{/* <TextField className={classes.selectCustom} autoComplete="off" type="password" onChange={e => setState({ password: e.target.value })} /> */}
223235
<PassStrength password={data.password} />
224236
</div>
225237
</Grid>
226-
<Grid item xs={6}>
238+
<Grid item xs={12} >
227239
<TextField
228240
fullWidth
229241
label="Confirm Password"
@@ -244,15 +256,14 @@ export function SetPasswordComponent(props: SetPasswordComponentProps) {
244256
}}
245257
/>
246258
<div>
247-
{/* <TextField className={classes.selectCustom} autoComplete="off" type="password" onChange={e => setState({ password: e.target.value })} /> */}
248259
<PassStrength password={data.cpassword} />
249260
</div>
250261
</Grid>
251262
</Grid>
252263

253264
<Grid container spacing={2} alignItems="center" direction="row" justify="flex-end">
254265
<Grid item xs={6}>
255-
<Button disabled={zscore < 2} variant="contained" color="primary" type="submit">
266+
<Button variant="contained" color="primary" name="submit" type="submit">
256267
Submit
257268
</Button>
258269
</Grid>

dashboard/src/utils/Components/PassStrengthMeter.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
.password-strength-meter {
2+
margin-top: 5px;
3+
margin-bottom: 5px;
24
text-align: left;
35
}
46

57
.password-strength-meter-progress {
68
-webkit-appearance: none;
79
appearance: none;
8-
width: 220px;
10+
width: 200px;
911
height: 8px;
1012
}
1113

@@ -15,6 +17,7 @@
1517
}
1618

1719
.password-strength-meter-label {
20+
position: 'absolute';
1821
font-size: 14px;
1922
}
2023

dashboard/src/utils/Components/PasswordStrengthMeter.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,19 @@ function PasswordStrengthMeter(props: any) {
2929
<progress
3030
className={`password-strength-meter-progress strength-${createPasswordLabel(testedResult)}`}
3131
value={testedResult.score}
32-
max="4"
32+
max="5"
3333
/>
34-
<br />
35-
<form>
34+
35+
3636
<label className="password-strength-meter-label">
37+
3738
{password && (
3839
<div>
3940
<strong>Password strength:</strong> {createPasswordLabel(testedResult)}
4041
</div>
4142
)}
4243
</label>
43-
</form>
44+
4445
</div>
4546
);
4647
}

server/api/my/hPassword.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ func ForgotPassword(w http.ResponseWriter, r *http.Request) {
6565
}
6666

6767
type setPassword struct {
68-
Token string `json:"token"`
69-
Password string `json:"password"`
68+
Token string `json:"token"`
69+
Password string `json:"password"`
70+
CPassword string `json:"cpassword"`
7071
}
7172

7273
// FirstTimePasswordSetup used in case of forget password and after user account is created for first time.
@@ -80,6 +81,11 @@ func FirstTimePasswordSetup(w http.ResponseWriter, r *http.Request) {
8081
return
8182
}
8283

84+
if strings.Compare(req.Password, req.CPassword) != 0 {
85+
utils.TrasaResponse(w, 200, "failed", "password mismatch", "ChangePassword")
86+
return
87+
}
88+
8389
res, err := redis.Store.MGet(req.Token, "orguser", "intent")
8490
if err != nil {
8591
logrus.Error(err)
@@ -120,6 +126,11 @@ func ChangePassword(w http.ResponseWriter, r *http.Request) {
120126
return
121127
}
122128

129+
if strings.Compare(req.Password, req.CPassword) != 0 {
130+
utils.TrasaResponse(w, 200, "failed", "password mismatch", "ChangePassword")
131+
return
132+
}
133+
123134
err := updatePassword(uc.User.ID, uc.User.OrgID, req)
124135
if err != nil {
125136
logrus.Error(err)

0 commit comments

Comments
 (0)