|
|
|
@ -1,8 +1,9 @@ |
|
|
|
import React from "react"; |
|
|
|
import React, { useState } from "react"; |
|
|
|
import "./index.less"; |
|
|
|
import Header from "../../components/Header"; |
|
|
|
import { Form, Input, Button, Checkbox, Row, Col } from "antd"; |
|
|
|
import { Form, Input, Button, Checkbox, Row, Col, notification } from "antd"; |
|
|
|
import _auth from "@netuno/auth-client"; |
|
|
|
import { Redirect } from "react-router-dom"; |
|
|
|
|
|
|
|
const layout = { |
|
|
|
labelCol: { span: 4 }, |
|
|
|
@ -14,15 +15,24 @@ const tailLayout = { |
|
|
|
}; |
|
|
|
|
|
|
|
const Login = () => { |
|
|
|
const [isLogged, setIsLogged] = useState(false); |
|
|
|
const onFinish = (values) => { |
|
|
|
_auth.login({ |
|
|
|
username: values.username, |
|
|
|
password: values.password, |
|
|
|
success: () => { |
|
|
|
alert("Login efetuado"); |
|
|
|
setIsLogged(true); |
|
|
|
if (values.remember) { |
|
|
|
localStorage.setItem("login", JSON.stringify(values)); |
|
|
|
} else { |
|
|
|
localStorage.removeItem("login"); |
|
|
|
} |
|
|
|
}, |
|
|
|
fail: () => { |
|
|
|
alert("ocorreu um erro"); |
|
|
|
notification["error"]({ |
|
|
|
message: "Ocorreu um erro", |
|
|
|
description: "Não foi possível realizar o login.", |
|
|
|
}); |
|
|
|
}, |
|
|
|
}); |
|
|
|
}; |
|
|
|
@ -30,6 +40,15 @@ const Login = () => { |
|
|
|
const onFinishFailed = (errorInfo) => { |
|
|
|
console.log("Failed:", errorInfo); |
|
|
|
}; |
|
|
|
let initialValues = { |
|
|
|
remember: true, |
|
|
|
}; |
|
|
|
if (localStorage.getItem("login")) { |
|
|
|
initialValues = JSON.parse(localStorage.getItem("login")); |
|
|
|
} |
|
|
|
if (_auth.isLogged()) { |
|
|
|
return <Redirect to="/main" />; |
|
|
|
} |
|
|
|
return ( |
|
|
|
<div className="login"> |
|
|
|
<Header /> |
|
|
|
@ -38,6 +57,7 @@ const Login = () => { |
|
|
|
<Col span={12}> |
|
|
|
<Form |
|
|
|
{...layout} |
|
|
|
initialValues={initialValues} |
|
|
|
className="login__form" |
|
|
|
onFinish={onFinish} |
|
|
|
onFinishFailed={onFinishFailed} |
|
|
|
@ -46,7 +66,10 @@ const Login = () => { |
|
|
|
label="Username" |
|
|
|
name="username" |
|
|
|
rules={[ |
|
|
|
{ required: true, message: "Por favor digite o seu nome de usuário." } |
|
|
|
{ |
|
|
|
required: true, |
|
|
|
message: "Por favor digite o seu nome de usuário.", |
|
|
|
}, |
|
|
|
]} |
|
|
|
> |
|
|
|
<Input /> |
|
|
|
|