Giter VIP home page Giter VIP logo

hack4impact / flask-base Goto Github PK

View Code? Open in Web Editor NEW
3.0K 3.0K 470.0 14.54 MB

A simple Flask boilerplate app with SQLAlchemy, Redis, User Authentication, and more.

Home Page: http://hack4impact.github.io/flask-base

License: MIT License

Python 44.78% JavaScript 8.65% CSS 4.75% HTML 40.37% Dockerfile 0.75% SCSS 0.54% Shell 0.10% Procfile 0.06%
authentication boilerplate database flask python3 redis sqlalchemy user-management

flask-base's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-base's Issues

Refactor menu code

  • Should fix macros for menus so they're more modular
  • Backport some new work done for journalup's front-end

Python 2 support

It looks like the only thing keeping this project from being able to run python2 currently is import urllib.parse in config.py, this can be easily handled with an if/else clause, is there anything else?

Using flask-base as a base for a new project?

What's the recommended way to use flask-base as the base for a new project? It seems if you use git clone then copy paste the files into your new project, you will lose track of updates and fixes.

Would git submodule add -b master https://github.com/hack4impact/flask-base be the preferred method?

Security enhancements

  • Double-check that CSRF protection is working properly
  • Other features from flask-security package that might be missing

Define login/logout/change password/reset password views

We should explicitly define these views. For example, in JournalUp, we have these functions:

@main.route('/login', methods=['GET', 'POST'])
def login():
    if current_user.is_authenticated():
        return redirect(index_url_for_blueprint(current_user))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter(func.lower(User.email) == func.lower(form.email.data)).first()
        if user is not None and user.verify_password(form.password.data):
            login_user(user, form.remember_me.data)
            # if user.is_role("admin"):
            #     return redirect(url_for('admin.index'))
            # elif user.is_role("student"):
            #     return redirect(url_for('students.index'))
            # else:
            #     return redirect(url_for('mentors.index'))
            return redirect(index_url_for_blueprint(user))
        flash('Invalid username or password.')
    return render_template('main/login.html', form=form)

@main.route('/logout')
@login_required
def logout():
    logout_user()
    flash('You have been logged out.')
    return redirect(url_for('.index'))

@main.route('/change-password', methods=['GET', 'POST'])
@login_required
def change_password():
    form = ChangePasswordForm()
    if form.validate_on_submit():
        user = current_user
        if user.verify_password(form.current_password.data):
            user.set_password(form.new_password.data)
            flash('Your password was successfully changed.')
            return redirect(index_url_for_blueprint(current_user))
        form.current_password.errors.append('Invalid password.')
    return render_template('main/change_password.html', form=form)

@main.route('/forgot-password', methods=['GET', 'POST'])
def forgot_password():
    if current_user.is_authenticated():
        flash('You are already logged in.')
        return redirect(index_url_for_blueprint(current_user))
    form = ForgotPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            send_reset_email(user = user)
            flash('The password reset email was sent.')
            return redirect(url_for('.index'))
        form.email.errors.append('Your email is invalid.')
    return render_template('main/forget_password.html', form=form)

@main.route('/reset/<token>', methods=['GET', 'POST'])
def reset_password_with_token(token):
    if current_user.is_authenticated():
        flash('You are already logged in.')
        return redirect(index_url_for_blueprint(current_user))
    user = User.query.filter_by(reset_token = token).first()
    if user is None:
        return abort(404)
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.new_password.data)
        flash('Your password was successfully changed.')
        login_user(user)
        user.reset_token = None
        return redirect(index_url_for_blueprint(current_user))        
    return render_template('main/reset_password.html', form=form)

Allowed to log in even before confirming email

Steps to reproduce:

  1. Make an account
  2. Don't confirm email
  3. Log in with account

Expected
4. See message that asks to reconfirm email and you are blocked from doing other user things

Actual
4. See message that asks to reconfirm email and you can do other user things

Make sure all db.sessions are committed

After a db.session.add the session must also be committed. This has led to strange bugs in cac where locally everything works but sessions that aren't committed in production don't work.

Add more in-code commenting

For people new to flask who are working on projects forked from flask-base, it would be nice to have more explanations of how and why we do things. This is a decently complex flask app and would probably confuse a lot of people.

should we require flake8?

Install flake8

might need sudo when installing globally

$ sudo pip install flake8

Set Up flake8 Hooks

add the hook to check style on ‘git commit’ (run in root of project)

$ flake8 --install-hook

setting the strict config means it will block the commit if there are errors

