The ability to remove address and reduce min. search length to 1 (thanks keycloak!)

min-len-1-and-remove-addy
dsc 2 years ago
parent 5fc91af0a4
commit 6d86bf77e7

@ -22,10 +22,10 @@ class User(pw.Model):
@staticmethod
async def search(needle) -> List['User']:
if not needle:
raise Exception("need search term")
needle = needle.replace("*", "")
needle = needle.lower()
if len(needle) <= 1:
raise Exception("need longer search term")
return User.select().where(
User.address.is_null(False),

@ -34,7 +34,6 @@ async def dashboard():
@bp_routes.post("/dashboard/address")
@login_required
async def dashboard_address_post():
# get FORM POST value 'address'
form = await request.form
address = form.get('address')
if not bool(re.match(r'^(WW)\\d[0-9A-Za-z]{94}$', address)):
@ -50,13 +49,21 @@ async def dashboard_address_post():
return await render_template('dashboard.html')
@bp_routes.post("/dashboard/address/delete")
@login_required
async def dashboard_address_delete():
from yellow.models import User
user = User.select().filter(User.id == session['user']['id']).get()
user.address = None
user.save()
session['user'] = user.to_json()
return redirect(url_for("bp_routes.dashboard"))
@bp_routes.route("/search")
async def search():
needle = request.args.get('username')
if needle:
if len(needle) <= 1:
raise Exception("Search term needs to be longer")
users = [u for u in await User.search(needle)]
if users:
return await render_template('search_results.html', users=users)
@ -73,7 +80,7 @@ async def search():
@bp_routes.route("/user/<path:name>")
async def user_page(name: str):
if not name or len(name) <= 1:
if not name:
raise Exception("invalid name")
name = name.lower()

@ -5,7 +5,7 @@
</div>
<div id="main">
<article>
<article style="min-width: 620px">
<Header>Welcome back <em>{{user.username}}</em>!</Header>
Current <u>WOW address</u>: <label>
{% if user.address %}
@ -18,7 +18,10 @@
Change <u>WOW address</u>:
<form action="{{ url_for('bp_routes.dashboard_address_post') }}" method="POST">
<input type="text" name="address">
<button data-tooltip="Be sure it's correct">Submit</button>
<button data-tooltip="Make sure it is correct!">Submit</button>
</form>
<form action="{{ url_for('bp_routes.dashboard_address_delete') }}" method="POST">
<button class="secondary" data-tooltip="Remove address from YelloWOWPages">Delete</button>
</form>
</footer>

Loading…
Cancel
Save