Giter Site home page Giter Site logo

hacking-flask-security-admin-example's Introduction

Example of combining Flask-Security and Flask-Admin
by Steve Saporta
April 15, 2014

Flask-Security provides a convenient way to add authentication and authorization to a Flask web app. Flask-Admin provides a convenient way to perform CRUD operations on database tables. This example combines Flask-Security and Flask-Admin so that authorized administrators can maintain the lists of users and roles that control access to the app.

You could easily generalize this app so that administrators could manage all sorts of database tables, not just users and roles.

This app also provides a basic example of the use of several underlying technologies that support Flask-Security and Flask-Admin.

Here are some helpful links:

To run this app, you'll need to install:

  • Python 3.3
  • Flask
  • Flask-Admin
  • Flask-Security
  • SQLAlchemy
  • A database system (PostgreSQL, SQLite, or another database system of your choice)
  • An empty database named "flask_example"

I personally ran it on Windows 7 with a PostgreSQL database, but you should be able to use the operating system and database system of your choice.

Comments throughout main.py explain what's going on.

Once you have the app running, you can view it in your browser (e.g. http://localhost:8080).

Some things to notice:

  • When you first visit the app's home page, you'll be prompted to log in, thanks to Flask-Security.
  • If you log in with username=[email protected] and password=password, you'll have the "end-user" role.
  • If you log in with username=[email protected] and password=password, you'll have the "admin" role.
  • Either role is permitted to access the home page.
  • Either role is permitted to access the /admin page. However, unless you have the "admin" role, you won't see the tabs for administration of users and roles on this page.
  • Only the admin role is permitted to access sub-pages of /admin page such as /admin/userview. Otherwise, you'll get a "forbidden" response.
  • Note that, when editing a user, the names of roles are automatically populated thanks to Flask-Admin.
  • You can add and edit users and roles. The resulting users will be able to log in (unless you set active=false) and, if they have the "admin" role, will be able to perform administration.

Enjoy!

hacking-flask-security-admin-example's People

Contributors

sasaporta avatar ssaporta-joule avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.