Giter Site home page Giter Site logo

realpython / flask-registration Goto Github PK

View Code? Open in Web Editor NEW
102.0 9.0 41.0 33 KB

Home Page: https://realpython.com/blog/python/handling-email-confirmation-in-flask/

License: MIT License

Python 77.17% CSS 0.12% JavaScript 0.05% HTML 21.63% Shell 1.03%

flask-registration's Introduction

Flask Registration

Build Status

Starter app for managing users - login/logout, registration, and email confirmation.

Blog posts:

QuickStart

Set Environment Variables

Development Example (with Debug Mail):

$ export APP_SETTINGS="project.config.DevelopmentConfig"
$ export APP_MAIL_SERVER=debugmail.io
$ export APP_MAIL_PORT=25
$ export APP_MAIL_USE_TLS=true
$ export APP_MAIL_USE_SSL=false
$ export APP_MAIL_USERNAME=ADDYOUROWN
$ export APP_MAIL_PASSWORD=ADDYOUROWN

Production Example:

$ export APP_SETTINGS="project.config.ProductionConfig"
$ export APP_MAIL_SERVER=ADDYOUROWN
$ export APP_MAIL_PORT=ADDYOUROWN
$ export APP_MAIL_USE_TLS=ADDYOUROWN
$ export APP_MAIL_USE_SSL=ADDYOUROWN
$ export APP_MAIL_USERNAME=ADDYOUROWN
$ export APP_MAIL_PASSWORD=ADDYOUROWN

Update Settings in Production

  1. SECRET_KEY
  2. SQLALCHEMY_DATABASE_URI

Create DB

Run:

$ sh create.sh

Or:

$ python manage.py create_db
$ python manage.py db init
$ python manage.py db migrate
$ python manage.py create_admin

Want to clean the environment? Run:

sh clean.sh

Run

$ python manage.py runserver

Testing

Without coverage:

$ python manage.py test

With coverage:

$ python manage.py cov

flask-registration's People

Contributors

cristiancantoro avatar mjhea0 avatar

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

flask-registration's Issues

remember me functionality not work

I have implement your code in my app but remember me functionality not work. Can you give me any suggestion how to implement it. I have used remember=True in login_user method (Ex. login_user(user,remember=True)).

error occurs when registering.

hello, when I register, it shows error:

OperationalError: (sqlite3.OperationalError) no such table: users [SQL: u'SELECT users.id AS users_id, users.email AS users_email, users.password AS users_password, users.registered_on AS users_registered_on, users.admin AS users_admin, users.confirmed AS users_confirmed, users.confirmed_on AS users_confirmed_on, users.password_reset_token AS users_password_reset_token \nFROM users \nWHERE users.email = ?\n LIMIT ? OFFSET ?'] [parameters: (u'[email protected]', 1, 0)]

why it shows this error?
can you give some advises?

AttributeError: 'bool' object has no attribute '__call__'

hello,after I python manage.py runserver, I get one error when I visit localhost:5000:

[2017-07-15 16:39:05,570] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "/home/ztgong/.virtualenvs/flask-registration/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/ztgong/.virtualenvs/flask-registration/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/ztgong/.virtualenvs/flask-registration/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/ztgong/.virtualenvs/flask-registration/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/ztgong/.virtualenvs/flask-registration/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/ztgong/work/web/flask-registration/project/main/views.py", line 26, in home
    return render_template('main/index.html', current_user=current_user)
  File "/home/ztgong/.virtualenvs/flask-registration/lib/python2.7/site-packages/flask/templating.py", line 134, in render_template
    context, ctx.app)
  File "/home/ztgong/.virtualenvs/flask-registration/lib/python2.7/site-packages/flask/templating.py", line 116, in _render
    rv = template.render(context)
  File "/home/ztgong/.virtualenvs/flask-registration/lib/python2.7/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/home/ztgong/.virtualenvs/flask-registration/lib/python2.7/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/ztgong/work/web/flask-registration/project/templates/main/index.html", line 1, in top-level template code
    {% extends "_base.html" %}
  File "/home/ztgong/work/web/flask-registration/project/templates/_base.html", line 17, in top-level template code
    {% include "navigation.html" %}
  File "/home/ztgong/work/web/flask-registration/project/templates/navigation.html", line 19, in top-level template code
    {% elif current_user.is_authenticated() %}
AttributeError: 'bool' object has no attribute '__call__'

how to fix it?
thank you very much~

url_for failure

Hi,
I've been trying to implement the "User Registration Email Confirmation" module in your project but i keep getting this error:
werkzeug.routing.BuildError: Could not build url for endpoint 'admin.confirm_email'. Did you forget to specify values ['token']?

Below are the functions:
`# Register
@admin.route('/register', methods=['GET', 'POST'])
def register__():
title = 'Register'
form = RegistrationForm(request.form)

if form.validate_on_submit():
    user = User(email=form.email__.data,
                password=form.password__.data,
                first_name=form.first_name__.data,
                last_name=form.last_name__.data,
                confirmed=False)

    db.session.add(user)
    db.session.commit()

    token__ = generate_confirmation_token(user.email)

    confirm_url = url_for('admin.confirm_email', token=token__, _external=True)
    html = render_template('activate.html',confirm_url=confirm_url)
    subject = 'Please confirm your email'
    send_email(user.email, subject, html)

    login_user(user)

    flash("Registration is Successful!\nA confirmation email has been sent via email","success")
    return redirect(url_for("admin.unconfirmed"))

return render_template('registration.html', form=form, title=title)

Email Confirmation

@admin.route('/confirm/')
@login_required
def confirm_email(token):
title='Email Confirmation'
if current_user.confirmed:
flash('Account already confirmed. Please login.', 'success')
return redirect(url_for('report.homepage'))

email = confirm_token(token)
user = User.query.filter_by(email=current_user.email).first_or_404()

if user.email == email:
    user.confirmed = True
    user.confirmed_on = datetime.datetime.now()
    db.session.add(user)
    db.session.commit()
    flash('You have confirmed your account. Thanks!', 'success')
else:
    flash('The confirmation link is invalid or has expired.', 'danger')
return redirect(url_for('report.homepage'))

`

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.