SFM2001 commited on
Commit
75fb515
·
1 Parent(s): 80af8fd
__pycache__/create_app.cpython-312.pyc CHANGED
Binary files a/__pycache__/create_app.cpython-312.pyc and b/__pycache__/create_app.cpython-312.pyc differ
 
__pycache__/database.cpython-312.pyc CHANGED
Binary files a/__pycache__/database.cpython-312.pyc and b/__pycache__/database.cpython-312.pyc differ
 
app.py CHANGED
@@ -3,4 +3,4 @@ from create_app import create_app
3
  app = create_app()
4
 
5
  if __name__ == '__main__':
6
- app.run(host="0.0.0.0", port=7860)
 
3
  app = create_app()
4
 
5
  if __name__ == '__main__':
6
+ app.run(host="0.0.0.0", port=7860, debug=True)
create_app.py CHANGED
@@ -17,6 +17,8 @@ LONGFORMER_MODEL = None
17
  QWEN_TOKENIZER = None
18
  QWEN_MODEL = None
19
  MODEL_SESSION = None
 
 
20
 
21
  def load_models():
22
  global MODELS_LOADED, LONGFORMER_TOKENIZER, LONGFORMER_MODEL, QWEN_TOKENIZER, QWEN_MODEL
 
17
  QWEN_TOKENIZER = None
18
  QWEN_MODEL = None
19
  MODEL_SESSION = None
20
+ TOKEN_STORE = {}
21
+ LOGGED = False
22
 
23
  def load_models():
24
  global MODELS_LOADED, LONGFORMER_TOKENIZER, LONGFORMER_MODEL, QWEN_TOKENIZER, QWEN_MODEL
database.py CHANGED
@@ -16,6 +16,13 @@ class User(UserMixin, db.Model):
16
  def check_password(self, password):
17
  return check_password_hash(self.password_hash, password)
18
 
 
 
 
 
 
 
 
19
  class History(db.Model):
20
  id = db.Column(db.Integer, primary_key=True)
21
  user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
 
16
  def check_password(self, password):
17
  return check_password_hash(self.password_hash, password)
18
 
19
+ def get_id(self):
20
+ return str(self.id)
21
+
22
+ @property
23
+ def is_active(self):
24
+ return True
25
+
26
  class History(db.Model):
27
  id = db.Column(db.Integer, primary_key=True)
28
  user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
inference/__pycache__/infer_single.cpython-312.pyc CHANGED
Binary files a/inference/__pycache__/infer_single.cpython-312.pyc and b/inference/__pycache__/infer_single.cpython-312.pyc differ
 
templates/login.html CHANGED
@@ -17,7 +17,6 @@
17
  <button type="submit" class="btn btn-primary">Login</button>
18
  </div>
19
  </form>
20
- <!-- Modal HTML -->
21
  <div class="modal fade" id="loginAlertModal" tabindex="-1" role="dialog" aria-labelledby="loginModalLabel" aria-hidden="true">
22
  <div class="modal-dialog" role="document">
23
  <div class="modal-content">
@@ -28,7 +27,6 @@
28
  </button>
29
  </div>
30
  <div class="modal-body">
31
- <!-- Message will be inserted here via JavaScript -->
32
  </div>
33
  </div>
34
  </div>
@@ -47,3 +45,4 @@
47
  });
48
  </script>
49
  {% endblock %}
 
 
17
  <button type="submit" class="btn btn-primary">Login</button>
18
  </div>
19
  </form>
 
20
  <div class="modal fade" id="loginAlertModal" tabindex="-1" role="dialog" aria-labelledby="loginModalLabel" aria-hidden="true">
21
  <div class="modal-dialog" role="document">
22
  <div class="modal-content">
 
27
  </button>
28
  </div>
29
  <div class="modal-body">
 
30
  </div>
31
  </div>
32
  </div>
 
45
  });
46
  </script>
47
  {% endblock %}
48
+
views/__pycache__/auth.cpython-312.pyc CHANGED
Binary files a/views/__pycache__/auth.cpython-312.pyc and b/views/__pycache__/auth.cpython-312.pyc differ
 
views/__pycache__/dashboard.cpython-312.pyc CHANGED
Binary files a/views/__pycache__/dashboard.cpython-312.pyc and b/views/__pycache__/dashboard.cpython-312.pyc differ
 
views/auth.py CHANGED
@@ -2,6 +2,10 @@ from flask import render_template, request, redirect, url_for
2
  from flask_login import login_user, logout_user, login_required
3
  from . import auth_bp
4
  from database import User, db
 
 
 
 
5
 
6
  @auth_bp.route('/register', methods=['GET', 'POST'])
7
  def register():
@@ -34,19 +38,26 @@ def login():
34
  if request.method == 'POST':
35
  email = request.form['email']
36
  password = request.form['password']
37
- print(email, password, flush=True)
38
  user = User.query.filter_by(email=email).first()