$ git config flake8.strict true

jquery not defined

Hi everyone,

I haven't done Flask web deployments before and I started using this code base with limited Flask knowledge. After working with the code base to get it to the point where I want to deploy it on for cloud testing, I found that the javascript functions were not working for the about page and the top right slider for the mobile view:

console_error

The only changes/differences between my local copy and the online deployment are that the online deployment has a different port number and is connected via upstream from a nginx web server. I enabled gzip javascript for nginx with these lines:

http {
...

    gzip on;
    gzip_disable "msie6";
    gzip_types application/x-javascript;

...
}

If you need any additional information feel free to email me.

Move Mailing to Sendgrid

Title says it all. Consistently plagued by gmail's security filters preventing us from sending emails.

Add auto-formatting to flask-base

From working on Go and working at Google (where most code is auto-formatted) I've noticed that there are immense benefits to auto-formatting code.

  1. Code style and conformation to standards, like pep8, are ensured.
  2. Writing code is faster.
  3. Less cognitive load, it's one less thing to worry about.
  4. No arguments about style.
  5. If all of our python code is formatted the same, getting up to speed with code you didn't write will take less effort.
  6. Diffs show actual code, not 'diff noise' where someone adds a space or changes formatting.

Add password requirements

@aharelick said "Agree with max and the suggestions from owasp say we should make the minimum 8 characters. They also say that the recommendations may be out of date, but I think it's a good place to start. Also, we should probably add the validator to RegistrationForm and ResetPasswordForm and ChangePasswordForm."

RQ multiple workers with variable lifetimes.

I want to setup plenty of tasks to be delegated to workers on a queue -or possibly multiple queues. Each of these workers will need to have longer than the default 180 seconds.

I tried looking around online to see how to set this up with flask without much luck so I was wondering if there if someone here could explain to me how?

Right now I have the default 1 worker with 180 seconds lifespan before it gets terminated.

Give flask-base a real task queue

Right now, async code (e.g. send_email) is implemented with threads). We should have a worker process always running which completes tasks from the task queue instead. One problem with the current approach is that clients of the send_email function do not know that it is asynchronous unless they read the implementation. I would much prefer something like this (with rq)

result = task_queue.enqueue(send_email, <args>)

Port to Flask 0.12

Not only is the getting closer to the fabled flask 1.0, but you could drop the Flask-Script dependency for example

account.register gets wrong url_for server address

After deploying the code base to an EC2 instance I have an email generation problem where the confirm_link = url_for('account.confirm', token=token, _external=True) is creating a url of:

127.0.0.1:8000/account/confirm-account/

I tried setting the app.config['SERVER_NAME'] to the name of my server as seen here:

http://stackoverflow.com/questions/12162634/where-do-i-define-the-domain-to-be-used-by-url-for-in-flask

However, that didn't work. I did manage to get it to work though by turning off the _external=True flag and manually setting the name of the server as a variable. Just wondering if there was a better way to go about this (maybe defining the server name in Local?) or if I'm missing something to how this whole flask stack works.

RQ task on startup

I'm testing to see how to get a RQ task to run on server startup similar to the email task. I assume that I'm supposed to have the task enqueued inside the context of the application. I tried running it inside the app/init.py python file but I got an exception:

raise RuntimeError('working outside of application context')
RuntimeError: working outside of application context

Where should I put the code for running the task?

Semantic-ui width always fits width of screen

I'm new to semantic-ui and when I try to build a table of information from the database it works but the width of the table is always the width of the browser. I tried various settings such as setting the 'width' variable or setting class as "ui celled striped table ten wide". Even placing it in a container and doing the same had no effect. What can I do to customize the width of a table/container in a view?

Requirment installation error. Error: pg_config executable not found

  Using cached psycopg2-2.6.1.tar.gz
    Complete output from command python setup.py egg_info:
    running egg_info
    creating pip-egg-info/psycopg2.egg-info
    writing pip-egg-info/psycopg2.egg-info/PKG-INFO
    writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
    writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
    writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'
    Error: pg_config executable not found.

    Please add the directory containing pg_config to the PATH
    or specify the full executable path with the option:

        python setup.py build_ext --pg-config /path/to/pg_config build ...

    or with the pg_config option in 'setup.cfg'.

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-U3FPuB/psycopg2/```

Environment:
(flask_base) adop@adop:~/flask-base$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.1 LTS
Release:        16.04
Codename:       xenial

(flask_base) adop@adop:~/flask-base$ python --version
Python 2.7.12

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.