diff --git a/assets/js/components/RegisterModal.jsx b/assets/js/components/RegisterModal.jsx index 225c31818db34c37ff2bbdc2d36da51a86b5d12f..06d91044d9ff78a2147da4cb4b356341fa84e6cf 100644 --- a/assets/js/components/RegisterModal.jsx +++ b/assets/js/components/RegisterModal.jsx @@ -1,6 +1,8 @@ import React from 'react'; +import { browserHistory } from 'react-router'; import { Modal, Button, Form, Input, TextArea, Header, Icon } from 'semantic-ui-react'; import Server from './../lib/Server'; +import Storage from './../lib/Storage'; export default class RegisterModal extends React.Component { @@ -15,6 +17,19 @@ export default class RegisterModal extends React.Component { this.setState({ [e.target.name]: e.target.value }); }; + handlePassword = (e) => { + if (e.target.name === 'password') this.passwordField = e.target; else + if (e.target.name === 'password-confirm') this.passwordConfirmField = e.target; + const isExist = this.passwordField && this.passwordConfirmField; + if (isExist) { + if (this.passwordField.value !== this.passwordConfirmField.value) { + this.passwordConfirmField.setCustomValidity("Passwords Don't Match"); + } else { + this.passwordConfirmField.setCustomValidity(''); + } + } + }; + handleSubmit = (e) => { e.preventDefault(); const form = new FormData(); @@ -29,10 +44,15 @@ export default class RegisterModal extends React.Component { }; fetch('/api/register/', data) - .then(r => r.json()) - .then((res) => { - alert(res); - }); + .then((response) => { + if (response.status < 200 || response.status > 399) throw response.json(); + else return response.json(); + }) + .then((response) => { + alert('Akun berhasil dibuat :)'); + Storage.set('user-data', response); + browserHistory.push('/home'); + }, error => error.then(r => alert(JSON.stringify(r)))); }; render = () => ( @@ -49,22 +69,28 @@ export default class RegisterModal extends React.Component { </Header> <Form.Field required> <label htmlFor="email">Email</label> - <Input onChange={this.handleChange} type="text" name="email" icon="user" iconPosition="left" placeholder="email" required /> + <Input onChange={this.handleChange} type="email" name="email" icon="user" iconPosition="left" placeholder="email" required /> </Form.Field> <Form.Field required> <label htmlFor="password">Password</label> - <Input onChange={this.handleChange} type="password" name="password" icon="key" iconPosition="left" placeholder="password" required /> + <Input + onChange={(e) => { this.handleChange(e); this.handlePassword(e); }} + type="password" id="password" name="password" icon="key" iconPosition="left" placeholder="password" required + /> </Form.Field> <Form.Field required> <label htmlFor="password-confirm">Konfirmasi Password</label> - <Input onChange={this.handleChange} type="password" name="password-confirm" icon="key" iconPosition="left" placeholder="password" required /> + <Input + onChange={(e) => { this.handleChange(e); this.handlePassword(e); }} + type="password" id="password-confirm" name="password-confirm" icon="key" iconPosition="left" placeholder="password" required + /> </Form.Field> <Form.Field required> <label htmlFor="name">Nama Perusahaan</label> <Input onChange={this.handleChange} placeholder="Nama Perusahaan" name="name" required /> </Form.Field> - <Form.Field required> + <Form.Field> <label htmlFor="logo">Logo</label> <Input onChange={this.handleChange} @@ -72,7 +98,6 @@ export default class RegisterModal extends React.Component { icon={{ name: 'attach', circular: true, link: true }} placeholder="attach logo" type="File" - required /> </Form.Field> <Form.Field required> diff --git a/assets/js/components/TopMenu.jsx b/assets/js/components/TopMenu.jsx index 6e180677916a9215a0a5ea4614c47dad64252d2a..ad5b6bed5151a807eaffa37acabe83e5511864c4 100644 --- a/assets/js/components/TopMenu.jsx +++ b/assets/js/components/TopMenu.jsx @@ -29,7 +29,7 @@ export default class TopMenu extends React.Component { <Menu color="blue" pointing secondary> <Image as="a" size="small" src="/assets/img/logo.png" href="/" /> <Menu.Menu position="right"> - <Menu.Item as={Link} to="/lowongan" name="home" active={activeItem === 'home'} onClick={this.handleItemClick} /> + <Menu.Item as={Link} to="/home" name="home" active={activeItem === 'home'} onClick={this.handleItemClick} /> <Menu.Item as={Link} to="/profile" name="profil" active={activeItem === 'profil'} onClick={this.handleItemClick} /> <Menu.Item as={Link} onClick={this.logout} name="logout" /> </Menu.Menu> diff --git a/core/views/accounts.py b/core/views/accounts.py index 1aab4a1c8ec7cd7085023539e1f4c2a18eacca1f..4afa426a8311f069eeb2fe3e8b9cad4b5a56f146 100644 --- a/core/views/accounts.py +++ b/core/views/accounts.py @@ -1,8 +1,6 @@ import requests from django.contrib.auth import authenticate, login from django.contrib.auth.models import User -from django.http import HttpResponseBadRequest -from django.http import HttpResponseNotAllowed from rest_framework import viewsets, status from rest_framework.decorators import list_route from rest_framework.parsers import FormParser,MultiPartParser @@ -151,11 +149,11 @@ class CompanyRegisterViewSet(viewsets.GenericViewSet): required: true type: string - name: password - description: password of the new acoount + description: password of the new account required: true type: string - name: email - description: email address of the new acoount + description: email address of the new account required: true type: string - name: name @@ -171,7 +169,7 @@ class CompanyRegisterViewSet(viewsets.GenericViewSet): required: false type: image - name: address - description: address of the new acoount + description: address of the new account required: false type: string """