roundabout,
created on Monday, 13 May 2024, 14:40:18 (1715611218),
received on Wednesday, 31 July 2024, 06:54:48 (1722408888)
Author identity: vlad <vlad.muntoiu@gmail.com>
9ae8ee9055925270966f6e3e2cfc110413eb4425
celery_tasks.py
@@ -119,3 +119,16 @@ def delete_site(route):
primary_site = Repo.query.filter_by(owner=repo.owner, has_site=2).first() if primary_site: copy_site(primary_site.route) @shared_task(ignore_result=False) def request_email_change(username, email): from models import User, EmailChangeRequest user = db.session.get(User, username) request = models.EmailChangeRequest(user, email) db.session.add(request) db.session.commit() return request.id
models.py
@@ -12,10 +12,11 @@ __all__ = [
"PullRequest", ] import secrets import subprocess from app import app, db, bcrypt import git from datetime import datetimefrom datetime import datetime, timedeltafrom enum import Enum from PIL import Image from cairosvg import svg2png
@@ -98,6 +99,7 @@ with (app.app_context()):
repositories = db.relationship("Repo", back_populates="owner") followers = db.relationship("UserFollow", back_populates="followed", foreign_keys="[UserFollow.followed_username]") follows = db.relationship("UserFollow", back_populates="follower", foreign_keys="[UserFollow.follower_username]") email_change_requests = db.relationship("EmailChangeRequest", back_populates="user")repo_access = db.relationship("RepoAccess", back_populates="user") votes = db.relationship("PostVote", back_populates="user") favourites = db.relationship("RepoFavourite", back_populates="user")
@@ -344,3 +346,19 @@ with (app.app_context()):
self.head_branch = head_branch self.base_branch = base_branch self.owner = owner class EmailChangeRequest(db.Model): id = db.Column(db.BigInteger, primary_key=True, autoincrement=True) user_username = db.Column(db.String(32), db.ForeignKey("user.username"), nullable=False) new_email = db.Column(db.String(254), nullable=False) code = db.Column(db.String(64), nullable=False) expires_on = db.Column(db.DateTime, nullable=False) user = db.relationship("User", back_populates="email_change_requests") def __init__(self, user, new_email): self.user = user self.new_email = new_email self.code = hex(secrets.randbits(256)).removeprefix("0x") self.expires_on = datetime.now() + timedelta(days=1)