Q: SQL login check ALCHEMY Pending

Asked

Viewed 159 times

0

I am creating a login to give access to the tool I am starting to create, the database is SQL Server

The structure of the project is this:

├── Project
│   ├── Controllers
│   │   ├── __init__.py
│   │   └── Mapping_Login
│   │       ├── __init__.py
│   │       └── Mapping_login.py
│   ├── __init__.py
│   ├── Models
│   │   ├── Conexao
│   │   │   ├── conexao.py
│   │   │   ├── conexao.pyc
│   │   │   ├── __init__.py
│   │   │   
│   │   ├── __init__.py
│   │   └── sing_in
│   │       ├── __init__.py
│   │       └── register.py
│   └── View
│       ├── __init__.py
│       ├── static_routes.py
│       ├── view_acept_reg.py
│       ├── view_index_page.py
│       └── view_register.py
├── run.py
├── static
│   ├── index.css
│   ├── main.css
│   ├── main.js
│   ├── user_login.png
│   └── util.css
└── templates
    └── printer
       ├── Acept.html
       ├── index.html
       ├── Register.html
       └── TelaInicial.html

I created a database mapping with SQLALCHEMY to do CRUD

class mapping_log:
    def __init__(self):
        metadata = MetaData()
        self.table = Table('login',metadata,
            Column('id',Integer, primary_key = True),
            Column('usuario',String),
            Column('Senha',String))


    def login(self, Usuario,senha):
         selecionar = self.table.select().where(self.table.c.usuario 
                         == Usuario and self.table.c.Senha == senha)
         conn = __engine__()
         usuarios = conn.execute(selecionar)
         print(usuarios)
         return usuarios
    def insert(self,key_value):
         inserir = self.table.insert()
         conn = __engine__()
         conn.execute(inserir,
              usuario = key_value.get('usuario'),
              Senha = key_value.get('Senha')
          )
    def deletar(self, id ):
        deletar_User =  self.table.delete().where(self.table.c.id == 
        id)        
        conn = __engine__()
        conn.execute(deletar_User)        

I created Routes for the login part I set the "def" as a test and I’m taking the login and password of the user from the template, but I’m having difficulty validating it checking if it exists and allowing access

 # -*- coding utf-8 -*-

 from flask import  render_template, abort, 
      render_template_string,url_for,Blueprint,request
 from Project.Controllers.Mapping_Login.Mapping_login import 
      mapping_log
 from Project import app 


 login_db = mapping_log()

 app_router = Blueprint('app',__name__, url_prefix='/index')
 @app_router.route('/')
      def hellou():
          return render_template('printer/index.html')



 @app_router.route('/initi', methods=['GET', 'POST'])
       def teste():
           usuario = request.form.get('login')
           senha = request.form.get ('password')
           usuarios =  login_db.login(usuario,senha)
           print(usuarios,"pasou aqui ")
           return render_template('printer/TelaInicial.html')



  app.register_blueprint(app_router)    

I don’t know where I might be going wrong so that this validation does not right, it passes to "Telainicial.html" with anything I type in the Login and password fields!

  • Where is giving this error? In function teste?

  • @Renan This it returns this error,

  • Then it’s because you’re not entering the condition if usuarios.rowcount() == 1. The error is saying that it is necessary to return a valid answer, that the return was None or no return has been specified. It is necessary to return something to be rendered by Flask in its function teste() there is only return if you enter the previously mentioned condition.

  • @Renan then I have to make this veficação direct in def login?

  • Not necessarily, you debugged the code to see what is being returned in login_db.login(usuario,senha)? usuarios.rowcount() is returning something other than 1.

  • @Renan

  • @Renan of the error when checking the user and password in if user.rowcount() ==1

  • And what’s the mistake? Edit your query and provide a [mcve]

  • @Renan edited!

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.