mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 23:45:44 +01:00
use login link of index resource
This commit is contained in:
@@ -26,6 +26,7 @@ import {
|
|||||||
getFetchIndexResourcesFailure,
|
getFetchIndexResourcesFailure,
|
||||||
getGroupsLink,
|
getGroupsLink,
|
||||||
getLogoutLink,
|
getLogoutLink,
|
||||||
|
getMeLink,
|
||||||
getRepositoriesLink,
|
getRepositoriesLink,
|
||||||
getUsersLink,
|
getUsersLink,
|
||||||
isFetchIndexResourcesPending
|
isFetchIndexResourcesPending
|
||||||
@@ -36,14 +37,15 @@ type Props = {
|
|||||||
authenticated: boolean,
|
authenticated: boolean,
|
||||||
error: Error,
|
error: Error,
|
||||||
loading: boolean,
|
loading: boolean,
|
||||||
repositoriesLink: String,
|
repositoriesLink: string,
|
||||||
usersLink: String,
|
usersLink: string,
|
||||||
groupsLink: String,
|
groupsLink: string,
|
||||||
configLink: String,
|
configLink: string,
|
||||||
logoutLink: String,
|
logoutLink: string,
|
||||||
|
meLink: string,
|
||||||
|
|
||||||
// dispatcher functions
|
// dispatcher functions
|
||||||
fetchMe: () => void,
|
fetchMe: (link: string) => void,
|
||||||
fetchIndexResources: () => void,
|
fetchIndexResources: () => void,
|
||||||
|
|
||||||
// context props
|
// context props
|
||||||
@@ -52,8 +54,8 @@ type Props = {
|
|||||||
|
|
||||||
class App extends Component<Props> {
|
class App extends Component<Props> {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.fetchIndexResources();
|
//this.props.fetchIndexResources();
|
||||||
this.props.fetchMe();
|
if (this.props.meLink) this.props.fetchMe(this.props.meLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -108,7 +110,7 @@ class App extends Component<Props> {
|
|||||||
|
|
||||||
const mapDispatchToProps = (dispatch: any) => {
|
const mapDispatchToProps = (dispatch: any) => {
|
||||||
return {
|
return {
|
||||||
fetchMe: () => dispatch(fetchMe()),
|
fetchMe: (link: string) => dispatch(fetchMe(link)),
|
||||||
fetchIndexResources: () => dispatch(fetchIndexResources())
|
fetchIndexResources: () => dispatch(fetchIndexResources())
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -125,6 +127,7 @@ const mapStateToProps = state => {
|
|||||||
const groupsLink = getGroupsLink(state);
|
const groupsLink = getGroupsLink(state);
|
||||||
const configLink = getConfigLink(state);
|
const configLink = getConfigLink(state);
|
||||||
const logoutLink = getLogoutLink(state);
|
const logoutLink = getLogoutLink(state);
|
||||||
|
const meLink = getMeLink(state);
|
||||||
return {
|
return {
|
||||||
authenticated,
|
authenticated,
|
||||||
me,
|
me,
|
||||||
@@ -134,7 +137,8 @@ const mapStateToProps = state => {
|
|||||||
usersLink,
|
usersLink,
|
||||||
groupsLink,
|
groupsLink,
|
||||||
configLink,
|
configLink,
|
||||||
logoutLink
|
logoutLink,
|
||||||
|
meLink
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,11 @@ import {
|
|||||||
Image
|
Image
|
||||||
} from "@scm-manager/ui-components";
|
} from "@scm-manager/ui-components";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { fetchIndexResources, getLoginLink } from "../modules/indexResource";
|
import {
|
||||||
|
fetchIndexResources,
|
||||||
|
getLoginLink,
|
||||||
|
getMeLink
|
||||||
|
} from "../modules/indexResource";
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
avatar: {
|
avatar: {
|
||||||
@@ -42,7 +46,7 @@ type Props = {
|
|||||||
authenticated: boolean,
|
authenticated: boolean,
|
||||||
loading: boolean,
|
loading: boolean,
|
||||||
error: Error,
|
error: Error,
|
||||||
loginLink: string,
|
link: string,
|
||||||
|
|
||||||
// dispatcher props
|
// dispatcher props
|
||||||
login: (link: string, username: string, password: string) => void,
|
login: (link: string, username: string, password: string) => void,
|
||||||
@@ -78,7 +82,7 @@ class Login extends React.Component<Props, State> {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (this.isValid()) {
|
if (this.isValid()) {
|
||||||
this.props.login(
|
this.props.login(
|
||||||
this.props.loginLink,
|
this.props.link,
|
||||||
this.state.username,
|
this.state.username,
|
||||||
this.state.password
|
this.state.password
|
||||||
);
|
);
|
||||||
@@ -94,7 +98,6 @@ class Login extends React.Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderRedirect = () => {
|
renderRedirect = () => {
|
||||||
this.props.fetchIndexResources();
|
|
||||||
const { from } = this.props.location.state || { from: { pathname: "/" } };
|
const { from } = this.props.location.state || { from: { pathname: "/" } };
|
||||||
return <Redirect to={from} />;
|
return <Redirect to={from} />;
|
||||||
};
|
};
|
||||||
@@ -153,20 +156,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);
|
const link = getLoginLink(state);
|
||||||
return {
|
return {
|
||||||
authenticated,
|
authenticated,
|
||||||
loading,
|
loading,
|
||||||
error,
|
error,
|
||||||
loginLink
|
link
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => {
|
const mapDispatchToProps = dispatch => {
|
||||||
return {
|
return {
|
||||||
login: (link: string, username: string, password: string) =>
|
login: (link: string, username: string, password: string) =>
|
||||||
dispatch(login(link, username, password)),
|
dispatch(login(link, username, password))
|
||||||
fetchIndexResources: () => dispatch(fetchIndexResources())
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import ReactDOM from "react-dom";
|
import ReactDOM from "react-dom";
|
||||||
import App from "./containers/App";
|
import Index from "./containers/Index";
|
||||||
import registerServiceWorker from "./registerServiceWorker";
|
import registerServiceWorker from "./registerServiceWorker";
|
||||||
|
|
||||||
import { I18nextProvider } from "react-i18next";
|
import { I18nextProvider } from "react-i18next";
|
||||||
@@ -38,7 +38,7 @@ ReactDOM.render(
|
|||||||
{/* ConnectedRouter will use the store from Provider automatically */}
|
{/* ConnectedRouter will use the store from Provider automatically */}
|
||||||
<ConnectedRouter history={history}>
|
<ConnectedRouter history={history}>
|
||||||
<PluginLoader>
|
<PluginLoader>
|
||||||
<App />
|
<Index />
|
||||||
</PluginLoader>
|
</PluginLoader>
|
||||||
</ConnectedRouter>
|
</ConnectedRouter>
|
||||||
</I18nextProvider>
|
</I18nextProvider>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import * as types from "./types";
|
|||||||
import { apiClient, UNAUTHORIZED_ERROR } from "@scm-manager/ui-components";
|
import { apiClient, UNAUTHORIZED_ERROR } from "@scm-manager/ui-components";
|
||||||
import { isPending } from "./pending";
|
import { isPending } from "./pending";
|
||||||
import { getFailure } from "./failure";
|
import { getFailure } from "./failure";
|
||||||
import { getMeLink } from "./indexResource";
|
import { fetchIndexResources, getMeLink } from "./indexResource";
|
||||||
|
|
||||||
// Action
|
// Action
|
||||||
|
|
||||||
@@ -128,9 +128,10 @@ const ME_URL = "/me";
|
|||||||
|
|
||||||
// side effects
|
// side effects
|
||||||
|
|
||||||
const callFetchMe = (): Promise<Me> => {
|
const callFetchMe = (link: string): Promise<Me> => {
|
||||||
|
console.log(link);
|
||||||
return apiClient
|
return apiClient
|
||||||
.get(ME_URL)
|
.get(link)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
@@ -139,7 +140,11 @@ const callFetchMe = (): Promise<Me> => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const login = (link: string, username: string, password: string) => {
|
export const login = (
|
||||||
|
loginLink: string,
|
||||||
|
username: string,
|
||||||
|
password: string
|
||||||
|
) => {
|
||||||
const login_data = {
|
const login_data = {
|
||||||
cookie: true,
|
cookie: true,
|
||||||
grant_type: "password",
|
grant_type: "password",
|
||||||
@@ -149,9 +154,13 @@ export const login = (link: string, username: string, password: string) => {
|
|||||||
return function(dispatch: any) {
|
return function(dispatch: any) {
|
||||||
dispatch(loginPending());
|
dispatch(loginPending());
|
||||||
return apiClient
|
return apiClient
|
||||||
.post(link, login_data)
|
.post(loginLink, login_data)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
return callFetchMe();
|
return dispatch(fetchIndexResources());
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
const meLink = response._links.me.href;
|
||||||
|
return dispatch(callFetchMe(meLink));
|
||||||
})
|
})
|
||||||
.then(me => {
|
.then(me => {
|
||||||
dispatch(loginSuccess(me));
|
dispatch(loginSuccess(me));
|
||||||
@@ -162,10 +171,10 @@ export const login = (link: string, username: string, password: string) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const fetchMe = () => {
|
export const fetchMe = (link: string) => {
|
||||||
return function(dispatch: any) {
|
return function(dispatch: any) {
|
||||||
dispatch(fetchMePending());
|
dispatch(fetchMePending());
|
||||||
return callFetchMe()
|
return callFetchMe(link)
|
||||||
.then(me => {
|
.then(me => {
|
||||||
dispatch(fetchMeSuccess(me));
|
dispatch(fetchMeSuccess(me));
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ describe("auth actions", () => {
|
|||||||
|
|
||||||
const store = mockStore({});
|
const store = mockStore({});
|
||||||
|
|
||||||
return store.dispatch(fetchMe()).then(() => {
|
return store.dispatch(fetchMe("me")).then(() => {
|
||||||
expect(store.getActions()).toEqual(expectedActions);
|
expect(store.getActions()).toEqual(expectedActions);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -150,7 +150,7 @@ describe("auth actions", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const store = mockStore({});
|
const store = mockStore({});
|
||||||
return store.dispatch(fetchMe()).then(() => {
|
return store.dispatch(fetchMe("me")).then(() => {
|
||||||
const actions = store.getActions();
|
const actions = store.getActions();
|
||||||
expect(actions[0].type).toEqual(FETCH_ME_PENDING);
|
expect(actions[0].type).toEqual(FETCH_ME_PENDING);
|
||||||
expect(actions[1].type).toEqual(FETCH_ME_FAILURE);
|
expect(actions[1].type).toEqual(FETCH_ME_FAILURE);
|
||||||
@@ -170,7 +170,7 @@ describe("auth actions", () => {
|
|||||||
|
|
||||||
const store = mockStore({});
|
const store = mockStore({});
|
||||||
|
|
||||||
return store.dispatch(fetchMe()).then(() => {
|
return store.dispatch(fetchMe("me")).then(() => {
|
||||||
// return of async actions
|
// return of async actions
|
||||||
expect(store.getActions()).toEqual(expectedActions);
|
expect(store.getActions()).toEqual(expectedActions);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user