diff options
author | Mathieu Suen <mathieu.suen@sonarsource.com> | 2020-11-25 15:09:54 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-12-02 20:06:57 +0000 |
commit | 458cff671f946eecb5696d2f7f873e7004a81966 (patch) | |
tree | ffab993df100b8e8d1013efd242445fd70ec350e /server/sonar-web/src/main/js/apps/account | |
parent | f1c787ccd9b21b6af6859c74814e45c1e7faea01 (diff) | |
download | sonarqube-458cff671f946eecb5696d2f7f873e7004a81966.tar.gz sonarqube-458cff671f946eecb5696d2f7f873e7004a81966.zip |
SONAR-14175 Adding the reset password form.
Diffstat (limited to 'server/sonar-web/src/main/js/apps/account')
5 files changed, 3 insertions, 261 deletions
diff --git a/server/sonar-web/src/main/js/apps/account/components/Password.tsx b/server/sonar-web/src/main/js/apps/account/components/Password.tsx deleted file mode 100644 index c689719ece1..00000000000 --- a/server/sonar-web/src/main/js/apps/account/components/Password.tsx +++ /dev/null @@ -1,141 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2020 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import * as React from 'react'; -import { SubmitButton } from 'sonar-ui-common/components/controls/buttons'; -import { Alert } from 'sonar-ui-common/components/ui/Alert'; -import { translate } from 'sonar-ui-common/helpers/l10n'; -import { changePassword } from '../../../api/users'; - -interface Props { - user: T.LoggedInUser; -} - -interface State { - errors?: string[]; - success: boolean; -} - -export default class Password extends React.Component<Props, State> { - oldPassword!: HTMLInputElement; - password!: HTMLInputElement; - passwordConfirmation!: HTMLInputElement; - state: State = { - success: false - }; - - handleSuccessfulChange = () => { - this.oldPassword.value = ''; - this.password.value = ''; - this.passwordConfirmation.value = ''; - this.setState({ success: true, errors: undefined }); - }; - - setErrors = (errors: string[]) => { - this.setState({ success: false, errors }); - }; - - handleChangePassword = (event: React.FormEvent) => { - event.preventDefault(); - - const { user } = this.props; - const previousPassword = this.oldPassword.value; - const password = this.password.value; - const passwordConfirmation = this.passwordConfirmation.value; - - if (password !== passwordConfirmation) { - this.password.focus(); - this.setErrors([translate('user.password_doesnt_match_confirmation')]); - } else { - changePassword({ login: user.login, password, previousPassword }).then( - this.handleSuccessfulChange, - () => {} - ); - } - }; - - render() { - const { success, errors } = this.state; - - return ( - <section className="boxed-group"> - <h2 className="spacer-bottom">{translate('my_profile.password.title')}</h2> - - <form className="boxed-group-inner" onSubmit={this.handleChangePassword}> - {success && <Alert variant="success">{translate('my_profile.password.changed')}</Alert>} - - {errors && - errors.map((e, i) => ( - <Alert key={i} variant="error"> - {e} - </Alert> - ))} - - <div className="form-field"> - <label htmlFor="old_password"> - {translate('my_profile.password.old')} - <em className="mandatory">*</em> - </label> - <input - autoComplete="off" - id="old_password" - name="old_password" - ref={elem => (this.oldPassword = elem!)} - required={true} - type="password" - /> - </div> - <div className="form-field"> - <label htmlFor="password"> - {translate('my_profile.password.new')} - <em className="mandatory">*</em> - </label> - <input - autoComplete="off" - id="password" - name="password" - ref={elem => (this.password = elem!)} - required={true} - type="password" - /> - </div> - <div className="form-field"> - <label htmlFor="password_confirmation"> - {translate('my_profile.password.confirm')} - <em className="mandatory">*</em> - </label> - <input - autoComplete="off" - id="password_confirmation" - name="password_confirmation" - ref={elem => (this.passwordConfirmation = elem!)} - required={true} - type="password" - /> - </div> - <div className="form-field"> - <SubmitButton id="change-password"> - {translate('my_profile.password.submit')} - </SubmitButton> - </div> - </form> - </section> - ); - } -} diff --git a/server/sonar-web/src/main/js/apps/account/components/Security.tsx b/server/sonar-web/src/main/js/apps/account/components/Security.tsx index 49637c3ad6f..8ac25c7955a 100644 --- a/server/sonar-web/src/main/js/apps/account/components/Security.tsx +++ b/server/sonar-web/src/main/js/apps/account/components/Security.tsx @@ -21,8 +21,8 @@ import * as React from 'react'; import { Helmet } from 'react-helmet-async'; import { connect } from 'react-redux'; import { translate } from 'sonar-ui-common/helpers/l10n'; +import ResetPassword from '../../../components/common/ResetPassword'; import { getCurrentUser, Store } from '../../../store/rootReducer'; -import Password from './Password'; import Tokens from './Tokens'; export interface SecurityProps { @@ -34,7 +34,7 @@ export function Security({ user }: SecurityProps) { <div className="account-body account-container"> <Helmet defer={false} title={translate('my_account.security')} /> <Tokens login={user.login} /> - {user.local && <Password user={user} />} + {user.local && <ResetPassword user={user} />} </div> ); } diff --git a/server/sonar-web/src/main/js/apps/account/components/__tests__/Password-test.tsx b/server/sonar-web/src/main/js/apps/account/components/__tests__/Password-test.tsx deleted file mode 100644 index cfa84980386..00000000000 --- a/server/sonar-web/src/main/js/apps/account/components/__tests__/Password-test.tsx +++ /dev/null @@ -1,27 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2020 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -import { shallow } from 'enzyme'; -import * as React from 'react'; -import { mockLoggedInUser } from '../../../../helpers/testMocks'; -import Password from '../Password'; - -it('renders correctly', () => { - expect(shallow(<Password user={mockLoggedInUser()} />)).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/apps/account/components/__tests__/__snapshots__/Password-test.tsx.snap b/server/sonar-web/src/main/js/apps/account/components/__tests__/__snapshots__/Password-test.tsx.snap deleted file mode 100644 index e16485c7246..00000000000 --- a/server/sonar-web/src/main/js/apps/account/components/__tests__/__snapshots__/Password-test.tsx.snap +++ /dev/null @@ -1,90 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`renders correctly 1`] = ` -<section - className="boxed-group" -> - <h2 - className="spacer-bottom" - > - my_profile.password.title - </h2> - <form - className="boxed-group-inner" - onSubmit={[Function]} - > - <div - className="form-field" - > - <label - htmlFor="old_password" - > - my_profile.password.old - <em - className="mandatory" - > - * - </em> - </label> - <input - autoComplete="off" - id="old_password" - name="old_password" - required={true} - type="password" - /> - </div> - <div - className="form-field" - > - <label - htmlFor="password" - > - my_profile.password.new - <em - className="mandatory" - > - * - </em> - </label> - <input - autoComplete="off" - id="password" - name="password" - required={true} - type="password" - /> - </div> - <div - className="form-field" - > - <label - htmlFor="password_confirmation" - > - my_profile.password.confirm - <em - className="mandatory" - > - * - </em> - </label> - <input - autoComplete="off" - id="password_confirmation" - name="password_confirmation" - required={true} - type="password" - /> - </div> - <div - className="form-field" - > - <SubmitButton - id="change-password" - > - my_profile.password.submit - </SubmitButton> - </div> - </form> -</section> -`; diff --git a/server/sonar-web/src/main/js/apps/account/components/__tests__/__snapshots__/Security-test.tsx.snap b/server/sonar-web/src/main/js/apps/account/components/__tests__/__snapshots__/Security-test.tsx.snap index 46d08174e68..4adb1b2c1c2 100644 --- a/server/sonar-web/src/main/js/apps/account/components/__tests__/__snapshots__/Security-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/account/components/__tests__/__snapshots__/Security-test.tsx.snap @@ -12,7 +12,7 @@ exports[`should render correctly: local user 1`] = ` <Tokens login="luke" /> - <Password + <ResetPassword user={ Object { "groups": Array [], |