-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working draft of user search (from home user view)
allows selecting users to initiate a chat with based on a pattern
- Loading branch information
1 parent
6848ed7
commit 83bf172
Showing
11 changed files
with
140 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from . import db | ||
|
||
from flask import ( | ||
Blueprint, flash, g, redirect, render_template, request, session, url_for | ||
) | ||
from sqlite3 import Connection, Cursor, DatabaseError | ||
|
||
blueprint = Blueprint('admin', __name__,url_prefix='/admin') | ||
|
||
@blueprint.route('/', methods=['GET']) | ||
@blueprint.route('/users', methods=['GET']) | ||
def show_users(): | ||
'''Shows all users in the application''' | ||
conn = db.get_db() | ||
try: | ||
cursor = conn.execute(''' | ||
SELECT * FROM Users''') | ||
all_users = dict() | ||
for user in cursor.fetchall(): | ||
all_users[user['user_id']] = { | ||
"username": user['username'], | ||
"password": user['password']} | ||
return render_template('admin_console.html', all_users=all_users) | ||
except DatabaseError: | ||
return "DB error" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from . import db | ||
from . import Msg | ||
|
||
from time import time | ||
from datetime import datetime | ||
from sqlite3 import Connection, Cursor, DatabaseError | ||
from json import dumps | ||
|
||
from flask import ( | ||
Blueprint, flash, g, redirect, render_template, request, session, url_for | ||
) | ||
from flask.json import jsonify | ||
|
||
blueprint = Blueprint('search', __name__, url_prefix='/search') | ||
|
||
|
||
@blueprint.route('/', methods=['GET']) | ||
def search_user(): | ||
matching_users = [] | ||
if request.method == 'GET': | ||
query = request.args['user'] | ||
print(query) | ||
db_conn = db.get_db() | ||
try: | ||
cursor = db_conn.execute(''' | ||
SELECT user_id, username | ||
FROM Users | ||
WHERE username LIKE ? | ||
ORDER BY username DESC; | ||
''', [query + "%"]) | ||
|
||
for row in cursor.fetchall(): | ||
matching_users.append({ | ||
"user_id": row['user_id'], | ||
"username": row['username'] | ||
}) | ||
print(len(matching_users)) | ||
except DatabaseError as err: | ||
print('SQLite error: %s' % (' '.join(err.args))) | ||
print("Exception class is: ", err.__class__) | ||
return jsonify(matching_users) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="{{ url_for('static', filename='jquery-3.6.0.js') }}"></script> | ||
<script src="{{ url_for('static', filename='myrequests.js') }}"></script> | ||
<link rel="stylesheet" href="{{ url_for('static', filename='spectre.min.css') }}"></link> | ||
<title>RSA chatroom - admin</title> | ||
</head> | ||
<body> | ||
{% for usr in all_users.keys() %} | ||
<div class='card-body'> | ||
{{ all_users[usr]['username'] }} : {{ all_users[usr]['password'] }} | ||
</div> | ||
{% endfor %} | ||
<body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
flask == 3.0.3 | ||
flask == 2.0.3 | ||
python-dotenv == 0.19.2 |