From 2ebd96015428ca5616f0debaf98c10edb676824f Mon Sep 17 00:00:00 2001 From: Philipp Czora Date: Wed, 7 Nov 2018 17:05:46 +0100 Subject: [PATCH] Use HATEOAS link to change password --- scm-ui-components/packages/ui-types/src/Me.js | 5 ++++- scm-ui/src/containers/ChangeUserPassword.js | 12 ++++-------- scm-ui/src/containers/Profile.js | 3 +-- scm-ui/src/modules/auth.js | 8 +++++--- scm-ui/src/users/components/PasswordConfirmation.js | 1 - scm-ui/src/users/components/SetUserPassword.js | 1 - ...updatePassword.test.js => changePassword.test.js} | 0 7 files changed, 14 insertions(+), 16 deletions(-) rename scm-ui/src/users/components/{updatePassword.test.js => changePassword.test.js} (100%) diff --git a/scm-ui-components/packages/ui-types/src/Me.js b/scm-ui-components/packages/ui-types/src/Me.js index ab67debae7..12516ade1b 100644 --- a/scm-ui-components/packages/ui-types/src/Me.js +++ b/scm-ui-components/packages/ui-types/src/Me.js @@ -1,7 +1,10 @@ // @flow +import type { Links } from "./hal"; + export type Me = { name: string, displayName: string, - mail: string + mail: string, + _links: Links }; diff --git a/scm-ui/src/containers/ChangeUserPassword.js b/scm-ui/src/containers/ChangeUserPassword.js index ccf0a81194..6e6f0806e0 100644 --- a/scm-ui/src/containers/ChangeUserPassword.js +++ b/scm-ui/src/containers/ChangeUserPassword.js @@ -1,6 +1,5 @@ // @flow import React from "react"; -import type { User } from "../../../scm-ui-components/packages/ui-types/src/index"; import { SubmitButton, Notification, @@ -8,11 +7,12 @@ import { InputField } from "../../../scm-ui-components/packages/ui-components/src/index"; import { translate } from "react-i18next"; -import { setPassword, updatePassword } from "../users/components/changePassword"; +import { updatePassword } from "../users/components/changePassword"; import PasswordConfirmation from "../users/components/PasswordConfirmation"; +import type { Me } from "@scm-manager/ui-types"; type Props = { - user: User, + me: Me, t: string => string }; @@ -69,11 +69,7 @@ class ChangeUserPassword extends React.Component { if (this.state.password) { const { oldPassword, password } = this.state; this.setLoadingState(); - updatePassword( - "http://localhost:8081/scm/api/v2/me/password", // TODO: Change this, as soon we have a profile component - oldPassword, - password - ) + updatePassword(this.props.me._links.password.href, oldPassword, password) .then(result => { if (result.error) { this.setErrorState(result.error); diff --git a/scm-ui/src/containers/Profile.js b/scm-ui/src/containers/Profile.js index eaa912a4f3..3a85afaeb4 100644 --- a/scm-ui/src/containers/Profile.js +++ b/scm-ui/src/containers/Profile.js @@ -60,8 +60,7 @@ class Profile extends React.Component { } /> } />
diff --git a/scm-ui/src/modules/auth.js b/scm-ui/src/modules/auth.js index 691ae2b128..e9bccb8fbc 100644 --- a/scm-ui/src/modules/auth.js +++ b/scm-ui/src/modules/auth.js @@ -136,10 +136,12 @@ const callFetchMe = (link: string): Promise => { return response.json(); }) .then(json => { + const { name, displayName, mail, _links } = json; return { - name: json.name, - displayName: json.displayName, - mail: json.mail + name, + displayName, + mail, + _links }; }); }; diff --git a/scm-ui/src/users/components/PasswordConfirmation.js b/scm-ui/src/users/components/PasswordConfirmation.js index f690eabd59..6db00b899f 100644 --- a/scm-ui/src/users/components/PasswordConfirmation.js +++ b/scm-ui/src/users/components/PasswordConfirmation.js @@ -14,7 +14,6 @@ type State = { }; type Props = { passwordChanged: string => void, - password: string, // Context props t: string => string }; diff --git a/scm-ui/src/users/components/SetUserPassword.js b/scm-ui/src/users/components/SetUserPassword.js index 66b8c9d34e..0f8e8e56da 100644 --- a/scm-ui/src/users/components/SetUserPassword.js +++ b/scm-ui/src/users/components/SetUserPassword.js @@ -79,7 +79,6 @@ class SetUserPassword extends React.Component { }; render() { - console.log("RENDER"); const { t } = this.props; const { loading, passwordChanged, error } = this.state; diff --git a/scm-ui/src/users/components/updatePassword.test.js b/scm-ui/src/users/components/changePassword.test.js similarity index 100% rename from scm-ui/src/users/components/updatePassword.test.js rename to scm-ui/src/users/components/changePassword.test.js