fix login_manager bug, use get_or_none

main
lza_menace 4 years ago
parent 4c17e2a5b0
commit 3d85028b29

@ -36,7 +36,7 @@ def create_app():
@login_manager.user_loader
def load_user(user_id):
from xmrbackers.models import User
user = User.get(user_id)
user = User.get_or_none(user_id)
return user
return app

@ -1,15 +1,9 @@
import quart.flask_patch
# import quart.flask_patch
from flask_wtf import FlaskForm
from wtforms import StringField, BooleanField
from wtforms import StringField
from wtforms.validators import DataRequired
class Login(FlaskForm):
class UserAuth(FlaskForm):
username = StringField('Username:', validators=[DataRequired()], render_kw={"placeholder": "Username", "class": "form-control", "type": "text"})
email = StringField('Email Address:', validators=[DataRequired()], render_kw={"placeholder": "Email", "class": "form-control", "type": "email"})
password = StringField('Password:', validators=[DataRequired()], render_kw={"placeholder": "Password", "class": "form-control", "type": "password"})
class Register(FlaskForm):
username = StringField('Username:', validators=[DataRequired()], render_kw={"placeholder": "Username", "class": "form-control", "type": "text"})
email = StringField('Email Address:', validators=[DataRequired()], render_kw={"placeholder": "Email", "class": "form-control", "type": "email"})
password = StringField('Password:', validators=[DataRequired()], render_kw={"placeholder": "Password", "class": "form-control", "type": "password"})

@ -17,8 +17,7 @@ class User(pw.Model):
register_date = pw.DateTimeField(default=datetime.now)
last_login_date = pw.DateTimeField(default=datetime.now)
username = pw.CharField(unique=True)
email = pw.CharField(unique=True)
password = pw.CharField(unique=True)
password = pw.CharField()
@property
def is_authenticated(self):
@ -48,6 +47,9 @@ class CreatorProfile(pw.Model):
create_date = pw.DateTimeField(default=datetime.now)
last_login_date = pw.DateTimeField(default=datetime.now)
wallet_address = pw.CharField(null=True)
website = pw.CharField(null=True)
twitter_handle = pw.CharField(null=True)
email = pw.CharField(unique=True, null=True)
bio = pw.CharField()
class Meta:
@ -58,6 +60,7 @@ class BackerProfile(pw.Model):
id = pw.AutoField()
register_date = pw.DateTimeField(default=datetime.now)
last_login_date = pw.DateTimeField(default=datetime.now)
email = pw.CharField(unique=True, null=True)
class Meta:
database = db

@ -4,7 +4,7 @@ from quart import flash, redirect, url_for
from flask_login import login_user, logout_user, current_user
from xmrbackers.factory import bcrypt
from xmrbackers.forms import Register, Login
from xmrbackers.forms import UserAuth
from xmrbackers.models import User
@ -12,23 +12,22 @@ bp = Blueprint('auth', 'auth')
@bp.route("/register", methods=["GET", "POST"])
async def register():
form = Register()
form = UserAuth()
if current_user.is_authenticated:
await flash('Already registered and authenticated.')
return redirect(url_for('meta.index'))
if form.validate_on_submit():
# Check if email already exists
# Check if username already exists
user = User.select().where(
User.email == form.email.data
User.username == form.username.data
).first()
if user:
await flash('This email is already registered.')
await flash('This username is already registered.')
return redirect(url_for('auth.login'))
# Save new user
user = User(
email=form.email.data,
username=form.username.data,
password=bcrypt.generate_password_hash(form.password.data).decode('utf8'),
)
@ -40,7 +39,7 @@ async def register():
@bp.route("/login", methods=["GET", "POST"])
async def login():
form = Login()
form = UserAuth()
if current_user.is_authenticated:
await flash('Already logged in.')
return redirect(url_for('meta.index'))
@ -48,7 +47,7 @@ async def login():
if form.validate_on_submit():
# Check if user doesn't exist
user = User.select().where(
User.email == form.email.data
User.username == form.username.data
).first()
if not user:
await flash('Invalid username or password.')

@ -34,7 +34,6 @@
</header>
<span class="image"><img src="/static/images/monero-logo.png" width=150px></span>
</div>
<a href="#swap" class="goto-next scrolly">Next</a>
</section>
{% include 'includes/footer.html' %}

@ -34,7 +34,6 @@
</header>
<span class="image"><img src="/static/images/monero-logo.png" width=150px></span>
</div>
<a href="#swap" class="goto-next scrolly">Next</a>
</section>
{% include 'includes/footer.html' %}

Loading…
Cancel
Save