use login link of index resource

This commit is contained in:
Maren Süwer
2018-10-11 08:30:37 +02:00
parent 6562071bfe
commit 79c62c55cb
3 changed files with 28 additions and 18 deletions

View File

@@ -18,7 +18,7 @@ import {
Image Image
} from "@scm-manager/ui-components"; } from "@scm-manager/ui-components";
import classNames from "classnames"; import classNames from "classnames";
import { fetchIndexResources } from "../modules/indexResource"; import { fetchIndexResources, getLoginLink } from "../modules/indexResource";
const styles = { const styles = {
avatar: { avatar: {
@@ -42,9 +42,10 @@ type Props = {
authenticated: boolean, authenticated: boolean,
loading: boolean, loading: boolean,
error: Error, error: Error,
loginLink: string,
// dispatcher props // dispatcher props
login: (username: string, password: string) => void, login: (link: string, username: string, password: string) => void,
fetchIndexResources: () => void, fetchIndexResources: () => void,
// context props // context props
@@ -76,7 +77,11 @@ class Login extends React.Component<Props, State> {
handleSubmit = (event: Event) => { handleSubmit = (event: Event) => {
event.preventDefault(); event.preventDefault();
if (this.isValid()) { if (this.isValid()) {
this.props.login(this.state.username, this.state.password); this.props.login(
this.props.loginLink,
this.state.username,
this.state.password
);
} }
}; };
@@ -148,17 +153,19 @@ const mapStateToProps = state => {
const authenticated = isAuthenticated(state); const authenticated = isAuthenticated(state);
const loading = isLoginPending(state); const loading = isLoginPending(state);
const error = getLoginFailure(state); const error = getLoginFailure(state);
const loginLink = getLoginLink(state);
return { return {
authenticated, authenticated,
loading, loading,
error error,
loginLink
}; };
}; };
const mapDispatchToProps = dispatch => { const mapDispatchToProps = dispatch => {
return { return {
login: (username: string, password: string) => login: (link: string, username: string, password: string) =>
dispatch(login(username, password)), dispatch(login(link, username, password)),
fetchIndexResources: () => dispatch(fetchIndexResources()) fetchIndexResources: () => dispatch(fetchIndexResources())
}; };
}; };

View File

@@ -125,7 +125,6 @@ export const fetchMeFailure = (error: Error) => {
// urls // urls
const ME_URL = "/me"; const ME_URL = "/me";
const LOGIN_URL = "/auth/access_token";
// side effects // side effects
@@ -140,7 +139,7 @@ const callFetchMe = (): Promise<Me> => {
}); });
}; };
export const login = (username: string, password: string) => { export const login = (link: string, username: string, password: string) => {
const login_data = { const login_data = {
cookie: true, cookie: true,
grant_type: "password", grant_type: "password",
@@ -150,7 +149,7 @@ export const login = (username: string, password: string) => {
return function(dispatch: any) { return function(dispatch: any) {
dispatch(loginPending()); dispatch(loginPending());
return apiClient return apiClient
.post(LOGIN_URL, login_data) .post(link, login_data)
.then(response => { .then(response => {
return callFetchMe(); return callFetchMe();
}) })

View File

@@ -100,9 +100,11 @@ describe("auth actions", () => {
const store = mockStore({}); const store = mockStore({});
return store.dispatch(login("tricia", "secret123")).then(() => { return store
expect(store.getActions()).toEqual(expectedActions); .dispatch(login("/auth/access_token", "tricia", "secret123"))
}); .then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
}); });
it("should dispatch login failure", () => { it("should dispatch login failure", () => {
@@ -111,12 +113,14 @@ describe("auth actions", () => {
}); });
const store = mockStore({}); const store = mockStore({});
return store.dispatch(login("tricia", "secret123")).then(() => { return store
const actions = store.getActions(); .dispatch(login("/auth/access_token", "tricia", "secret123"))
expect(actions[0].type).toEqual(LOGIN_PENDING); .then(() => {
expect(actions[1].type).toEqual(LOGIN_FAILURE); const actions = store.getActions();
expect(actions[1].payload).toBeDefined(); expect(actions[0].type).toEqual(LOGIN_PENDING);
}); expect(actions[1].type).toEqual(LOGIN_FAILURE);
expect(actions[1].payload).toBeDefined();
});
}); });
it("should dispatch fetch me success", () => { it("should dispatch fetch me success", () => {