Skip to content

Commit

Permalink
Merge pull request #18 from Duzz-Clean/duzzsys-patch-1
Browse files Browse the repository at this point in the history
Novas funcionalidades de autenticação.
  • Loading branch information
pablomariz authored May 21, 2020
2 parents 8e75e6f + d22ba2d commit ec5ec83
Show file tree
Hide file tree
Showing 7 changed files with 413 additions and 129 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ Os serviços estarão listados no fim deste documento, porém também estão dis

##### Rotas:

**_Atenção! Para uso das rotas, com excessão do novo usuário e autenticar usuário, é necessário informar as seguintes chaves-valores:_**

["Username"] = Nome de usuario ou email,
["UserType"] = Tipo do usuário,
["Token"] = Token de acesso à aplicação


**_As rotas obrigatórias para as demais estão descritas:_**


*__/novo_veiculo__*

Função : Encaminhar para fazer o cadastramento de um novo veículo
Expand Down
20 changes: 20 additions & 0 deletions apiDatabase.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
create database dcleanapi;
use dcleanapi;

create table connections(
`id` INT(12) PRIMARY KEY AUTO_INCREMENT,
`token` INT(12) NOT NULL, -- Chave estrangeira de tokens.id
`active` BOOLEAN DEFAULT TRUE
)ENGINE = InnoDB;

create table tokens(
`id` INT(12) PRIMARY KEY AUTO_INCREMENT,
`user` INT(12) NOT NULL, -- Usuário que utiliza
`token` TEXT NOT NULL, -- Token de autenticação
`datetime` TIMESTAMP DEFAULT NOW() -- Data e hora de gerado
)ENGINE = InnoDB;

ALTER TABLE connections
ADD CONSTRAINT fk_tokens FOREIGN KEY (token) REFERENCES tokens(id);

INSERT INTO `tokens` (`token`) VALUES ('953J359p267d761M');
8 changes: 7 additions & 1 deletion conf.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
[config_server]
devs = "Jonas Duarte, Pablo Mariz"

[config_bank]
[config_bank_app]
address_bank = localhost
name_bank = dclean
user_bank = root
password_bank = ''

[config_bank_api]
address_bank = localhost
name_bank = dcleanapi
user_bank = root
password_bank = ''
30 changes: 18 additions & 12 deletions database_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
from mysql_manager import Gera_query

class Database():
def __init__(self):
def __init__(self, database = 1):
self.gerador_de_query = Gera_query()
self.connected = False
self.database = database


def connect(self):
def connect(self, database):
if not self.connected:
credencials = self.authenticate()
credencials = self.authenticate(database)
address = credencials.get('AddressBank')
name = credencials.get('NameBank')
user = credencials.get('UserBank')
Expand Down Expand Up @@ -45,7 +46,7 @@ def disconnect(self):
self.conected = False
return True

def authenticate(self):
def authenticate(self, database):
"""
Utiliza as informações presentes no glpi.cfg para\n
retorná-las em forma de lista como credenciais
Expand All @@ -56,10 +57,15 @@ def authenticate(self):
config = configparser.ConfigParser()
config.read('conf.cfg')

address_bank = config.get('config_bank', 'address_bank')
name_bank = config.get('config_bank', 'name_bank')
user_bank = config.get('config_bank', 'user_bank')
password_bank = config.get('config_bank', 'password_bank')
if self.database == 1:
config_bank = 'config_bank_app'
else:
config_bank = 'config_bank_api'

address_bank = config.get(config_bank, 'address_bank')
name_bank = config.get(config_bank, 'name_bank')
user_bank = config.get(config_bank, 'user_bank')
password_bank = config.get(config_bank, 'password_bank')
if password_bank == "''":
password_bank = ''

Expand All @@ -71,8 +77,8 @@ def authenticate(self):
}


def commit_without_return(self, query):
self.connect()
def commit_without_return(self, query, database = 1):
self.connect(database)
try:
self.cursor.execute(query)
except:
Expand All @@ -82,9 +88,9 @@ def commit_without_return(self, query):
self.disconnect()
return True

def commit_with_return(self, query):
def commit_with_return(self, query, database = 1):
results = None
self.connect()
self.connect(database)
try:
self.cursor.execute(query)
except:
Expand Down
4 changes: 2 additions & 2 deletions db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ create table limpezas
(
`id` INT(12) PRIMARY KEY AUTO_INCREMENT,
`carro` INT(12) NOT NULL, -- Chave estrangeira de carros ID
`data` DATE NOT NULL
`data` TIMESTAMP DEFAULT NOW()
)ENGINE = InnoDB;
--
create table notificacoes
Expand Down Expand Up @@ -80,7 +80,7 @@ create table notificacoes_recusadas
`notificacao` INT(12) NOT NULL, -- Chave estrangeira de notificacoes ID
`tipo` INT(12) NOT NULL, -- Chave estrangeira de notificacoes_tipos ID
`carro` INT(12) NOT NULL, -- Chave estrangeira de carros ID
`data` DATE NOT NULL
`data` TIMESTAMP DEFAULT NOW()
)ENGINE = InnoDB;

INSERT INTO `tipos_usuarios` (`id`, `descricao`) VALUES (NULL, 'Usuário'), (NULL, 'Motorista'), (NULL, 'DuzzClean');
Expand Down
Loading

0 comments on commit ec5ec83

Please sign in to comment.