get auth/logins working with xmr signing auth

revamp
lza_menace 2 years ago
parent 6dc1b351b8
commit 6681315128

@ -21,11 +21,16 @@ def check_tx_key(tx_id, tx_key, wallet_address):
def make_wallet_rpc(method, data={}): def make_wallet_rpc(method, data={}):
try: try:
w = Wallet(port=config.XMR_WALLET_RPC_PORT, user=config.XMR_WALLET_RPC_USER, password=config.XMR_WALLET_RPC_PASS) w = Wallet(
port=config.XMR_WALLET_RPC_PORT,
user=config.XMR_WALLET_RPC_USER,
password=config.XMR_WALLET_RPC_PASS,
timeout=5
)
res = w._backend.raw_request(method, data) res = w._backend.raw_request(method, data)
return res return res
except: except Exception as e:
raise Exception('there was a problem i dont feel like writing good code for right now') raise Exception('there was a problem i dont feel like writing good code for right now', e)
class EnumArrayField(pwpg.ArrayField): class EnumArrayField(pwpg.ArrayField):
@ -54,6 +59,9 @@ class EnumArrayField(pwpg.ArrayField):
"""python -> database""" """python -> database"""
if not isinstance(value, (tuple, list)): if not isinstance(value, (tuple, list)):
raise TypeError("Wrong type, must be a list of enums") raise TypeError("Wrong type, must be a list of enums")
# if isinstance(value, tuple):
# value = value[0]
data = [] data = []
for enum in value: for enum in value:
if not isinstance(enum, self.enum_class): if not isinstance(enum, self.enum_class):

@ -66,7 +66,6 @@ class User(pw.Model):
def generate_challenge(self): def generate_challenge(self):
self.challenge = token_urlsafe(24) self.challenge = token_urlsafe(24)
self.save() self.save()
return self.challenge
class Meta: class Meta:
database = db database = db

@ -73,18 +73,19 @@ async def challenge(handle):
'address': user.wallet_address, 'address': user.wallet_address,
'signature': form.signature.data 'signature': form.signature.data
} }
res = make_wallet_rpc('verify', data) try:
print(res) res = make_wallet_rpc('verify', data)
from quart import jsonify if res['good']:
return jsonify(res) user.generate_challenge()
# # Check if user doesn't exist login_user(user)
# user = User.select().where( await flash('Successful login!')
# User.handle == form.handle.data return redirect(url_for('main.index'))
# ).first() else:
# if not user: await flash('Invalid signature. Try again.')
# await flash('That handle does not exist.') return redirect(url_for('auth.challenge', handle=handle))
# return redirect(url_for('auth.login')) except Exception as e:
return redirect(url_for('main.index')) await flash(f'Issue with checking the signature provided: {e}')
return redirect(url_for('auth.challenge', handle=handle))
return await render_template( return await render_template(
'auth/challenge.html', 'auth/challenge.html',
@ -99,29 +100,3 @@ async def logout():
else: else:
await flash('Not authenticated!') await flash('Not authenticated!')
return redirect(url_for('main.index')) return redirect(url_for('main.index'))
# @auth_bp.route("/reset/<string:hash>", methods=["GET", "POST"])
# def reset(hash):
# hash = PasswordReset.query.filter(PasswordReset.hash==hash).first()
# if not hash:
# flash('Invalid password reset hash')
# return redirect(url_for('auth.login'))
#
# if hash.hours_elapsed() > hash.expiration_hours or hash.expired:
# flash('Reset hash has expired')
# return redirect(url_for('auth.login'))
#
# form = ResetPassword()
# if form.validate_on_submit():
# try:
# user = User.query.get(hash.user)
# user.password = bcrypt.generate_password_hash(form.password.data).decode('utf8')
# hash.expired = True
# db.session.commit()
# flash('Password reset successfully')
# return redirect(url_for('auth.login'))
# except:
# flash('Error resetting password')
# return redirect(url_for('auth.login'))
#
# return render_template('auth/reset.html', form=form)

@ -35,7 +35,6 @@
<input type="submit" value="Login" class="btn btn-link btn-outline btn-xl"> <input type="submit" value="Login" 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>
</div> </div>
</section> </section>

@ -32,7 +32,6 @@
<input type="submit" value="Login" class="btn btn-link btn-outline btn-xl"> <input type="submit" value="Login" 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>
</div> </div>
</section> </section>

@ -32,7 +32,6 @@
<input type="submit" value="Register" class="btn btn-link btn-outline btn-xl"> <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>
</div> </div>
</section> </section>

@ -1,3 +1,14 @@
<hr>
<section id="banner">
<div class="content">
<header>
<p>This is a simple prototype and is under heavy development.</p>
</header>
<span class="image"><img src="/static/images/monero-logo.png" width=150px></span>
</div>
</section>
<footer id="footer"> <footer id="footer">
<ul class="icons"> <ul class="icons">
</ul> </ul>

@ -7,8 +7,8 @@
<li><a href="{{ url_for('auth.logout') }}">Logout</a></li> <li><a href="{{ url_for('auth.logout') }}">Logout</a></li>
</ul> </ul>
</nav> </nav>
<p>Authenticated: {{ current_user.is_authenticated }}</p>
{% if current_user.is_authenticated %} {% if current_user.is_authenticated %}
<p>Authenticated: {{ current_user.is_authenticated }}</p>
<p>Username: {{ current_user.handle }}</p> <p>Username: {{ current_user.handle }}</p>
<p>Email: {{ current_user.email }}</p> <p>Email: {{ current_user.email }}</p>
<p>Wallet Address: {{ current_user.wallet_address }}</p> <p>Wallet Address: {{ current_user.wallet_address }}</p>
@ -18,14 +18,19 @@
<hr> <hr>
<script src="/static/js/noty.js"></script> <script src="/static/js/noty.js"></script>
{% with messages = get_flashed_messages() %} {% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %} {% if messages %}
<script type="text/javascript"> <script type="text/javascript">
{% for message in messages %} {% for category, message in messages %}
{% if category == "message" %}
{% set _c = "info" %}
{% else %}
{% set _c = category %}
{% endif %}
new Noty({ new Noty({
type: 'error', type: '{{ _c }}',
theme: 'relax', theme: 'relax',
layout: 'topCenter', layout: 'topRight',
text: '{{ message }}', text: '{{ message }}',
timeout: 4500 timeout: 4500
}).show(); }).show();

@ -27,17 +27,6 @@
<p>{{ s.id }}</p> <p>{{ s.id }}</p>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% else %}
<section id="banner">
<div class="content">
<header>
<p>This is a simple prototype and is under heavy development.</p>
</header>
<span class="image"><img src="/static/images/monero-logo.png" width=150px></span>
</div>
</section>
{% endif %} {% endif %}
{% include 'includes/footer.html' %} {% include 'includes/footer.html' %}

Loading…
Cancel
Save