diff --git a/config/_development.json b/config/_development.json index eb77e8c..41eccab 100644 --- a/config/_development.json +++ b/config/_development.json @@ -51,5 +51,16 @@ "access_expires": 60, "refresh_expires": 1440, "algorithm": "HS512" + }, + "openapi": { + "host": "http://eduardo-velasques.dev.netuno.org:10090", + "basePath": "/services", + "schemes": [ "http" ], + "servers": [ + { + "url": "http://eduardo-velasques.dev.netuno.org:10090/services", + "description": "Desenvolvimento Remoto" + } + ] } } diff --git a/dbs/social_ma.mv.db b/dbs/social_ma.mv.db index f2892ea..70f219d 100644 Binary files a/dbs/social_ma.mv.db and b/dbs/social_ma.mv.db differ diff --git a/server/services/_openapi.json b/server/services/_openapi.json new file mode 100644 index 0000000..8a67c12 --- /dev/null +++ b/server/services/_openapi.json @@ -0,0 +1,15 @@ +{ + "info": { + "title": "Plataforma Social", + "description": "REST API da Plataforma Social.", + "version": "1.0" + }, + "components": { + "securitySchemes": { + "BearerAuth": { + "type": "http", + "scheme": "bearer" + } + } + } + } \ No newline at end of file diff --git a/server/services/_schema/cities.js b/server/services/_schema/cities.js new file mode 100644 index 0000000..78510d0 --- /dev/null +++ b/server/services/_schema/cities.js @@ -0,0 +1,10 @@ + +const dbCidades = _db.query("SELECT uid FROM cidade") + +const citiesUids = _val.list() + +for (let dbCidade of dbCidades) { + citiesUids.add(dbCidade.getString("uid")) +} + +_dataSchema.set("enum", citiesUids) \ No newline at end of file diff --git a/server/services/_schema/result.out.200.json b/server/services/_schema/result.out.200.json new file mode 100644 index 0000000..312da85 --- /dev/null +++ b/server/services/_schema/result.out.200.json @@ -0,0 +1,11 @@ +{ + "type": "object", + "properties": { + "result": { + "type": "boolean" + } + }, + "required": [ + "result" + ] +} \ No newline at end of file diff --git a/server/services/_schema/result.out.409.json b/server/services/_schema/result.out.409.json new file mode 100644 index 0000000..39c19ed --- /dev/null +++ b/server/services/_schema/result.out.409.json @@ -0,0 +1,15 @@ +{ + "type": "object", + "properties": { + "result": { + "type": "boolean" + }, + "error": { + "type": "string-not-empty" + } + }, + "required": [ + "result", + "error" + ] +} \ No newline at end of file diff --git a/server/services/register.post.in.json b/server/services/register.post.in.json new file mode 100644 index 0000000..d0e5ef8 --- /dev/null +++ b/server/services/register.post.in.json @@ -0,0 +1,32 @@ +{ + "summary": "Registro", + "description": "Registro da conta do usuário.", + "type": "object", + "security": [ + { "BearerAuth": [] } + ], + "properties": { + "name": { + "type": "string-not-empty" + }, + "surname": { + "type": "string-not-empty" + }, + "username": { + "type": "string-not-empty" + }, + "password": { + "type": "string-not-empty" + }, + "email": { + "type": "string-not-empty" + }, + "city_uid": { + "type": "uid", + "_schema": "cities" + } + }, + "required": [ + "name", "surname", "username", "password", "email", "city_uid" + ] +} \ No newline at end of file diff --git a/server/services/register.post.js b/server/services/register.post.js index 3a48bb2..a68ff88 100644 --- a/server/services/register.post.js +++ b/server/services/register.post.js @@ -15,16 +15,18 @@ if (dbCidade == null) { _header.status(409) _out.json( _val.map() - .set("error", true) - .set("message", "city-not-found") + .set("result", false) + .set("error", "city-not-found") ) } else if (emailExists != null) { + _header.status(409) _out.json( _val.map() .set("result", false) .set("error", "email-exists") ) } else if (usernameExists != null) { + _header.status(409) _out.json( _val.map() .set("result", false) diff --git a/server/services/register.post.out.200.json b/server/services/register.post.out.200.json new file mode 100644 index 0000000..982da14 --- /dev/null +++ b/server/services/register.post.out.200.json @@ -0,0 +1,3 @@ +{ + "_schema": "result.out.200" +} \ No newline at end of file diff --git a/server/services/register.post.out.409.json b/server/services/register.post.out.409.json new file mode 100644 index 0000000..3fc0029 --- /dev/null +++ b/server/services/register.post.out.409.json @@ -0,0 +1,3 @@ +{ + "_schema": "result.out.409" +} \ No newline at end of file diff --git a/website/src/App.js b/website/src/App.js index c3c5a22..388eda3 100644 --- a/website/src/App.js +++ b/website/src/App.js @@ -1,5 +1,6 @@ import React, { useEffect, useState} from 'react'; +import _auth from '@netuno/auth-client'; import _service from '@netuno/service-client'; import { Layout, Menu } from 'antd'; @@ -14,6 +15,8 @@ import Login from './pages/Login'; import Register from './pages/Register'; import Main from './pages/Main'; +import Core from './Core'; + import logo from './logo.svg'; import './App.less'; @@ -22,6 +25,7 @@ const { Header, Footer, Content } = Layout; const { SubMenu } = Menu; function App() { + const [ logged, setLogged ] = useState(false); const [ data, setData ] = useState([]); useEffect(() => { _service({ @@ -37,20 +41,40 @@ function App() { }); }, []); + Core.events.login = () => { + setLogged(true); + } + Core.events.logout = () => { + setLogged(false); + } + + let menu = null; + if (_auth.isLogged()) { + menu = <> + + Principal + + ; + } else { + menu = <> + + Home + + + Login + + + Registrar + + ; + } + return (
- - Home - - - Login - - - Registrar - + {menu}
diff --git a/website/src/Core.js b/website/src/Core.js new file mode 100644 index 0000000..ef16406 --- /dev/null +++ b/website/src/Core.js @@ -0,0 +1,7 @@ + +export default class Core { + static events = { + login: ()=> {}, + logout: ()=> {} + }; +} diff --git a/website/src/pages/Login/index.js b/website/src/pages/Login/index.js index 9ad51ae..d26bb6c 100644 --- a/website/src/pages/Login/index.js +++ b/website/src/pages/Login/index.js @@ -6,6 +6,8 @@ import _auth from '@netuno/auth-client'; import { Redirect } from "react-router-dom"; +import Core from "../../Core"; + import './index.less'; const layout = { @@ -31,6 +33,8 @@ export default ()=> { } else { localStorage.removeItem("login"); } + Core.events.login(); + //window.location = '/main'; }, fail: ()=> { setLoading(false); diff --git a/website/src/pages/Main/index.js b/website/src/pages/Main/index.js index 5abc607..2773aa7 100644 --- a/website/src/pages/Main/index.js +++ b/website/src/pages/Main/index.js @@ -4,6 +4,8 @@ import { Redirect } from "react-router-dom"; import _auth from '@netuno/auth-client'; +import Core from "../../Core"; + import { Button } from 'antd'; export default ()=> { @@ -14,6 +16,8 @@ export default ()=> { const onLogout = ()=> { _auth.logout(); setLoading(true); + Core.events.logout(); + //window.location = '/login'; } return (