Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refine activation code generation. #1225

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 7 additions & 4 deletions app/api/views/auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import secrets
import string

import facebook
import google.oauth2.credentials
Expand All @@ -10,7 +9,7 @@

from app import email_utils
from app.api.base import api_bp
from app.config import FLASK_SECRET, DISABLE_REGISTRATION
from app.config import ACTIVATION_CODE_NUM_DIGITS, FLASK_SECRET, DISABLE_REGISTRATION
from app.dashboard.views.setting import send_reset_password_email
from app.db import Session
from app.email_utils import (
Expand Down Expand Up @@ -114,7 +113,9 @@ def auth_register():
Session.flush()

# create activation code
code = "".join([str(secrets.choice(string.digits)) for _ in range(6)])
code = str(secrets.randbelow(10**ACTIVATION_CODE_NUM_DIGITS)).zfill(
ACTIVATION_CODE_NUM_DIGITS
)
AccountActivation.create(user_id=user.id, code=code)
Session.commit()

Expand Down Expand Up @@ -208,7 +209,9 @@ def auth_reactivate():
Session.commit()

# create activation code
code = "".join([str(secrets.choice(string.digits)) for _ in range(6)])
code = str(secrets.randbelow(10**ACTIVATION_CODE_NUM_DIGITS)).zfill(
ACTIVATION_CODE_NUM_DIGITS
)
AccountActivation.create(user_id=user.id, code=code)
Session.commit()

Expand Down
2 changes: 2 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ def sl_getenv(env_var: str, default_factory: Callable = None):

print("WARNING: Use a temp directory for GNUPGHOME", GNUPGHOME)

ACTIVATION_CODE_NUM_DIGITS = 6

# Github, Google, Facebook client id and secrets
GITHUB_CLIENT_ID = os.environ.get("GITHUB_CLIENT_ID")
GITHUB_CLIENT_SECRET = os.environ.get("GITHUB_CLIENT_SECRET")
Expand Down