Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.37 KB | None | 0 0
  1. import React, { Component, PropTypes } from 'react';
  2. import { propTypes, reduxForm, Field } from 'redux-form';
  3. import { connect } from 'react-redux';
  4. import { push as pushAction } from 'react-router-redux';
  5. import compose from 'recompose/compose';
  6. import { Container, Row, Col } from 'react-grid-system';
  7.  
  8. import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
  9. import getMuiTheme from 'material-ui/styles/getMuiTheme';
  10. import { Card, CardActions } from 'material-ui/Card';
  11. import Avatar from 'material-ui/Avatar';
  12. import RaisedButton from 'material-ui/RaisedButton';
  13. import Snackbar from 'material-ui/Snackbar';
  14. import TextField from 'material-ui/TextField';
  15. import CircularProgress from 'material-ui/CircularProgress';
  16. import LockIcon from 'material-ui/svg-icons/action/lock-outline';
  17. import RegisterIcon from 'material-ui/svg-icons/social/people';
  18.  
  19. import { cyan500, pinkA200 } from 'material-ui/styles/colors';
  20.  
  21. import defaultTheme from 'admin-on-rest/lib/mui/defaultTheme';
  22. import { AUTH_LOGIN } from 'admin-on-rest/lib/auth';
  23.  
  24. const styles = {
  25. main: {
  26. display: 'flex',
  27. flexDirection: 'column',
  28. minHeight: '100vh',
  29. alignItems: 'center',
  30. justifyContent: 'center',
  31.  
  32. },
  33. card: {
  34. minWidth: 300,
  35. width: '300px',
  36. padding: '10px'
  37. },
  38. avatar: {
  39. margin: '1em',
  40. textAlign: 'center ',
  41. },
  42. form: {
  43. padding: '0 1em 1em 1em',
  44. },
  45. input: {
  46. display: 'flex',
  47. },
  48. };
  49.  
  50. function getColorsFromTheme(theme) {
  51. if (!theme) return { primary1Color: cyan500, accent1Color: pinkA200 };
  52. const {
  53. palette: {
  54. primary1Color,
  55. accent1Color,
  56. },
  57. } = theme;
  58. return { primary1Color, accent1Color };
  59. }
  60.  
  61. const renderInput = ({ meta: { touched, error } = {}, input: { ...inputProps }, ...props }) =>
  62. <TextField
  63. errorText={touched && error}
  64. {...inputProps}
  65. {...props}
  66. fullWidth
  67. />;
  68.  
  69. var translate = function( key ) {
  70. return key;
  71. }
  72.  
  73. class CustomLoginPage extends Component {
  74. constructor(props) {
  75. super(props);
  76. this.state = { signInError: false };
  77. }
  78.  
  79. login = ({ username, password }) => {
  80. const { authClient, push, location } = this.props;
  81. if (!authClient) return;
  82. return authClient(AUTH_LOGIN, { username, password })
  83. .then(() => push(location.state ? location.state.nextPathname : '/'))
  84. .catch(e => this.setState({ signInError: e }));
  85.  
  86.  
  87. console.log(username + " " + password);
  88. return false;
  89. }
  90.  
  91. handleRegister( data ) {
  92. console.log(data);
  93. }
  94.  
  95. render() {
  96. const { handleSubmit, submitting, theme } = this.props;
  97. const muiTheme = getMuiTheme(theme);
  98. const { primary1Color, accent1Color } = getColorsFromTheme(muiTheme);
  99. const { signInError } = this.state;
  100.  
  101. return (
  102. <MuiThemeProvider muiTheme={muiTheme}>
  103. <div style={{ ...styles.main, backgroundColor: primary1Color }}>
  104.  
  105.  
  106. <Row>
  107.  
  108. <Col xs={4} md={4}>
  109.  
  110. <Card style={styles.card}>
  111. <div style={styles.avatar}>
  112. <Avatar backgroundColor={accent1Color} icon={<LockIcon />} size={60} />
  113. <br />
  114. <strong>You can login here.</strong>
  115. </div>
  116. {signInError && <Snackbar open autoHideDuration={4000} message={signInError.message || signInError || translate('aor.auth.sign_in_error')} />}
  117.  
  118. <form onSubmit={handleSubmit(this.login)}>
  119. <div>
  120. <div>
  121. <Field
  122. name="username"
  123. component={renderInput}
  124. floatingLabelText={"YOUR USERNAME"}
  125. disabled={submitting}
  126. />
  127. </div>
  128. <div>
  129. <Field
  130. name="password"
  131. component={renderInput}
  132. floatingLabelText={"PASSWORD"}
  133. type="password"
  134. disabled={submitting}
  135. />
  136. </div>
  137. </div>
  138. <CardActions>
  139. <RaisedButton
  140. type="submit"
  141. primary
  142. disabled={submitting}
  143. icon={submitting && <CircularProgress size={25} thickness={2} />}
  144. label={"GİRİŞ YAP"}
  145. fullWidth
  146. />
  147. </CardActions>
  148. </form>
  149. </Card>
  150.  
  151. </Col>
  152. <Col xs={4} md={4}></Col>
  153.  
  154. <Col xs={4} md={4}>
  155.  
  156. <Card style={styles.card}>
  157. <div style={styles.avatar}>
  158. <Avatar backgroundColor={accent1Color} icon={<RegisterIcon />} size={60} />
  159. <br />
  160. <strong>Create account from here</strong>
  161. </div>
  162. {signInError && <Snackbar open autoHideDuration={4000} message={signInError.message || signInError || translate('aor.auth.sign_in_error')} />}
  163.  
  164. <form onSubmit={this.handleRegister(this.login)}>
  165. <div>
  166. <div>
  167. <Row>
  168. <Col xs={6} md={6}>
  169. <Field
  170. name="firstname"
  171. component={renderInput}
  172. floatingLabelText={"First name"}
  173. disabled={submitting}
  174. />
  175.  
  176. </Col>
  177. <Col xs={6} md={6}>
  178.  
  179. <Field
  180. name="lastname"
  181. component={renderInput}
  182. floatingLabelText={"Last name"}
  183. disabled={submitting}
  184. />
  185. </Col>
  186. </Row>
  187. </div>
  188. <div>
  189. <Field
  190. name="registerUsername"
  191. component={renderInput}
  192. floatingLabelText={"Cellphone"}
  193. disabled={submitting}
  194. />
  195. </div>
  196. <div>
  197. <Field
  198. name="registerPassword"
  199. component={renderInput}
  200. floatingLabelText={"Password"}
  201. type="password"
  202. disabled={submitting}
  203. />
  204. </div>
  205. <div>
  206. <Field
  207. name="registerPassword2"
  208. component={renderInput}
  209. floatingLabelText={"Password (again)"}
  210. type="password"
  211. disabled={submitting}
  212. />
  213. </div>
  214. </div>
  215. <CardActions>
  216. <RaisedButton
  217. type="submit"
  218. primary
  219. disabled={submitting}
  220. icon={submitting && <CircularProgress size={25} thickness={2} />}
  221. label={"REGISTER"}
  222. fullWidth
  223. />
  224. </CardActions>
  225. </form>
  226. </Card>
  227. </Col>
  228.  
  229. </Row>
  230.  
  231.  
  232.  
  233. </div>
  234. </MuiThemeProvider>
  235. );
  236. }
  237. }
  238.  
  239. CustomLoginPage.defaultProps = {
  240. theme: defaultTheme,
  241. };
  242.  
  243. const enhance = compose(
  244. translate,
  245. reduxForm({
  246. form: 'signIn',
  247. validate: (values, props) => {
  248. const errors = {};
  249.  
  250. if (!values.username) errors.username = "Please enter username.";
  251. if (!values.password) errors.password = "Please enter password.";
  252.  
  253. return errors;
  254. },
  255. }),
  256. connect(null, { push: pushAction }),
  257. );
  258.  
  259. export default enhance(CustomLoginPage);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement