无法使用 Admin-On-Rest 创建自定义登录页面

Cannot create a custom login page with Admin-On-Rest

已经尝试了一段时间以了解如何在 admin-on-rest v-1.0.0 中设置自定义登录页面

需要启用基于电子邮件的登录。为此,我稍微更改了默认的 admin-on-rest 登录页面代码(如下)

用电子邮件替换用户名并将 authClient 更改为 loopbackRestClient

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { propTypes, reduxForm, Field } from 'redux-form';
import { connect } from 'react-redux';
import compose from 'recompose/compose';

import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import getMuiTheme from 'material-ui/styles/getMuiTheme';
import { Card, CardActions } from 'material-ui/Card';
import Avatar from 'material-ui/Avatar';
import RaisedButton from 'material-ui/RaisedButton';
import TextField from 'material-ui/TextField';
import CircularProgress from 'material-ui/CircularProgress';
import LockIcon from 'material-ui/svg-icons/action/lock-outline';
import { cyan500, pinkA200 } from 'material-ui/styles/colors';

import defaultTheme from 'admin-on-rest';
import { userLogin as userLoginAction } from 'admin-on-rest';

import Notification from 'admin-on-rest';

const styles = {
    main: {
        display: 'flex',
        flexDirection: 'column',
        minHeight: '100vh',
        alignItems: 'center',
        justifyContent: 'center',
    },
    card: {
        minWidth: 300,
    },
    avatar: {
        margin: '1em',
        textAlign: 'center ',
    },
    form: {
        padding: '0 1em 1em 1em',
    },
    input: {
        display: 'flex',
    },
};

function getColorsFromTheme(theme) {
    if (!theme) return { primary1Color: cyan500, accent1Color: pinkA200 };
    const {
        palette: {
            primary1Color,
            accent1Color,
        },
      } = theme;
    return { primary1Color, accent1Color };
}

// see http://redux-form.com/6.4.3/examples/material-ui/
const renderInput = ({ meta: { touched, error } = {}, input: { ...inputProps }, ...props }) =>
    <TextField
        errorText={touched && error}
        {...inputProps}
        {...props}
        fullWidth
    />;


class EmailLogin extends Component {

    login = (auth) => this.props.userLogin(auth, this.props.location.state ? this.props.location.state.nextPathname : '/');

    render() {
        const { handleSubmit, submitting, theme } = this.props;
        const muiTheme = getMuiTheme(theme);
        const { primary1Color, accent1Color } = getColorsFromTheme(muiTheme);
        console.log(styles.form)
        return (
            <MuiThemeProvider muiTheme={muiTheme}>
                <div style={{ ...styles.main, backgroundColor: primary1Color }}>
                    <Card style={styles.card}>
                        <div style={styles.avatar}>
                            <Avatar backgroundColor={accent1Color} icon={<LockIcon />} size={60} />
                        </div>
                        <form onSubmit={handleSubmit(this.login)}>
                            <div style={styles.form}>
                                <div style={styles.input} >
                                    <Field
                                        name="email"
                                        floatingLabelText={"email"}
                                        component={renderInput}
                                        disabled={submitting}
                                        placeholder={"email"}
                                    />
                                </div>
                                <div style={styles.input}>
                                    <Field
                                        name="password"
                                        component={renderInput}
                                        type="password"
                                        disabled={submitting}
                                    />
                                </div>
                            </div>
                            <CardActions>
                                <RaisedButton
                                    type="submit"
                                    primary
                                    disabled={submitting}
                                    icon={submitting && <CircularProgress size={25} thickness={2} />}
                                    fullWidth
                                />
                            </CardActions>
                        </form>
                    </Card>
                    <Notification />
                </div>
            </MuiThemeProvider>
        );
    }
}


EmailLogin.propTypes = {
    ...propTypes,
    authClient: PropTypes.func,
    previousRoute: PropTypes.string,
    theme: PropTypes.object,
    userLogin: PropTypes.func.isRequired,
};

EmailLogin.defaultProps = {
    theme: defaultTheme,
};

const enhance = compose(
    reduxForm({
        form: 'signIn',
        validate: (values, props) => {
            const errors = {};
            return errors;
        },
    }),
    connect(null, { userLogin: userLoginAction }),
);

export default enhance( EmailLogin );

我已将以上内容添加到我的 app.js

中 Admin 的 loginPage 属性中

但是 admin-on-rest 似乎显示的是默认页面。

我从这个问题中复制了 BtcLoginPage

Is there any examples of how to create a custom login page?

但管理员仍然只显示默认页面(带有用户名的页面)。

请指教。如何使用 Admin-On-Rest 创建自定义页面。

谢谢

admin-on-rest-demo 存储库中有一个工作示例:

自定义登录组件:

https://github.com/marmelab/admin-on-rest-demo/blob/master/src/Login.js

已集成到管理中:

https://github.com/marmelab/admin-on-rest-demo/blob/master/src/App.js#L45

您使用的是哪个版本的 aor?

看来我做错了什么。

我的自定义 loginPage(上图)出现静默错误。该行

import Notification from 'admin-on-rest';

失败需要

import { Notification } from 'admin-on-rest';

不过。

Admin-on-rest 隐式地​​将默认管理页面替换为我的自定义页面。我将错误归咎于我对 Redux 和 React-Redux 的了解有限。但解决方案更简单。