Fakultas Ilmu Komputer UI

Commit dfc575b6 authored by Zamil Majdy's avatar Zamil Majdy
Browse files

revised company register

parent 50b7c7cb
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>
......
......@@ -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>
......
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
"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment