fix bugs, fix auth logic

main
lza_menace 3 years ago
parent ddfb382e50
commit 0a3f190a85

@ -36,8 +36,8 @@ def create_app():
@login_manager.user_loader @login_manager.user_loader
def load_user(user_id): def load_user(user_id):
from xmrbackers.models import User from xmrbackers.models import User
user = User.query.get(user_id) user = User.get(user_id)
return user.id return user
return app return app
bcrypt = Bcrypt(create_app()) bcrypt = Bcrypt(create_app())

@ -4,7 +4,7 @@ from quart import flash, redirect, url_for
from flask_login import login_user, logout_user, current_user from flask_login import login_user, logout_user, current_user
from xmrbackers.factory import bcrypt from xmrbackers.factory import bcrypt
from xmrbackers.forms import Register from xmrbackers.forms import Register, Login
from xmrbackers.models import User from xmrbackers.models import User
@ -13,17 +13,18 @@ bp = Blueprint('auth', 'auth')
@bp.route("/register", methods=["GET", "POST"]) @bp.route("/register", methods=["GET", "POST"])
async def register(): async def register():
form = Register() form = Register()
# if current_user.is_authenticated: if current_user.is_authenticated:
# flash('Already registered and authenticated.') await flash('Already registered and authenticated.')
# return redirect(url_for('meta.index')) return redirect(url_for('meta.index'))
# return 'gotem'
if form.validate_on_submit(): if form.validate_on_submit():
# Check if email already exists # Check if email already exists
user = User.query.filter_by(email=form.email.data).first() user = User.select().where(
User.email == form.email.data
).first()
if user: if user:
flash('This email is already registered.') await flash('This email is already registered.')
# return redirect(url_for('auth.login')) return redirect(url_for('auth.login'))
return 'gotem'
# Save new user # Save new user
user = User( user = User(
@ -34,65 +35,47 @@ async def register():
user.save() user.save()
login_user(user) login_user(user)
return redirect(url_for('meta.index')) return redirect(url_for('meta.index'))
return await render_template("auth/register.html", form=form) return await render_template("auth/register.html", form=form)
#
# @auth_bp.route("/login", methods=["GET", "POST"]) @bp.route("/login", methods=["GET", "POST"])
# def login(): async def login():
# form = Login() form = Login()
# if current_user.is_authenticated: if current_user.is_authenticated:
# flash('Already registered and authenticated.') await flash('Already logged in.')
# return redirect(url_for('wallet.dashboard')) return redirect(url_for('meta.index'))
#
# if form.validate_on_submit(): if form.validate_on_submit():
# # Check if user doesn't exist # Check if user doesn't exist
# user = User.query.filter_by(email=form.email.data).first() user = User.select().where(
# if not user: User.email == form.email.data
# flash('Invalid username or password.') ).first()
# return redirect(url_for('auth.login')) if not user:
# await flash('Invalid username or password.')
# # Check if password is correct return redirect(url_for('auth.login'))
# password_matches = bcrypt.check_password_hash(
# user.password, # Check if password is correct
# form.password.data password_matches = bcrypt.check_password_hash(
# ) user.password,
# if not password_matches: form.password.data
# flash('Invalid username or password.') )
# return redirect(url_for('auth.login')) if not password_matches:
# await flash('Invalid username or password.')
# # Capture event, login user, and redirect to wallet page return redirect(url_for('auth.login'))
# capture_event(user.id, 'login')
# login_user(user) login_user(user)
# return redirect(url_for('wallet.dashboard')) return redirect(url_for('meta.index'))
#
# return render_template("auth/login.html", form=form) return await render_template("auth/login.html", form=form)
#
# @auth_bp.route("/logout") @bp.route("/logout")
# def logout(): async def logout():
# if current_user.is_authenticated: if current_user.is_authenticated:
# docker.stop_container(current_user.wallet_container) logout_user()
# capture_event(current_user.id, 'stop_container') else:
# current_user.clear_wallet_data() await flash('Not authenticated!')
# capture_event(current_user.id, 'logout') return redirect(url_for('meta.index'))
# logout_user()
# return redirect(url_for('meta.index'))
#
# @auth_bp.route("/delete", methods=["GET", "POST"])
# @login_required
# def delete():
# form = Delete()
# if form.validate_on_submit():
# docker.stop_container(current_user.wallet_container)
# capture_event(current_user.id, 'stop_container')
# sleep(1)
# docker.delete_wallet_data(current_user.id)
# capture_event(current_user.id, 'delete_wallet')
# current_user.clear_wallet_data(reset_password=True, reset_wallet=True)
# flash('Successfully deleted wallet data')
# return redirect(url_for('wallet.setup'))
# else:
# flash('Please confirm deletion of the account')
# return redirect(url_for('wallet.dashboard'))
#
# @auth_bp.route("/reset/<string:hash>", methods=["GET", "POST"]) # @auth_bp.route("/reset/<string:hash>", methods=["GET", "POST"])
# def reset(hash): # def reset(hash):
# hash = PasswordReset.query.filter(PasswordReset.hash==hash).first() # hash = PasswordReset.query.filter(PasswordReset.hash==hash).first()

@ -0,0 +1,46 @@
.noty_theme__relax.noty_bar {
margin: 4px 0;
overflow: hidden;
border-radius: 2px;
position: relative; }
.noty_theme__relax.noty_bar .noty_body {
padding: 10px; }
.noty_theme__relax.noty_bar .noty_buttons {
border-top: 1px solid #e7e7e7;
padding: 5px 10px; }
.noty_theme__relax.noty_type__alert,
.noty_theme__relax.noty_type__notification {
background-color: #fff;
border: 1px solid #dedede;
color: #444; }
.noty_theme__relax.noty_type__warning {
background-color: #FFEAA8;
border: 1px solid #FFC237;
color: #826200; }
.noty_theme__relax.noty_type__warning .noty_buttons {
border-color: #dfaa30; }
.noty_theme__relax.noty_type__error {
background-color: #FF8181;
border: 1px solid #e25353;
color: #FFF; }
.noty_theme__relax.noty_type__error .noty_buttons {
border-color: darkred; }
.noty_theme__relax.noty_type__info,
.noty_theme__relax.noty_type__information {
background-color: #78C5E7;
border: 1px solid #3badd6;
color: #FFF; }
.noty_theme__relax.noty_type__info .noty_buttons,
.noty_theme__relax.noty_type__information .noty_buttons {
border-color: #0B90C4; }
.noty_theme__relax.noty_type__success {
background-color: #BCF5BC;
border: 1px solid #7cdd77;
color: darkgreen; }
.noty_theme__relax.noty_type__success .noty_buttons {
border-color: #50C24E; }

@ -0,0 +1,222 @@
.noty_layout_mixin, #noty_layout__top, #noty_layout__topLeft, #noty_layout__topCenter, #noty_layout__topRight, #noty_layout__bottom, #noty_layout__bottomLeft, #noty_layout__bottomCenter, #noty_layout__bottomRight, #noty_layout__center, #noty_layout__centerLeft, #noty_layout__centerRight {
position: fixed;
margin: 0;
padding: 0;
z-index: 9999999;
-webkit-transform: translateZ(0) scale(1, 1);
transform: translateZ(0) scale(1, 1);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-webkit-font-smoothing: subpixel-antialiased;
filter: blur(0);
-webkit-filter: blur(0);
max-width: 90%; }
#noty_layout__top {
top: 0;
left: 5%;
width: 90%; }
#noty_layout__topLeft {
top: 20px;
left: 20px;
width: 325px; }
#noty_layout__topCenter {
top: 5%;
left: 50%;
width: 325px;
-webkit-transform: translate(-webkit-calc(-50% - .5px)) translateZ(0) scale(1, 1);
transform: translate(calc(-50% - .5px)) translateZ(0) scale(1, 1); }
#noty_layout__topRight {
top: 20px;
right: 20px;
width: 325px; }
#noty_layout__bottom {
bottom: 0;
left: 5%;
width: 90%; }
#noty_layout__bottomLeft {
bottom: 20px;
left: 20px;
width: 325px; }
#noty_layout__bottomCenter {
bottom: 5%;
left: 50%;
width: 325px;
-webkit-transform: translate(-webkit-calc(-50% - .5px)) translateZ(0) scale(1, 1);
transform: translate(calc(-50% - .5px)) translateZ(0) scale(1, 1); }
#noty_layout__bottomRight {
bottom: 20px;
right: 20px;
width: 325px; }
#noty_layout__center {
top: 50%;
left: 50%;
width: 325px;
-webkit-transform: translate(-webkit-calc(-50% - .5px), -webkit-calc(-50% - .5px)) translateZ(0) scale(1, 1);
transform: translate(calc(-50% - .5px), calc(-50% - .5px)) translateZ(0) scale(1, 1); }
#noty_layout__centerLeft {
top: 50%;
left: 20px;
width: 325px;
-webkit-transform: translate(0, -webkit-calc(-50% - .5px)) translateZ(0) scale(1, 1);
transform: translate(0, calc(-50% - .5px)) translateZ(0) scale(1, 1); }
#noty_layout__centerRight {
top: 50%;
right: 20px;
width: 325px;
-webkit-transform: translate(0, -webkit-calc(-50% - .5px)) translateZ(0) scale(1, 1);
transform: translate(0, calc(-50% - .5px)) translateZ(0) scale(1, 1); }
.noty_progressbar {
display: none; }
.noty_has_timeout.noty_has_progressbar .noty_progressbar {
display: block;
position: absolute;
left: 0;
bottom: 0;
height: 3px;
width: 100%;
background-color: #646464;
opacity: 0.2;
filter: alpha(opacity=10); }
.noty_bar {
-webkit-backface-visibility: hidden;
-webkit-transform: translate(0, 0) translateZ(0) scale(1, 1);
-ms-transform: translate(0, 0) scale(1, 1);
transform: translate(0, 0) scale(1, 1);
-webkit-font-smoothing: subpixel-antialiased;
overflow: hidden; }
.noty_effects_open {
opacity: 0;
-webkit-transform: translate(50%);
-ms-transform: translate(50%);
transform: translate(50%);
-webkit-animation: noty_anim_in 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
animation: noty_anim_in 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards; }
.noty_effects_close {
-webkit-animation: noty_anim_out 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
animation: noty_anim_out 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards; }
.noty_fix_effects_height {
-webkit-animation: noty_anim_height 75ms ease-out;
animation: noty_anim_height 75ms ease-out; }
.noty_close_with_click {
cursor: pointer; }
.noty_close_button {
position: absolute;
top: 2px;
right: 2px;
font-weight: bold;
width: 20px;
height: 20px;
text-align: center;
line-height: 20px;
background-color: rgba(0, 0, 0, 0.05);
border-radius: 2px;
cursor: pointer;
-webkit-transition: all .2s ease-out;
transition: all .2s ease-out; }
.noty_close_button:hover {
background-color: rgba(0, 0, 0, 0.1); }
.noty_modal {
position: fixed;
width: 100%;
height: 100%;
background-color: #000;
z-index: 10000;
opacity: .3;
left: 0;
top: 0; }
.noty_modal.noty_modal_open {
opacity: 0;
-webkit-animation: noty_modal_in .3s ease-out;
animation: noty_modal_in .3s ease-out; }
.noty_modal.noty_modal_close {
-webkit-animation: noty_modal_out .3s ease-out;
animation: noty_modal_out .3s ease-out;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards; }
@-webkit-keyframes noty_modal_in {
100% {
opacity: .3; } }
@keyframes noty_modal_in {
100% {
opacity: .3; } }
@-webkit-keyframes noty_modal_out {
100% {
opacity: 0; } }
@keyframes noty_modal_out {
100% {
opacity: 0; } }
@keyframes noty_modal_out {
100% {
opacity: 0; } }
@-webkit-keyframes noty_anim_in {
100% {
-webkit-transform: translate(0);
transform: translate(0);
opacity: 1; } }
@keyframes noty_anim_in {
100% {
-webkit-transform: translate(0);
transform: translate(0);
opacity: 1; } }
@-webkit-keyframes noty_anim_out {
100% {
-webkit-transform: translate(50%);
transform: translate(50%);
opacity: 0; } }
@keyframes noty_anim_out {
100% {
-webkit-transform: translate(50%);
transform: translate(50%);
opacity: 0; } }
@-webkit-keyframes noty_anim_height {
100% {
height: 0; } }
@keyframes noty_anim_height {
100% {
height: 0; } }
/*# sourceMappingURL=noty.css.map*/
/* Custom */
.noty_body {
text-align: center;
}

