Fakultas Ilmu Komputer UI

Commit c2eecf47 authored by Joshua Casey's avatar Joshua Casey
Browse files

Merge branch 'UserStory2' of https://gitlab.com/PPL2017csui/PPLA1 into UserStory2

parents bdcd4933 4855d770
......@@ -35,11 +35,11 @@ export default class App extends React.Component {
<Route path="/register" component={CompanyRegister} />
<Route component={Dashboard} onEnter={this.handleAuth}>
<Route path="/" component={Profile} />
<Route path="profile" component={Profile} />
<Route path="lowongan" component={VacancyPage} />
<Route path="users" component={Profile} />
<Route path="/profile" component={Profile} />
<Route path="/lowongan" component={VacancyPage} />
<Route path="/users" component={Profile} />
</Route>
<Redirect from="*" to="/login" />
<Redirect from="*" to={Server.isLoggedIn() ? '/lowongan' : '/login'} />
</Router>
);
}
......
......@@ -2,6 +2,7 @@ import React from 'react';
import { Form, Input, Button, Message, Image } from 'semantic-ui-react';
import { browserHistory } from 'react-router';
import Server from '../lib/Server';
import Storage from '../lib/Storage';
export default class LoginForm extends React.Component {
......@@ -21,7 +22,7 @@ export default class LoginForm extends React.Component {
constructor(props) {
super(props);
/* istanbul ignore next */
this.state = { email: '', password: '', errorFlag: false };
this.state = { username: '', password: '', errorFlag: false };
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
......@@ -33,11 +34,13 @@ export default class LoginForm extends React.Component {
handleSubmit(event) {
event.preventDefault();
const data = {
type: this.props.type,
email: this.state.email,
'login-type': this.props.type,
username: this.state.username,
password: this.state.password,
};
Server.post('api/login/', data).then(() => {
Server.post('/login/', data).then((response) => {
Storage.set('user-data', response);
browserHistory.push('/home');
}, () => {
this.setState({ errorFlag: true });
......@@ -52,8 +55,8 @@ export default class LoginForm extends React.Component {
</div>
<Form.Group widths="equal">
<Form.Field required>
<label htmlFor="id"> Email </label>
<Input type="text" id="email" icon="user" iconPosition="left" placeholder="email" onChange={e => this.handleChange(e, 'email')} required />
<label htmlFor="id"> Username </label>
<Input type="text" id="username" icon="user" iconPosition="left" placeholder="username" onChange={e => this.handleChange(e, 'username')} required />
</Form.Field>
</Form.Group>
......@@ -67,7 +70,7 @@ export default class LoginForm extends React.Component {
<Button type="submit" fluid color="blue">Login</Button>
<Message
error
content="Login gagal: email atau password salah."
content="Login gagal: username atau password salah."
/>
</Form>
......
import React from 'react';
import { Menu, Image } from 'semantic-ui-react';
import { Link } from 'react-router';
import { Link, browserHistory } from 'react-router';
import Server from '../lib/Server';
import Storage from '../lib/Storage';
export default class TopMenu extends React.Component {
state = { activeItem: 'home' };
constructor(props) {
super(props);
/* istanbul ignore next */
this.logout = this.logout.bind(this);
}
handleItemClick = (e, { name }) => this.setState({ activeItem: name })
render() {
const { activeItem } = this.state;
logout = () => {
Server.get('/api-auth/logout/?next=/', true).then(() => {
Storage.clear();
browserHistory.push('/login');
});
};
render() {
return (
<Menu color='blue' pointing secondary>
<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="/profile" name='profil' active={activeItem === 'profil'} onClick={this.handleItemClick}/>
<Menu.Item as={Link} to="/lowongan" name="home" onClick={this.handleItemClick} />
<Menu.Item as={Link} to="/profile" name="profil" onClick={this.handleItemClick} />
{Server.isLoggedIn() ?
<Menu.Item as={Link} href="/api/api-auth/logout/?next=/" name='logout' active={activeItem === 'logout'} onClick={this.handleItemClick}/> :
<Menu.Item as={Link} to="/login" name='login' active={activeItem === 'login'} onClick={this.handleItemClick} />
}
<Menu.Item as={Link} onClick={this.logout} name="logout" /> :
<Menu.Item as={Link} to="/login" name="login" />
}
</Menu.Menu>
</Menu>
);
......
......@@ -44,7 +44,7 @@ export default class Server {
if (response.status === 204) {
return response;
}
return response.json();
return response;
});
/* istanbul ignore next */
......
......@@ -34,6 +34,7 @@ class UserViewSet(viewsets.ModelViewSet):
return [AllowAny()]
return super(UserViewSet, self).get_permissions()
class StudentViewSet(viewsets.ModelViewSet):
queryset = Student.objects.all()
serializer_class = StudentSerializer
......
from rest_framework import viewsets
from rest_framework.generics import get_object_or_404
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from core.lib.permissions import IsAdminOrStudent, IsAdminOrCompany
......@@ -13,6 +14,11 @@ class VacancyViewSet(viewsets.ModelViewSet):
serializer_class = VacancySerializer
permission_classes = [IsAdminOrCompany]
def get_permissions(self):
if self.action in ["get", "list"]:
return [IsAuthenticated()]
return super(VacancyViewSet, self).get_permissions()
class ApplicationViewSet(viewsets.GenericViewSet):
serializer_class = VacancySerializer
......
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