|
4 | 4 | import logging |
5 | 5 | import math |
6 | 6 | from flask import render_template, request, redirect, url_for, session, flash |
7 | | -from .utils import * |
| 7 | +from .utils import getSetting, render_module, renderRepos, render_message |
8 | 8 | from flask_login import login_user, logout_user, current_user, login_required |
9 | 9 |
|
10 | 10 | from augur.application.db.models import User, Repo, ClientApplication |
11 | 11 | from .server import LoginException |
12 | | -from augur.application.util import * |
| 12 | +from augur.application.util import get_all_repos, get_all_repos_count |
13 | 13 | from augur.application.db.lib import get_value |
14 | 14 | from ..server import app, db_session |
15 | 15 |
|
@@ -57,7 +57,7 @@ def repo_table_view(): |
57 | 57 | query = request.args.get('q') |
58 | 58 | try: |
59 | 59 | page = int(request.args.get('p') or 0) |
60 | | - except: |
| 60 | + except (ValueError, TypeError): |
61 | 61 | page = 1 |
62 | 62 |
|
63 | 63 | sorting = request.args.get('s') |
@@ -147,19 +147,19 @@ def user_login(): |
147 | 147 | result = User.create_user(username, password, email, first_name, last_name, admin) |
148 | 148 | if not result[0]: |
149 | 149 | raise LoginException("An error occurred registering your account") |
150 | | - else: |
151 | | - user = User.get_user(db_session, username) |
152 | | - flash(result[1]["status"]) |
| 150 | + |
| 151 | + user = User.get_user(db_session, username) |
| 152 | + flash(result[1]["status"]) |
153 | 153 |
|
154 | 154 | # Log the user in if the password is valid |
155 | 155 | if user.validate(password) and login_user(user, remember = remember): |
156 | 156 | flash(f"Welcome, {username}!") |
157 | 157 | if "login_next" in session: |
158 | 158 | return redirect(session.pop("login_next")) |
159 | 159 | return redirect(url_for('root')) |
160 | | - else: |
161 | | - print("Invalid login") |
162 | | - raise LoginException("Invalid login credentials") |
| 160 | + |
| 161 | + print("Invalid login") |
| 162 | + raise LoginException("Invalid login credentials") |
163 | 163 | except LoginException as e: |
164 | 164 | flash(str(e)) |
165 | 165 | return render_module('login', title="Login") |
@@ -198,10 +198,18 @@ def authorize_user(): |
198 | 198 | @app.route('/account/delete') |
199 | 199 | @login_required |
200 | 200 | def user_delete(): |
201 | | - if current_user.delete()[0]: |
202 | | - flash(f"Account {current_user.login_name} successfully removed") |
203 | | - logout_user() |
204 | | - else: |
| 201 | + try: |
| 202 | + username = current_user.login_name |
| 203 | + result = current_user.delete(db_session) |
| 204 | + |
| 205 | + if result[0]: |
| 206 | + flash(f"Account {username} successfully removed") |
| 207 | + logout_user() |
| 208 | + else: |
| 209 | + logger.error(f"Failed to delete account {username}: {result[1]}") |
| 210 | + flash("An error occurred removing the account") |
| 211 | + except Exception as e: |
| 212 | + logger.error(f"Exception occurred while deleting account: {e}") |
205 | 213 | flash("An error occurred removing the account") |
206 | 214 |
|
207 | 215 | return redirect(url_for("root")) |
@@ -256,7 +264,7 @@ def user_groups_view(): |
256 | 264 |
|
257 | 265 | try: |
258 | 266 | activepage = int(request.args.get('p')) if 'p' in request.args else 0 |
259 | | - except: |
| 267 | + except (ValueError, TypeError): |
260 | 268 | activepage = 0 |
261 | 269 |
|
262 | 270 | (groups, status) = current_user.get_groups_info(**params) |
@@ -291,7 +299,7 @@ def user_group_view(group = None): |
291 | 299 |
|
292 | 300 | try: |
293 | 301 | params["page"] = int(request.args.get('p') or 0) |
294 | | - except: |
| 302 | + except (ValueError, TypeError): |
295 | 303 | params["page"] = 1 |
296 | 304 |
|
297 | 305 | if query := request.args.get('q'): |
@@ -337,6 +345,8 @@ def dashboard_view(): |
337 | 345 | ]} |
338 | 346 | ] |
339 | 347 |
|
340 | | - backend_config = requestJson("config/get", False) |
| 348 | + # backend_config = requestJson("config/get", False) |
| 349 | + # TODO: requestJson is undefined and causing pylint errors. Setting empty config for now. |
| 350 | + backend_config = {} |
341 | 351 |
|
342 | 352 | return render_template('admin-dashboard.j2', sections = empty, config = backend_config) |
0 commit comments