Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flask role-based authorization
#11
OK, and it is in the file users.db, which was defined by yourself
Reply
#12
Yes, that is correct.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#13
I've edited the database.py with the database creation. It will add a default user of admin, password admin, and role of admin
After the app.secret_key in app.py I added
db = Database()
db.create()

database.py
import sqlite3 


class Database:
    def __init__(self):
        self.connection = sqlite3.connect('users.db')
        self.cursor = self.connection.cursor()

    def getuser(self, user, passwd):
        query = f'select user, password, role from users where user="{user}" and password="{passwd}"'
        return self.cursor.execute(query).fetchone()

    def adduser(self, user, password, role):
        pass

    def edituser(self, id):
        pass

    def deleteuser(self, id):
        pass

    def create(self):
        query = '''
                create table if not exists users (
                    id integer primary key,
                    user text,
                    password text,
                    role text
                )
                '''

        self.connection.execute(query)
        self.connection.commit()

        query = '''
                insert into users (user, password, role) values ("admin", "admin", "admin")
                '''
        self.connection.execute(query)
        self.connection.commit()
erdemath likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#14
Thanks a lot for all the info..
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Flask with paramiko based ssh client gives gevent LoopExit exception hbknjr 3 4,847 Dec-25-2018, 07:48 AM
Last Post: hbknjr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020