Skip to content

Commit

Permalink
Correções diversAs
Browse files Browse the repository at this point in the history
  • Loading branch information
pablomariz committed May 21, 2020
1 parent 6f5e684 commit 7421149
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 76 deletions.
11 changes: 6 additions & 5 deletions database_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
from mysql_manager import Gera_query

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


def connect(self, database):
Expand Down Expand Up @@ -57,11 +56,13 @@ def authenticate(self, database):
config = configparser.ConfigParser()
config.read('conf.cfg')

if self.database == 1:
if database == 1:
config_bank = 'config_bank_app'
else:
config_bank = 'config_bank_api'

print(config_bank)

address_bank = config.get(config_bank, 'address_bank')
name_bank = config.get(config_bank, 'name_bank')
user_bank = config.get(config_bank, 'user_bank')
Expand Down Expand Up @@ -132,15 +133,15 @@ def return_user_id(self, username):


def return_salt(self, username):
query = f'select salt from usuarios where login = "{username}"'
query = f'select salt from usuarios where username = "{username}"'

salt = self.commit_with_return(query)[0][0]

return salt


def return_password(self, username, password):
query = f'select password from usuarios where login = "{username}" and password = "{password}"'
query = f'select password from usuarios where username = "{username}" and password = "{password}"'

password = self.commit_with_return(query)[0][0]

Expand Down
25 changes: 12 additions & 13 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def gera_token(self, data):
user_id = self.database.return_user_id(username)

token = str(user_type)
token += self.crypto(username, user_id)
token += self.crypto(username, str(user_id))

query = f"INSERT INTO `tokens` (`user`,`token`) VALUES ({int(user_id)}, '{token}');"
self.database.commit_without_return(query, database = 2)
Expand Down Expand Up @@ -82,20 +82,20 @@ def confirm_token(self, data):
def active_token(self, token, user_id):
try:
query = f'select id from tokens where token = {token} and user = {user_id}'
token_id = self.database.commit_with_return(query, database = 2)[0][0]
if len(id) > 0:
token_id = self.database.commit_with_return(query, database = 2)[0]

if len(token_id) > 0:
query = self.gera_query.alterar_dados_da_tabela('connections', ['active'], [1], where=True,
valor_where=token_id, coluna_verificacao='id')
valor_where=token_id[0], coluna_verificacao='id')
self.database.commit_without_return(query, database = 2)
else:
query = self.gera_query.inserir_na_tabela('connections', ['token'], [token_id])
query = self.gera_query.inserir_na_tabela('connections', ['token'], [token_id[0]])
self.database.commit_without_return(query, database = 2)

self.r = {
'Message' : {
'token' : token,
'token_id' : token_id
'token_id' : token_id[0]
},
'Status' : 200
}
Expand All @@ -111,14 +111,14 @@ def active_token(self, token, user_id):
def deactive_token(self, token):
try:
query = f'select id from tokens where token = {token}'
token_id = self.database.commit_with_return(query, database = 2)[0][0]
token_id = self.database.commit_with_return(query, database = 2)[0]

if len(id) > 0:
if len(token_id) > 0:
query = self.gera_query.alterar_dados_da_tabela('connections', ['active'], [0], where=True,
valor_where=token_id, coluna_verificacao='id')
valor_where=token_id[0], coluna_verificacao='id')
self.database.commit_without_return(query, database = 2)
else:
query = self.gera_query.inserir_na_tabela('connections', ['token', 'active'], [token_id, 0])
query = self.gera_query.inserir_na_tabela('connections', ['token', 'active'], [token_id[0], 0])
self.database.commit_without_return(query, database = 2)

self.r = {
Expand Down Expand Up @@ -223,7 +223,6 @@ def novo_veiculo(self, data):
username = data['Username']
user_type = data['UserType']
license_plate = data['LicensePlate']
username = data['Username']

user_id = self.database.return_user_id(username)
columns = self.database.return_columns('carros')
Expand Down Expand Up @@ -406,7 +405,7 @@ def autenticar_usuario(self, data):

user_id = self.database.return_user_id(username)

if len(user_id) == 0:
if not user_id:
raise Exception('Usuário não encontrado no banco de dados')

salt = self.database.return_salt(username)
Expand Down
Loading

0 comments on commit 7421149

Please sign in to comment.