@ -0,0 +1 @@
{"version":3,"sources":[],"names":[],"mappings":"","file":"noty.css","sourceRoot":""}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,47 @@
<!DOCTYPE HTML>
<html>
{% include 'includes/head.html' %}
<body class="is-preload landing">
<div id="page-wrapper">
{% include 'includes/header.html' %}
<section id="banner">
<div class="content">
<header>
<h2>Login</h2>
<form method="POST" action="{{ url_for('auth.login') }}">
{% for f in form %}
{% if f.name == 'csrf_token' %}
{{ f }}
{% else %}
<div class="form-group">
{{ f.label }}
{{ f }}
</div>
{% endif %}
{% endfor %}
<ul>
{% for field, errors in form.errors.items() %}
<li>{{ form[field].label }}: {{ ', '.join(errors) }}</li>
{% endfor %}
</ul>
<input type="submit" value="Login" class="btn btn-link btn-outline btn-xl">
</form>
</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' %}
</div>
{% include 'includes/scripts.html' %}
</body>
</html>

@ -6,15 +6,30 @@
<body class="is-preload landing"> <body class="is-preload landing">
<div id="page-wrapper"> <div id="page-wrapper">
{% include 'includes/header.html' %}
<section id="banner"> <section id="banner">
<div class="content"> <div class="content">
<header> <header>
<h2>Register</h2> <h2>Register</h2>
<p>Authenticated: {{ current_user.is_authenticated }}</p> <form method="POST" action="{{ url_for('auth.register') }}">
<form>
{{ form.username }} {% for f in form %}
{{ form.password }} {% if f.name == 'csrf_token' %}
{{ form.email }} {{ f }}
{% else %}
<div class="form-group">
{{ f.label }}
{{ f }}
</div>
{% endif %}
{% endfor %}
<ul>
{% for field, errors in form.errors.items() %}
<li>{{ form[field].label }}: {{ ', '.join(errors) }}</li>
{% endfor %}
</ul>
<input type="submit" value="Register" class="btn btn-link btn-outline btn-xl">
</form> </form>
</header> </header>
<span class="image"><img src="/static/images/monero-logo.png" width=150px></span> <span class="image"><img src="/static/images/monero-logo.png" width=150px></span>

