mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 00:15:44 +01:00
Added method to change password as a user
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
|||||||
} from "@scm-manager/ui-components";
|
} from "@scm-manager/ui-components";
|
||||||
import * as userValidator from "./userValidation";
|
import * as userValidator from "./userValidation";
|
||||||
import { translate } from "react-i18next";
|
import { translate } from "react-i18next";
|
||||||
import { updatePassword } from "./updatePassword";
|
import { setPassword } from "./changePassword";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
user: User,
|
user: User,
|
||||||
@@ -79,7 +79,7 @@ class SetUserPassword extends React.Component<Props, State> {
|
|||||||
const { user } = this.props;
|
const { user } = this.props;
|
||||||
const { password } = this.state;
|
const { password } = this.state;
|
||||||
this.setLoadingState();
|
this.setLoadingState();
|
||||||
updatePassword(user._links.password.href, password)
|
setPassword(user._links.password.href, password)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
this.setErrorState(result.error);
|
this.setErrorState(result.error);
|
||||||
|
|||||||
32
scm-ui/src/users/components/changePassword.js
Normal file
32
scm-ui/src/users/components/changePassword.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
//@flow
|
||||||
|
import { apiClient } from "@scm-manager/ui-components";
|
||||||
|
const CONTENT_TYPE_PASSWORD_OVERWRITE =
|
||||||
|
"application/vnd.scmm-passwordOverwrite+json;v=2";
|
||||||
|
const CONTENT_TYPE_PASSWORD_CHANGE =
|
||||||
|
"application/vnd.scmm-passwordChange+json;v=2";
|
||||||
|
|
||||||
|
export function setPassword(url: string, password: string) {
|
||||||
|
return apiClient
|
||||||
|
.put(url, { newPassword: password }, CONTENT_TYPE_PASSWORD_OVERWRITE)
|
||||||
|
.then(response => {
|
||||||
|
return response;
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
return { error: err };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updatePassword(
|
||||||
|
url: string,
|
||||||
|
oldPassword: string,
|
||||||
|
newPassword: string
|
||||||
|
) {
|
||||||
|
return apiClient
|
||||||
|
.put(url, { oldPassword, newPassword }, CONTENT_TYPE_PASSWORD_CHANGE)
|
||||||
|
.then(response => {
|
||||||
|
return response;
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
return { error: err };
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
//@flow
|
|
||||||
import { apiClient } from "@scm-manager/ui-components";
|
|
||||||
const CONTENT_TYPE_PASSWORD_OVERWRITE =
|
|
||||||
"application/vnd.scmm-passwordOverwrite+json;v=2";
|
|
||||||
|
|
||||||
export function updatePassword(url: string, password: string) {
|
|
||||||
return apiClient
|
|
||||||
.put(url, { newPassword: password }, CONTENT_TYPE_PASSWORD_OVERWRITE)
|
|
||||||
.then(response => {
|
|
||||||
return response;
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
return { error: err };
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,23 +1,35 @@
|
|||||||
//@flow
|
//@flow
|
||||||
import fetchMock from "fetch-mock";
|
import fetchMock from "fetch-mock";
|
||||||
import { updatePassword } from "./updatePassword";
|
import { setPassword, updatePassword } from "./changePassword";
|
||||||
|
|
||||||
describe("get content type", () => {
|
describe("password change", () => {
|
||||||
const PASSWORD_URL = "/users/testuser/password";
|
const SET_PASSWORD_URL = "/users/testuser/password";
|
||||||
const password = "testpw123";
|
const CHANGE_PASSWORD_URL = "/me/password";
|
||||||
|
const oldPassword = "old";
|
||||||
|
const newPassword = "testpw123";
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
fetchMock.reset();
|
fetchMock.reset();
|
||||||
fetchMock.restore();
|
fetchMock.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should update password", done => {
|
// TODO: Verify content type
|
||||||
|
it("should set password", done => {
|
||||||
fetchMock.put("/api/v2" + PASSWORD_URL, 204);
|
fetchMock.put("/api/v2" + SET_PASSWORD_URL, 204);
|
||||||
|
|
||||||
updatePassword(PASSWORD_URL, password).then(content => {
|
|
||||||
|
|
||||||
|
setPassword(SET_PASSWORD_URL, newPassword).then(content => {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO: Verify content type
|
||||||
|
it("should update password", done => {
|
||||||
|
fetchMock.put("/api/v2" + CHANGE_PASSWORD_URL, 204);
|
||||||
|
|
||||||
|
updatePassword(CHANGE_PASSWORD_URL, oldPassword, newPassword).then(
|
||||||
|
content => {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user