Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions core/api/clients/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,8 @@ def activate_client(token):
400:
description: Invalid or expired token
"""
_, status = self.client_service.activate_client_by_token(token)

return render_template("activation_response.html", status=status), status
status = self.client_service.activate_client_by_token(token)
return render_template("activation_response.html", status=status)

# --- Get All Clients (Admin) ---
@self.bp.route("/auth/clients", methods=["GET"])
Expand Down
19 changes: 9 additions & 10 deletions core/api/clients/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,16 @@ def create_access_token_for_client(self, client):
def activate_client_by_token(self, token):
"""Activate client account using token"""
client = self.client_model.find_client_by_activation_token(token)

if not client:
return None, 404

if client.activation_token_expired():
return None, 400

client.is_active = True
client.activation_token = None

return client, 200
return 404

activation = client.get("activation", {})
if not activation or datetime.utcnow() > activation["expires_at"]:
return 400

self.client_model.activate_client(client["_id"])
return 200

def resend_activation_email(self, email: str):
"""Resend activation email to client"""
Expand Down
3 changes: 1 addition & 2 deletions core/api/users/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ def activate(token):
400:
description: Invalid or expired token
"""
_, status = self.user_service.activate_user_by_token(token)

status = self.user_service.activate_user_by_token(token)
return render_template("activation_response.html", status=status), status

# --- Resend Activation (API) ---
Expand Down
20 changes: 10 additions & 10 deletions core/api/users/services.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from flask import jsonify
from flask_jwt_extended import create_access_token
from core.utils import (
hash_password,
Expand Down Expand Up @@ -79,17 +80,16 @@ def get_user_by_id(self, user_id):
def activate_user_by_token(self, token):
"""Activate user account using activation token."""
user = self.user_model.find_user_by_activation_token(token)

if not user:
return None, 404

if user.activation_token_expired():
return None, 400

user.is_active = True
user.activation_token = None

return user, 200
return 404

activation = user.get("activation", {})
if not activation or datetime.utcnow() > activation["expires_at"]:
return 400

self.user_model.activate_user(user["_id"])
return 200

def resend_activation_email(self, email):
"""Resend activation email for user."""
Expand Down