Use HATEOAS link to change password

This commit is contained in:
Philipp Czora
2018-11-07 17:05:46 +01:00
parent e5dcae6874
commit 2ebd960154
7 changed files with 14 additions and 16 deletions

View File

@@ -1,7 +1,10 @@
// @flow
import type { Links } from "./hal";
export type Me = {
name: string,
displayName: string,
mail: string
mail: string,
_links: Links
};

View File

@@ -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<Props, State> {
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);

View File

@@ -60,8 +60,7 @@ class Profile extends React.Component<Props, State> {
<Route path={url} exact render={() => <ProfileInfo me={me} />} />
<Route
path={`${url}/password`}
exact
component={ChangeUserPassword}
render={() => <ChangeUserPassword me={me} />}
/>
</div>
<div className="column">

View File

@@ -136,10 +136,12 @@ const callFetchMe = (link: string): Promise<Me> => {
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
};
});
};

View File

@@ -14,7 +14,6 @@ type State = {
};
type Props = {
passwordChanged: string => void,
password: string,
// Context props
t: string => string
};

View File

@@ -79,7 +79,6 @@ class SetUserPassword extends React.Component<Props, State> {
};
render() {
console.log("RENDER");
const { t } = this.props;
const { loading, passwordChanged, error } = this.state;