mirror of
https://git.wownero.com/wownero/YellWOWPages.git
synced 2024-08-15 01:03:25 +00:00
Merge pull request 'Support address removal and reduce min. search length to 1' (#10) from min-len-1-and-remove-addy into master
Reviewed-on: https://git.wownero.com/wownero/YellWOWPages/pulls/10
This commit is contained in:
commit
dc2e24c1e8
3 changed files with 19 additions and 9 deletions
|
@ -22,10 +22,10 @@ class User(pw.Model):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def search(needle) -> List['User']:
|
async def search(needle) -> List['User']:
|
||||||
|
if not needle:
|
||||||
|
raise Exception("need search term")
|
||||||
needle = needle.replace("*", "")
|
needle = needle.replace("*", "")
|
||||||
needle = needle.lower()
|
needle = needle.lower()
|
||||||
if len(needle) <= 1:
|
|
||||||
raise Exception("need longer search term")
|
|
||||||
|
|
||||||
return User.select().where(
|
return User.select().where(
|
||||||
User.address.is_null(False),
|
User.address.is_null(False),
|
||||||
|
|
|
@ -34,7 +34,6 @@ async def dashboard():
|
||||||
@bp_routes.post("/dashboard/address")
|
@bp_routes.post("/dashboard/address")
|
||||||
@login_required
|
@login_required
|
||||||
async def dashboard_address_post():
|
async def dashboard_address_post():
|
||||||
# get FORM POST value 'address'
|
|
||||||
form = await request.form
|
form = await request.form
|
||||||
address = form.get('address')
|
address = form.get('address')
|
||||||
if not bool(re.match(r'^(WW)\\d[0-9A-Za-z]{94}$', 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')
|
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")
|
@bp_routes.route("/search")
|
||||||
async def search():
|
async def search():
|
||||||
needle = request.args.get('username')
|
needle = request.args.get('username')
|
||||||
if needle:
|
if needle:
|
||||||
if len(needle) <= 1:
|
|
||||||
raise Exception("Search term needs to be longer")
|
|
||||||
|
|
||||||
users = [u for u in await User.search(needle)]
|
users = [u for u in await User.search(needle)]
|
||||||
if users:
|
if users:
|
||||||
return await render_template('search_results.html', users=users)
|
return await render_template('search_results.html', users=users)
|
||||||
|
@ -73,7 +80,7 @@ async def search():
|
||||||
|
|
||||||
@bp_routes.route("/user/<path:name>")
|
@bp_routes.route("/user/<path:name>")
|
||||||
async def user_page(name: str):
|
async def user_page(name: str):
|
||||||
if not name or len(name) <= 1:
|
if not name:
|
||||||
raise Exception("invalid name")
|
raise Exception("invalid name")
|
||||||
name = name.lower()
|
name = name.lower()
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="main">
|
<div id="main">
|
||||||
<article>
|
<article style="min-width: 620px">
|
||||||
<Header>Welcome back <em>{{user.username}}</em>!</Header>
|
<Header>Welcome back <em>{{user.username}}</em>!</Header>
|
||||||
Current <u>WOW address</u>: <label>
|
Current <u>WOW address</u>: <label>
|
||||||
{% if user.address %}
|
{% if user.address %}
|
||||||
|
@ -18,7 +18,10 @@
|
||||||
Change <u>WOW address</u>:
|
Change <u>WOW address</u>:
|
||||||
<form action="{{ url_for('bp_routes.dashboard_address_post') }}" method="POST">
|
<form action="{{ url_for('bp_routes.dashboard_address_post') }}" method="POST">
|
||||||
<input type="text" name="address">
|
<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>
|
</form>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue