implement registration, login, starting wallet dashboard
parent
561d0155f3
commit
59ea26b8f1
@ -1,3 +1,3 @@
|
||||
from .account import account_bp
|
||||
from .wallet import wallet_bp
|
||||
from .authentication import authentication_bp
|
||||
from .meta import meta_bp
|
||||
|
@ -1,28 +0,0 @@
|
||||
from flask import request, render_template, session
|
||||
from flask import redirect, url_for, current_app
|
||||
from wowstash.blueprints.account import account_bp
|
||||
|
||||
|
||||
@account_bp.route("/account")
|
||||
def overview():
|
||||
if session.get("public_address"):
|
||||
return render_template("account.html",
|
||||
session_data=session,
|
||||
h=daemon.get_height(),
|
||||
wallet=wallet)
|
||||
else:
|
||||
return redirect(url_for("index"))
|
||||
|
||||
@account_bp.route("/account/wallet")
|
||||
def connect_wallet():
|
||||
if session.get("public_address"):
|
||||
wallet.init(host=current_app.config['DAEMON_HOST'],
|
||||
port=current_app.config['DAEMON_PORT'],
|
||||
public_view_key=session['public_view_key'],
|
||||
wallet_password=session['wallet_password'],
|
||||
mnemonic_seed=session['seed'],
|
||||
restore_height=daemon.get_height(),
|
||||
path=current_app.config['BINARY_PATH'])
|
||||
return redirect(url_for("account.overview"))
|
||||
else:
|
||||
return redirect(url_for("index"))
|
@ -1,27 +1,79 @@
|
||||
from flask import request, render_template, session, redirect, url_for
|
||||
from flask import request, render_template, session, redirect, url_for, flash
|
||||
from flask_login import login_user, logout_user, current_user
|
||||
from wowstash.blueprints.authentication import authentication_bp
|
||||
from wowstash.forms import Register
|
||||
from wowstash.forms import Register, Login
|
||||
from wowstash.models import User
|
||||
from wowstash.library.jsonrpc import wallet
|
||||
from wowstash.factory import db, bcrypt
|
||||
|
||||
|
||||
@authentication_bp.route("/register", methods=["GET", "POST"])
|
||||
def register():
|
||||
form = Register()
|
||||
if current_user.is_authenticated:
|
||||
flash('Already registered and authenticated.')
|
||||
return redirect(url_for('wallet.dashboard'))
|
||||
|
||||
if form.validate_on_submit():
|
||||
print(dir(User))
|
||||
# user = User.query
|
||||
user = User.objects.filter(email=form.email.data)
|
||||
print(user)
|
||||
return "ok"
|
||||
else:
|
||||
print(form)
|
||||
# Check if Wownero wallet is available
|
||||
if wallet.connected is False:
|
||||
flash('Wallet RPC interface is unavailable at this time. Try again later.')
|
||||
return redirect(url_for('authentication.register'))
|
||||
|
||||
# Check if email already exists
|
||||
user = User.query.filter_by(email=form.email.data).first()
|
||||
if user:
|
||||
flash('This email is already registered.')
|
||||
return redirect(url_for('authentication.login'))
|
||||
|
||||
# Create new subaddress
|
||||
subaddress = wallet.new_address(label=form.email.data)
|
||||
|
||||
# Save new user
|
||||
user = User(
|
||||
email=form.email.data,
|
||||
password=bcrypt.generate_password_hash(form.password.data).decode('utf8'),
|
||||
subaddress_index=subaddress[0]
|
||||
)
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
|
||||
# Login user and redirect to wallet page
|
||||
login_user(user)
|
||||
return redirect(url_for('wallet.dashboard'))
|
||||
|
||||
return render_template("authentication/register.html", form=form)
|
||||
|
||||
@authentication_bp.route("/login", methods=["GET", "POST"])
|
||||
def login():
|
||||
return render_template("authentication/login.html")
|
||||
form = Login()
|
||||
if current_user.is_authenticated:
|
||||
flash('Already registered and authenticated.')
|
||||
return redirect(url_for('wallet.dashboard'))
|
||||
|
||||
if form.validate_on_submit():
|
||||
# Check if user doesn't exist
|
||||
user = User.query.filter_by(email=form.email.data).first()
|
||||
if not user:
|
||||
flash('Invalid username or password.')
|
||||
return redirect(url_for('authentication.login'))
|
||||
|
||||
# Check if password is correct
|
||||
password_matches = bcrypt.check_password_hash(
|
||||
user.password,
|
||||
form.password.data
|
||||
)
|
||||
if not password_matches:
|
||||
flash('Invalid username or password.')
|
||||
return redirect(url_for('authentication.login'))
|
||||
|
||||
# Login user and redirect to wallet page
|
||||
login_user(user)
|
||||
return redirect(url_for('wallet.dashboard'))
|
||||
|
||||
return render_template("authentication/login.html", form=form)
|
||||
|
||||
@authentication_bp.route("/logout")
|
||||
def logout():
|
||||
session.clear()
|
||||
return redirect(url_for('index'))
|
||||
logout_user()
|
||||
return redirect(url_for('meta.index'))
|
||||
|
@ -1,5 +1,5 @@
|
||||
from flask import Blueprint
|
||||
|
||||
account_bp = Blueprint("account", __name__)
|
||||
wallet_bp = Blueprint("wallet", __name__)
|
||||
|
||||
from . import routes
|
@ -0,0 +1,21 @@
|
||||
from flask import request, render_template, session, redirect, url_for, current_app
|
||||
from flask_login import login_required, current_user
|
||||
from wowstash.blueprints.wallet import wallet_bp
|
||||
from wowstash.library.jsonrpc import wallet, daemon
|
||||
from wowstash.factory import login_manager
|
||||
from wowstash.models import User
|
||||
|
||||
|
||||
@wallet_bp.route("/wallet/dashboard")
|
||||
@login_required
|
||||
def dashboard():
|
||||
user = User.query.get(current_user.id)
|
||||
wallet_height = wallet.height()['height']
|
||||
daemon_height = daemon.height()['height']
|
||||
subaddress = wallet.get_address(0, user.subaddress_index)['addresses'][0]['address']
|
||||
return render_template(
|
||||
"account/dashboard.html",
|
||||
wallet_height=wallet_height,
|
||||
daemon=daemon_height,
|
||||
subaddress=subaddress
|
||||
)
|
@ -1,8 +1,15 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField
|
||||
from wtforms import StringField, BooleanField
|
||||
from wtforms.validators import DataRequired
|
||||
|
||||
|
||||
class Register(FlaskForm):
|
||||
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"})
|
||||
faq_reviewed = BooleanField('FAQ Reviewed:', validators=[DataRequired()], render_kw={"class": "form-control-span"})
|
||||
terms_reviewed = BooleanField('Terms Reviewed:', validators=[DataRequired()], render_kw={"class": "form-control-span"})
|
||||
privacy_reviewed = BooleanField('Privacy Policy Reviewed:', validators=[DataRequired()], render_kw={"class": "form-control-span"})
|
||||
|
||||
class Login(FlaskForm):
|
||||
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"})
|
||||
|
Loading…
Reference in New Issue