Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from 'react';
- import { login } from '../../util/APIUtils';
- import './Login.css';
- import { Link } from 'react-router-dom';
- import { ACCESS_TOKEN } from '../../constants';
- import { Form, Input, Button, Icon, notification } from 'antd';
- const FormItem = Form.Item;
- class Login extends Component {
- render() {
- const AntWrappedLoginForm = Form.create()(LoginForm)
- return (
- <div className="login-container">
- <h1 className="page-title">Login</h1>
- <div className="login-content">
- <AntWrappedLoginForm onLogin={this.props.onLogin} />
- </div>
- </div>
- );
- }
- }
- class LoginForm extends Component {
- constructor(props) {
- super(props);
- this.handleSubmit = this.handleSubmit.bind(this);
- }
- handleSubmit(event) {
- event.preventDefault();
- this.props.form.validateFields((err, values) => {
- if (!err) {
- const loginRequest = Object.assign({}, values);
- login(loginRequest)
- .then(response => {
- localStorage.setItem(ACCESS_TOKEN, response.accessToken);
- this.props.onLogin();
- }).catch(error => {
- if(error.status === 401) {
- notification.error({
- message: 'Demo Drop',
- description: 'Uw e-mailadres of wachtwoord is onjuist. Probeer het opnieuw!'
- });
- } else {
- notification.error({
- message: 'Demo Drop',
- description: error.message || 'Sorry! Er is iets misgegaan. Probeer het opnieuw!'
- });
- }
- });
- }
- });
- }
- render() {
- const { getFieldDecorator } = this.props.form;
- return (
- <Form onSubmit={this.handleSubmit} className="login-form">
- <FormItem>
- {getFieldDecorator('usernameOrEmail', {
- rules: [{ required: true, message: 'Voer je email adres in!' }],
- })(
- <Input
- prefix={<Icon type="user" />}
- size="large"
- name="usernameOrEmail"
- placeholder="Gebruikersnaam of Email" />
- )}
- </FormItem>
- <FormItem>
- {getFieldDecorator('password', {
- rules: [{ required: true, message: 'Voer je wachtwoord in.' }],
- })(
- <Input
- prefix={<Icon type="lock" />}
- size="large"
- name="password"
- type="password"
- placeholder="Wachtwoord" />
- )}
- </FormItem>
- <FormItem>
- <Button type="primary" htmlType="submit" size="large" className="login-form-button">Login</Button>
- Of <Link to="/signup">registreer nu!</Link>
- </FormItem>
- </Form>
- );
- }
- }
- export default Login;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement