-
Notifications
You must be signed in to change notification settings - Fork 1
Change password component #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bestinbthomas
wants to merge
9
commits into
master
Choose a base branch
from
change-password
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b429a78
Add ChangePassword component
bestinbthomas 5fede1a
get token from url
bestinbthomas c5dd4c3
add forgot password in login
bestinbthomas 3667210
fixup! add forgot password in login
bestinbthomas 43a49f3
fixup! fixup! add forgot password in login
bestinbthomas bc5d318
Add fixes
kumaran-14 aa64fde
change Forgot Password to Component
bestinbthomas c523e5e
fixup! change Forgot Password to Component
bestinbthomas b132c3a
fixup! fixup! change Forgot Password to Component
bestinbthomas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import * as authStyles from 'app/styles/Authentication.module.css'; | ||
import * as registerStyles from 'app/styles/Register.module.css'; | ||
import { changePasswordProps, ChangePasswordState } from 'app/types/Authentication/ChangePassword'; | ||
import classnames from 'classnames'; | ||
import * as React from 'react'; | ||
|
||
export class ChangePassword extends React.Component<changePasswordProps, ChangePasswordState> { | ||
private credentialsFormRef = React.createRef<HTMLFormElement>(); | ||
private passwordResetToken = ''; | ||
private userId = 0; | ||
constructor(props: changePasswordProps) { | ||
super(props); | ||
this.state = { | ||
password: '', | ||
passwordError: '', | ||
repeatPassword: '', | ||
}; | ||
} | ||
|
||
public componentDidMount() { | ||
// get string from url | ||
const search = this.props.location.search; | ||
const urlParams = search.split('&'); | ||
this.passwordResetToken = urlParams[0].split('=')[1]; | ||
this.userId = parseInt(urlParams[1].split('=')[1], 0); | ||
} | ||
|
||
public render() { | ||
return ( | ||
<div className={classnames(authStyles.registerRoot)}> | ||
<div className={classnames(authStyles.registerMessage)}> | ||
<h1 className={classnames(authStyles['register-h1'])}> Reset Password </h1> | ||
<p> Enter your new password </p> | ||
</div> | ||
<div className={classnames('col-sm-12', authStyles.form)}> | ||
<form | ||
className={classnames( | ||
'registerForm d-flex flex-wrap', | ||
authStyles['main-register-form'], | ||
)} | ||
noValidate | ||
> | ||
<div className={classnames(authStyles['stage-div'])}> | ||
<form | ||
className={classnames(authStyles['stage-form'])} | ||
noValidate | ||
ref={this.credentialsFormRef} | ||
> | ||
<div className={classnames(authStyles['login-label'])}> New Password </div> | ||
<div className={classnames(registerStyles['input-group'])}> | ||
<input | ||
type="password" | ||
className={classnames('form-control', authStyles['register-input'])} | ||
id="registerValidationPassword" | ||
aria-describedby="inputGroupPrepend" | ||
pattern=".{5,}" | ||
value={this.state.password} | ||
onChange={(e) => | ||
this.setState({ | ||
password: e.target.value, | ||
}) | ||
} | ||
required | ||
/> | ||
<div className={classnames('invalid-feedback', authStyles['register-error'])}> | ||
Password should have minimum 5 characters. | ||
</div> | ||
</div> | ||
<div className={classnames(authStyles['login-label'])}> Confirm Password </div> | ||
<div className={classnames(registerStyles['input-group'])}> | ||
<input | ||
type="password" | ||
className={classnames('form-control', authStyles['register-input'])} | ||
id="registerValidationrepeatPassword" | ||
aria-describedby="inputGroupPrepend" | ||
pattern=".{5,}" | ||
value={this.state.repeatPassword} | ||
onChange={(e) => | ||
this.setState({ | ||
repeatPassword: e.target.value, | ||
}) | ||
} | ||
required | ||
/> | ||
</div> | ||
|
||
<div | ||
className={ | ||
this.state.passwordError !== '' || this.props.errorMessage !== '' | ||
? classnames('form-row', authStyles['register-error-active']) | ||
: classnames('form-row', authStyles['register-error-inactive']) | ||
} | ||
> | ||
<div | ||
className={classnames( | ||
'col text-center mt -0 mb-2 errorMessage', | ||
registerStyles.errorMessage, | ||
)} | ||
> | ||
{this.state.passwordError} | ||
{'\n'} | ||
{this.props.errorMessage} | ||
</div> | ||
</div> | ||
<div | ||
className={classnames( | ||
registerStyles['input-group'], | ||
'd-flex justify-content-center', | ||
)} | ||
> | ||
<button | ||
className={classnames(authStyles['register-button'])} | ||
onClick={(e) => this.submitPassword(e)} | ||
> | ||
Confirm | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
private submitPassword = (e: React.MouseEvent) => { | ||
e.preventDefault(); | ||
if (this.state.password === this.state.repeatPassword) { | ||
if (this.credentialsFormRef.current) { | ||
this.credentialsFormRef.current.classList.add('was-validated'); | ||
if (this.credentialsFormRef.current.checkValidity()) { | ||
this.setState({ | ||
...this.state, | ||
passwordError: '', | ||
}); | ||
this.props.changePassword(this.state.password, this.passwordResetToken, this.userId); | ||
} | ||
} | ||
} else { | ||
this.setState({ | ||
...this.state, | ||
passwordError: 'Password and confirm passwords have different values', | ||
}); | ||
} | ||
}; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import * as styles from 'app/styles/Authentication.module.css'; | ||
import classnames from 'classnames'; | ||
import * as React from 'react'; | ||
import { Col, Row } from 'react-bootstrap'; | ||
import * as registerStyles from 'app/styles/Register.module.css'; | ||
import { Routes } from 'app/routes'; | ||
import * as LoginInterfaces from 'app/types/Authentication/Login'; | ||
import { AuthType } from 'app/types/Authentication'; | ||
|
||
// tslint:disable-next-line: variable-name | ||
const ForgotPassword = (props: LoginInterfaces.ForgotPasswordProps) => { | ||
const forgotPasswordRef = React.createRef<HTMLFormElement>(); | ||
const [username, setUsername] = React.useState(''); | ||
|
||
const handleForgotPassword = (event: React.FormEvent<HTMLFormElement>) => { | ||
const form = forgotPasswordRef.current; | ||
|
||
event.preventDefault(); | ||
if (form) { | ||
if (form.checkValidity()) { | ||
props.forgotPassword(username); | ||
} | ||
form.classList.add('was-validated'); | ||
} | ||
}; | ||
bestinbthomas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return ( | ||
<div> | ||
<div className={classnames(styles.loginRoot)}> | ||
<div className={classnames(styles.welcomeBack)}> | ||
<h1> Forgot your password? </h1> | ||
</div> | ||
<Row> | ||
<Col className="text-center my-3 ml-auto mr-auto"> | ||
<div className="text-dark"> | ||
Don't have an account? | ||
<a | ||
href={Routes.REGISTER} | ||
className={classnames(styles['create-one-button'])} | ||
onClick={() => { | ||
props.updateErrorMessage(''); | ||
props.handleSelectPanel(AuthType.REGISTER); | ||
}} | ||
> | ||
Create one | ||
</a> | ||
<Row> | ||
<div className={classnames('col-sm-10', styles.form)}> | ||
<form | ||
className={classnames(styles.loginForm)} | ||
noValidate | ||
ref={forgotPasswordRef} | ||
onSubmit={handleForgotPassword} | ||
> | ||
<div className="form-row"> | ||
<div className="col mb-4"> | ||
<div className={classnames(styles['login-label'])}> Your Email: </div> | ||
<div className="input-group"> | ||
<input | ||
type="email" | ||
className={classnames('form-control', styles['login-input'])} | ||
id="validationUsername" | ||
aria-describedby="inputGroupPrepend" | ||
required | ||
value={username} | ||
onChange={(e) => setUsername(e.target.value)} | ||
/> | ||
<div className={classnames('invalid-feedback', styles['login-error'])}> | ||
{' '} | ||
Please enter a valid Email.{' '} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div className={classnames('form-row', styles['error-row'])}> | ||
<div | ||
className={ | ||
!props.errorMessage | ||
? classnames( | ||
'col text-center mt-0 mb-2 ', | ||
styles['register-error-inactive'], | ||
registerStyles.errorMessage, | ||
) | ||
: classnames( | ||
'col text-center mt-0 mb-2 errorMessage', | ||
styles['register-error-active'], | ||
registerStyles.errorMessageLogin, | ||
styles['login-error-active'], | ||
) | ||
} | ||
> | ||
{props.errorMessage} | ||
</div> | ||
</div> | ||
<div className="form-row"> | ||
<div className="col text-center"> | ||
<button | ||
className={classnames('btn btn-info', styles.loginButton)} | ||
type="submit" | ||
> | ||
Reset Password | ||
</button> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
</Row> | ||
</div> | ||
</Col> | ||
</Row> | ||
<Row> | ||
<Col className="text-center my-3 ml-auto mr-auto"> | ||
<div | ||
className={classnames('text-dark', styles['forgot-your-password'])} | ||
onClick={() => props.closeForgotPassword()} | ||
> | ||
Back{' '} | ||
</div> | ||
</Col> | ||
</Row> | ||
<Row> | ||
<Col className="text-center my-3 ml-auto mr-auto"> | ||
<div className="text-dark"> | ||
Don't have an account?{' '} | ||
<a | ||
href={Routes.REGISTER} | ||
className={classnames(styles['create-one-button'])} | ||
onClick={() => { | ||
props.updateErrorMessage(''); | ||
props.handleSelectPanel(AuthType.REGISTER); | ||
}} | ||
> | ||
Create one | ||
</a> | ||
</div> | ||
</Col> | ||
</Row> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ForgotPassword; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.