Commit 8a734896 authored by Dida Adams Arizona's avatar Dida Adams Arizona

Merge branch 'riri' into 'master'

login lagi

See merge request !41
parents bc31197f ba7e806e
...@@ -61,6 +61,7 @@ const create = (baseURL = 'https://trftia.eksad.com/tia-reporting-dev/public/') ...@@ -61,6 +61,7 @@ const create = (baseURL = 'https://trftia.eksad.com/tia-reporting-dev/public/')
// //
const getRoot = () => api.get('') const getRoot = () => api.get('')
const login = (body) => api.post('auth/login', body) const login = (body) => api.post('auth/login', body)
const verification = (body) => api.post('email/reset_password', body)
//Role //Role
const getRole = () => api.get('role/get_all_role') const getRole = () => api.get('role/get_all_role')
...@@ -83,6 +84,7 @@ const create = (baseURL = 'https://trftia.eksad.com/tia-reporting-dev/public/') ...@@ -83,6 +84,7 @@ const create = (baseURL = 'https://trftia.eksad.com/tia-reporting-dev/public/')
// a list of the API functions from step 2 // a list of the API functions from step 2
getRoot, getRoot,
login, login,
verification,
getRole, getRole,
addRole, addRole,
editRole, editRole,
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import Images from '../assets/Images'; import Images from '../assets/Images';
import { TextField, InputAdornment, Button, Typography } from '@material-ui/core'; import { TextField, InputAdornment, Button, Typography } from '@material-ui/core';
import api from '../api';
class ForgotPassword extends Component { class ForgotPassword extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.state = { this.state = {
username: '' email: ''
} }
} }
...@@ -15,6 +16,13 @@ class ForgotPassword extends Component { ...@@ -15,6 +16,13 @@ class ForgotPassword extends Component {
let data = this.state let data = this.state
this.setState({...data, [e.target.name] : e.target.value}) this.setState({...data, [e.target.name] : e.target.value})
} }
verification() {
let payload = {
"email": this.state.email
}
}
render() { render() {
return ( return (
<div style={{ flex: 1, display: 'flex', backgroundColor: '#51c6ea', height: '100vh', justifyContent: 'center', alignItems: 'center' }}> <div style={{ flex: 1, display: 'flex', backgroundColor: '#51c6ea', height: '100vh', justifyContent: 'center', alignItems: 'center' }}>
...@@ -23,11 +31,11 @@ class ForgotPassword extends Component { ...@@ -23,11 +31,11 @@ class ForgotPassword extends Component {
<TextField <TextField
label={<Typography style={{fontSize: 12, fontFamily: 'Nunito Sans, sans-serif'}}>Email *</Typography>} label={<Typography style={{fontSize: 12, fontFamily: 'Nunito Sans, sans-serif'}}>Email *</Typography>}
id="username" id="email"
type={"text"} type={"text"}
name={"username"} name={"email"}
value={this.state.username} value={this.state.email}
onChange={(username) => this.setState({username: username.target.value})} onChange={(email) => this.setState({email: email.target.value})}
variant="outlined" variant="outlined"
error={false} error={false}
style={{ width: 250, height: 51, marginTop: 32, fontSize: 14 }} style={{ width: 250, height: 51, marginTop: 32, fontSize: 14 }}
...@@ -37,7 +45,7 @@ class ForgotPassword extends Component { ...@@ -37,7 +45,7 @@ class ForgotPassword extends Component {
}} }}
/> />
<Button variant="contained" style={{ marginTop: 23, width: 250, height: 30, borderRadius: 4 }} disabled> <Button variant="contained" style={{ marginTop: 23, width: 250, height: 30, borderRadius: 4, backgroundColor: '#51c6ea', color: '#ffffff' }}>
<Typography style={{fontSize: 12, fontFamily: 'Nunito Sans, sans-serif'}}>Lanjut</Typography> <Typography style={{fontSize: 12, fontFamily: 'Nunito Sans, sans-serif'}}>Lanjut</Typography>
</Button> </Button>
......
...@@ -23,7 +23,11 @@ class Login extends Component { ...@@ -23,7 +23,11 @@ class Login extends Component {
this.state = { this.state = {
username: '', username: '',
password: '', password: '',
showPass: false showPass: false,
errorUsername: false,
errorPassword: false,
msgUsername: '',
msgPassword: ''
} }
} }
...@@ -34,6 +38,21 @@ class Login extends Component { ...@@ -34,6 +38,21 @@ class Login extends Component {
handleChange(e) { handleChange(e) {
let data = this.state let data = this.state
this.setState({...data, [e.target.name] : e.target.value}) this.setState({...data, [e.target.name] : e.target.value})
if (e.target.name == "username") {
this.setState({ errorUsername: false, msgUsername: '' })
} else if (e.target.name) {
this.setState({ errorPassword: false, msgPassword: '' })
}
}
validateLogin() {
if (this.state.username.trim() == "") {
this.setState({ errorUsername: true, msgUsername: 'Username harus diisi!' })
} else if (this.state.password.trim() == "") {
this.setState({ errorPassword: true, msgPassword: 'Password harus diisi!' })
} else {
this.login()
}
} }
login() { login() {
...@@ -46,7 +65,11 @@ class Login extends Component { ...@@ -46,7 +65,11 @@ class Login extends Component {
localStorage.setItem(Constant.TOKEN, response.data.data.token) localStorage.setItem(Constant.TOKEN, response.data.data.token)
this.props.history.push('/home/beranda') this.props.history.push('/home/beranda')
} else { } else {
alert(response.data.message) if (response.data.message == 'Password Salah!') {
this.setState({ errorPassword: true, msgPassword: response.data.message })
} else {
this.setState({ errorUsername: true, msgUsername: response.data.message })
}
} }
}) })
} }
...@@ -59,7 +82,7 @@ class Login extends Component { ...@@ -59,7 +82,7 @@ class Login extends Component {
<img src={Images.imageLogin} style={{ marginTop: 30 }} /> <img src={Images.imageLogin} style={{ marginTop: 30 }} />
</div> </div>
<div style={{ width: '50%', height: '100vh', backgroundColor: '#51c6ea', display: 'flex', justifyContent: 'center', alignItems: 'center', flexDirection: 'column' }}> <div style={{ width: '50%', height: '100vh', backgroundColor: '#51c6ea', display: 'flex', justifyContent: 'center', alignItems: 'center', flexDirection: 'column' }}>
<div style={{ paddingTop: 56, paddingLeft: 64, paddingRight: 64, display: 'flex', flexDirection: 'column', width: 378, height: 431, borderRadius: 12, boxShadow: '0 2 4 0 rgba(0, 0, 0, 0.2)', backgroundColor: '#ffffff' }}> <div style={{ paddingTop: 56, paddingLeft: 54, paddingRight: 54, display: 'flex', flexDirection: 'column', width: 388, height: 441, borderRadius: 12, boxShadow: '0 2 4 0 rgba(0, 0, 0, 0.2)', backgroundColor: '#ffffff' }}>
<img src={Images.tia} /> <img src={Images.tia} />
<TextField <TextField
...@@ -68,11 +91,13 @@ class Login extends Component { ...@@ -68,11 +91,13 @@ class Login extends Component {
type={"text"} type={"text"}
name={"username"} name={"username"}
value={this.state.username} value={this.state.username}
onChange={(username) => this.handleChange(username)} onChange={(username) => {
this.handleChange(username)
}}
variant="outlined" variant="outlined"
error={false} error={this.state.errorUsername}
style={{ width: 250, height: 51, marginTop: 32, fontSize: 14 }} style={{ width: '100%', height: 51, marginTop: 32, fontSize: 14 }}
helperText="" helperText={this.state.msgUsername}
InputProps={{ InputProps={{
endAdornment: <InputAdornment position="end"><img src={Images.email} /></InputAdornment>, endAdornment: <InputAdornment position="end"><img src={Images.email} /></InputAdornment>,
}} }}
...@@ -84,11 +109,13 @@ class Login extends Component { ...@@ -84,11 +109,13 @@ class Login extends Component {
type={this.state.showPass ? 'text' : 'password'} type={this.state.showPass ? 'text' : 'password'}
name={"password"} name={"password"}
value={this.state.password} value={this.state.password}
onChange={(password) => this.handleChange(password) } onChange={(password) => {
this.handleChange(password)
}}
variant="outlined" variant="outlined"
error={false} error={this.state.errorPassword}
style={{ width: 250, height: 51, marginTop: 20 }} style={{ width: '100%', height: 51, marginTop: this.state.errorUsername ? 35 : 20 }}
helperText="" helperText={this.state.msgPassword}
InputProps={{ InputProps={{
endAdornment: <InputAdornment position="end"> endAdornment: <InputAdornment position="end">
<IconButton <IconButton
...@@ -103,12 +130,12 @@ class Login extends Component { ...@@ -103,12 +130,12 @@ class Login extends Component {
}} }}
/> />
<div style={{ flexDirection: 'row', width: '100%', marginTop: 16 }}> <div style={{ flexDirection: 'row', width: '100%', marginTop: this.state.errorPassword ? 26 : 16 }}>
<CustomCheckbox name="checked-remember" /> <CustomCheckbox name="checked-remember" />
<span style={{ color: 'rgba(0, 0, 0, 0.5)', fontSize: 12, fontFamily: 'Nunito Sans, sans-serif' }}>Remember Me</span> <span style={{ color: 'rgba(0, 0, 0, 0.5)', fontSize: 12, fontFamily: 'Nunito Sans, sans-serif' }}>Remember Me</span>
<span style={{marginLeft: 30, color: '#51c6ea', cursor: 'pointer', fontSize: 12, fontFamily: 'Nunito Sans, sans-serif' }}>Lupa Kata Sandi?</span> <span style={{marginLeft: 30, color: '#51c6ea', cursor: 'pointer', fontSize: 12, fontFamily: 'Nunito Sans, sans-serif' }}>Lupa Kata Sandi?</span>
</div> </div>
<Button name="submit" variant="contained" onClick={() => this.login()} style={{ marginTop: 23, width: '100%', height: 35, borderRadius: 4 }}> <Button name="submit" variant="contained" disabled={this.state.username.trim() == '' && this.state.password.trim() == '' ? true : false} onClick={() => this.validateLogin()} style={{ marginTop: 23, width: '100%', height: 35, borderRadius: 4, color: this.state.username.trim() == '' && this.state.password.trim() == '' ? '#4b4b4b' : '#fff', backgroundColor: this.state.username.trim() == '' && this.state.password.trim() == '' ? '#d8d8d8' : '#51c6ea' }}>
<Typography style={{fontSize: 12, fontFamily: 'Nunito Sans, sans-serif'}}>Login</Typography> <Typography style={{fontSize: 12, fontFamily: 'Nunito Sans, sans-serif'}}>Login</Typography>
</Button> </Button>
</div> </div>
...@@ -118,4 +145,4 @@ class Login extends Component { ...@@ -118,4 +145,4 @@ class Login extends Component {
} }
} }
export default Login; export default Login;
\ No newline at end of file
Markdown is supported
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