@ -17,4 +17,6 @@
<meta name="twitter:image" content=""> <meta name="twitter:image" content="">
<meta name="keywords" content="Wownero, Monero, crypto, swap"> <meta name="keywords" content="Wownero, Monero, crypto, swap">
<link rel="stylesheet" href="/static/css/main.css" /> <link rel="stylesheet" href="/static/css/main.css" />
<link rel="stylesheet" href="/static/css/noty.css">
<link rel="stylesheet" href="/static/css/noty-relax.css">
</head> </head>

@ -2,8 +2,27 @@
<h1 id="logo"><a href="/">{{ config.SITE_NAME }}</a></h1> <h1 id="logo"><a href="/">{{ config.SITE_NAME }}</a></h1>
<nav id="nav"> <nav id="nav">
<ul> <ul>
<li><a href="/">Home</a></li> <li><a href="{{ url_for('auth.login') }}">Login</a></li>
<li><a href="/#search" class="button primary">Search</a></li> <li><a href="{{ url_for('auth.register') }}">Register</a></li>
<li><a href="{{ url_for('auth.logout') }}">Logout</a></li>
</ul> </ul>
</nav> </nav>
<p>Authenticated: {{ current_user.is_authenticated }}</p>
</header> </header>
<script src="/static/js/noty.js"></script>
{% with messages = get_flashed_messages() %}
{% if messages %}
<script type="text/javascript">
{% for message in messages %}
new Noty({
type: 'error',
theme: 'relax',
layout: 'topCenter',
text: '{{ message }}',
timeout: 4500
}).show();
{% endfor %}
</script>
{% endif %}
{% endwith %}