39
- print(user, flush=True)
40
  if user and user.check_password(password):
41
- print("LOGIN?", flush=True)
42
  login_user(user)
43
 
44
- return redirect(url_for('dashboard.dashboard'))
 
 
 
 
 
 
 
45
  else:
46
  return render_template('login.html', message="Invalid email or password.")
47
  return render_template('login.html')
48
 
49
 
 
50
  @auth_bp.route('/logout')
51
  @login_required
52
  def logout():
 
2
  from flask_login import login_user, logout_user, login_required
3
  from . import auth_bp
4
  from database import User, db
5
+ from create_app import *
6
+ import secrets
7
+ from flask import make_response
8
+
9
 
10
  @auth_bp.route('/register', methods=['GET', 'POST'])
11
  def register():
 
38
  if request.method == 'POST':
39
  email = request.form['email']
40
  password = request.form['password']
 
41
  user = User.query.filter_by(email=email).first()
42
+
43
  if user and user.check_password(password):
44
+ # Use Flask-Login's login_user
45
  login_user(user)
46
 
47
+ # Generate token (if still needed for API calls)
48
+ token = secrets.token_urlsafe(32)
49
+ TOKEN_STORE[token] = user.id
50
+
51
+ # Create response with token in cookie
52
+ response = make_response(redirect(url_for('dashboard.dashboard')))
53
+ response.set_cookie('auth_token', token, httponly=True, secure=True)
54
+ return response
55
  else:
56
  return render_template('login.html', message="Invalid email or password.")
57
  return render_template('login.html')
58
 
59
 
60
+
61
  @auth_bp.route('/logout')
62
  @login_required
63
  def logout():
views/dashboard.py CHANGED
@@ -2,34 +2,33 @@ from flask import render_template, redirect, url_for, request, flash
2
  from flask_login import login_required, current_user
3
  from . import dashboard_bp
4
  from database import History, db
5
-
6
 
7
  @dashboard_bp.route('/dashboard', defaults={'page': 1})
8
  @dashboard_bp.route('/dashboard/page/<int:page>')
9
- @login_required
10
  def dashboard(page):
 
 
 
11
  per_page = 10
12
- pagination = History.query.filter_by(user_id=current_user.id).order_by(History.created_at.desc()).paginate(page=page, per_page=per_page, error_out=False)
 
 
13
  histories = pagination.items
14
 
15
- scores_tr = [history.score_tr for history in histories]
16
- scores_cc = [history.score_cc for history in histories]
17
- scores_lr = [history.score_lr for history in histories]
18
- scores_gra = [history.score_gra for history in histories]
19
- creation_times = [history.created_at.strftime('%Y-%m-%d %H:%M:%S') for history in histories]
20
-
21
  return render_template(
22
  'dashboard.html',
23
  histories=histories,
24
  pagination=pagination,
25
- scores_tr=scores_tr,
26
- scores_cc=scores_cc,
27
- scores_lr=scores_lr,
28
- scores_gra=scores_gra,
29
- creation_times=creation_times
30
  )
 
31
  @dashboard_bp.route('/delete_histories', methods=['POST'])
32
- @login_required
33
  def delete_histories():
34
  history_ids = request.form.getlist('history_ids')
35
  History.query.filter(History.id.in_(history_ids), History.user_id == current_user.id).delete(synchronize_session=False)
 
2
  from flask_login import login_required, current_user
3
  from . import dashboard_bp
4
  from database import History, db
5
+ from create_app import *
6
 
7
  @dashboard_bp.route('/dashboard', defaults={'page': 1})
8
  @dashboard_bp.route('/dashboard/page/<int:page>')
9
+ @login_required # Use Flask-Login's decorator
10
  def dashboard(page):
11
+ # Get user ID from current_user (Flask-Login)
12
+ user_id = current_user.id
13
+
14
  per_page = 10
15
+ pagination = History.query.filter_by(user_id=user_id).order_by(History.created_at.desc()).paginate(
16
+ page=page, per_page=per_page, error_out=False
17
+ )
18
  histories = pagination.items
19
 
 
 
 
 
 
 
20
  return render_template(
21
  'dashboard.html',
22
  histories=histories,
23
  pagination=pagination,
24
+ scores_tr=[h.score_tr for h in histories],
25
+ scores_cc=[h.score_cc for h in histories],
26
+ scores_lr=[h.score_lr for h in histories],
27
+ scores_gra=[h.score_gra for h in histories],
28
+ creation_times=[h.created_at.strftime('%Y-%m-%d %H:%M:%S') for h in histories]
29
  )
30
+
31
  @dashboard_bp.route('/delete_histories', methods=['POST'])
 
32
  def delete_histories():
33
  history_ids = request.form.getlist('history_ids')
34
  History.query.filter(History.id.in_(history_ids), History.user_id == current_user.id).delete(synchronize_session=False)