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