@ -1,9 +1 @@
<script src="/static/js/main.js"></script> <script src="/static/js/main.js"></script>
{% with messages = get_flashed_messages() %}
{% if messages %}
{% for message in messages %}
<p>{{ message }}</p>
{% endfor %}
{% endif %}
{% endwith %}

@ -6,24 +6,15 @@
<body class="is-preload landing"> <body class="is-preload landing">
<div id="page-wrapper"> <div id="page-wrapper">
<header id="header"> {% include 'includes/header.html' %}
<h1 id="logo"><a href="/">MyThing sample app</a></h1>
<nav id="nav">
<ul>
<li><a href="/register" class="button primary">Register</a></li>
</ul>
</nav>
</header>
<section id="banner"> <section id="banner">
<div class="content"> <div class="content">
<header> <header>
<h2>MyThing</h2> <p>This is a simple prototype and is under heavy development.</p>
<p>This is a sample app.</p>
</header> </header>
<span class="image"><img src="/static/images/monero-logo.png" width=150px></span> <span class="image"><img src="/static/images/monero-logo.png" width=150px></span>
</div> </div>
<a href="#swap" class="goto-next scrolly">Next</a>
</section> </section>
{% include 'includes/footer.html' %} {% include 'includes/footer.html' %}

Loading…
Cancel
Save