Compare commits
60 Commits
4.39.1
...
bfbcf567aa
| Author | SHA1 | Date | |
|---|---|---|---|
| bfbcf567aa | |||
| a505186051 | |||
| 8fcca8571a | |||
| 1550507667 | |||
| 757f153042 | |||
| a9f65bed60 | |||
| a8ca607581 | |||
| 5b47bd1654 | |||
| e9faf93878 | |||
| 0f60f7cec9 | |||
| 3180034ff8 | |||
| b3ee67213d | |||
| aeb34f8582 | |||
| 2372b8f50f | |||
| f3050b2ca0 | |||
| ebe941c8a5 | |||
| 651b2dd52a | |||
| 1c580cb6f7 | |||
| 21765ae9d8 | |||
| d661a52f43 | |||
| 45528ff81d | |||
| 6170fbf127 | |||
| c8ab76066b | |||
| 357d34a42b | |||
| 246754872d | |||
| df59d73d66 | |||
| ff6d78f255 | |||
| d59fa5fe1c | |||
| de1fe02200 | |||
| 439bfc5efd | |||
| 0a8a420850 | |||
| d119e74c2f | |||
| b5485429ef | |||
| f3a7900cbd | |||
| 0f91161ff3 | |||
| 1da9a3f828 | |||
| 167e56bc95 | |||
| c5a0d2d513 | |||
| 25ebbaa7fd | |||
| 067d94841e | |||
| 804eec0c03 | |||
| 651f3f1e9c | |||
| fd988d6ef0 | |||
| da4a8cc979 | |||
| 299da46abe | |||
| 1ad8294ec3 | |||
| f5de4a9624 | |||
| 5501b033e8 | |||
| 32a4b865ef | |||
| 5d5a23dd63 | |||
| 03053d0e54 | |||
| 4d70590d05 | |||
| bc879c10ae | |||
| c6b237a004 | |||
| 722979fe19 | |||
| b63ada023d | |||
| 8b4e4e3a2b | |||
| 32465d1220 | |||
| 98bae4c86c | |||
| 7ff6cf2451 |
52
.drone.yml
52
.drone.yml
@ -1,52 +0,0 @@
|
|||||||
|
|
||||||
kind: pipeline
|
|
||||||
type: docker
|
|
||||||
name: build-multiarch-images
|
|
||||||
|
|
||||||
platform:
|
|
||||||
os: linux
|
|
||||||
arch: amd64
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: make-tags
|
|
||||||
image: node
|
|
||||||
commands:
|
|
||||||
- echo -n "${DRONE_TAG}, latest" > .tags
|
|
||||||
|
|
||||||
- name: build
|
|
||||||
image: thegeeklab/drone-docker-buildx
|
|
||||||
privileged: true
|
|
||||||
settings:
|
|
||||||
provenance: false
|
|
||||||
dockerfile: app/Dockerfile
|
|
||||||
context: app
|
|
||||||
registry: git.mrmeeb.stream
|
|
||||||
username:
|
|
||||||
from_secret: docker_username
|
|
||||||
password:
|
|
||||||
from_secret: docker_password
|
|
||||||
repo: git.mrmeeb.stream/mrmeeb/simple-login
|
|
||||||
platforms:
|
|
||||||
- linux/arm64
|
|
||||||
- linux/amd64
|
|
||||||
|
|
||||||
- name: notify
|
|
||||||
image: plugins/slack
|
|
||||||
when:
|
|
||||||
status:
|
|
||||||
- success
|
|
||||||
- failure
|
|
||||||
- killed
|
|
||||||
settings:
|
|
||||||
webhook:
|
|
||||||
from_secret: slack_webhook
|
|
||||||
icon_url:
|
|
||||||
from_secret: slack_avatar
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
event:
|
|
||||||
include:
|
|
||||||
- tag
|
|
||||||
ref:
|
|
||||||
include:
|
|
||||||
- refs/tags/**
|
|
||||||
195
.gitea/workflows/build-release-image.yaml
Normal file
195
.gitea/workflows/build-release-image.yaml
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
name: Build-Release-Image
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
CONTAINER_NAME: git.mrmeeb.stream/mrmeeb/simple-login-dev
|
||||||
|
TEA_VERSION: 0.9.2
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
Build-Image:
|
||||||
|
runs-on: [ubuntu-docker-latest, "${{ matrix.platform }}"]
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
platform:
|
||||||
|
- linux/amd64
|
||||||
|
- linux/arm64
|
||||||
|
steps:
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
platform=${{ matrix.platform }}
|
||||||
|
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
|
||||||
|
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
# Not needed currently due to https://github.com/go-gitea/gitea/issues/29563
|
||||||
|
#- name: Prepare tags
|
||||||
|
# id: meta
|
||||||
|
# uses: docker/metadata-action@v5
|
||||||
|
# with:
|
||||||
|
# images: ${{ env.CONTAINER_NAME }}
|
||||||
|
# tags: |
|
||||||
|
# type=pep440,pattern={{version}}
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
- name: Login to Gitea Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: git.mrmeeb.stream
|
||||||
|
username: ${{ env.GITHUB_ACTOR }}
|
||||||
|
password: ${{ secrets.GTCR_TOKEN }}
|
||||||
|
- name: Build and push by digest
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
id: build
|
||||||
|
with:
|
||||||
|
context: ./app
|
||||||
|
platforms: ${{ matrix.platform }}
|
||||||
|
provenance: false
|
||||||
|
outputs: type=image,name=${{ env.CONTAINER_NAME }},push-by-digest=true,name-canonical=true,push=true
|
||||||
|
- name: Export digest
|
||||||
|
run: |
|
||||||
|
mkdir -p /tmp/digests
|
||||||
|
digest="${{ steps.build.outputs.digest }}"
|
||||||
|
touch "/tmp/digests/${digest#sha256:}"
|
||||||
|
- name: Upload digest
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: digests-${{ env.PLATFORM_PAIR }}
|
||||||
|
path: /tmp/digests/*
|
||||||
|
if-no-files-found: error
|
||||||
|
retention-days: 1
|
||||||
|
- name: Notify
|
||||||
|
uses: rjstone/discord-webhook-notify@v1
|
||||||
|
if: failure()
|
||||||
|
with:
|
||||||
|
severity: ${{ job.status == 'success' && 'info' || (job.status == 'cancelled' && 'warn' || 'error') }}
|
||||||
|
details: Build ${{ job.status == 'success' && 'succeeded' || (job.status == 'cancelled' && 'cancelled' || 'failed') }}!
|
||||||
|
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
|
||||||
|
username: Gitea
|
||||||
|
avatarUrl: ${{ vars.RUNNER_ICON_URL }}
|
||||||
|
|
||||||
|
Merge-Images:
|
||||||
|
runs-on: ubuntu-docker-latest
|
||||||
|
needs: [Build-Image]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Get tag
|
||||||
|
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||||
|
- name: Download digests
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
path: /tmp/digests
|
||||||
|
pattern: digests-*
|
||||||
|
merge-multiple: true
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
# Not needed currently due to https://github.com/go-gitea/gitea/issues/29563
|
||||||
|
#- name: Prepare Docker metadata
|
||||||
|
# id: meta
|
||||||
|
# uses: docker/metadata-action@v5
|
||||||
|
# with:
|
||||||
|
# images: ${{ env.CONTAINER_NAME }}
|
||||||
|
- name: Login to Gitea Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: git.mrmeeb.stream
|
||||||
|
username: ${{ env.GITHUB_ACTOR }}
|
||||||
|
password: ${{ secrets.GTCR_TOKEN }}
|
||||||
|
- name: Create manifest latest
|
||||||
|
working-directory: /tmp/digests
|
||||||
|
run: |
|
||||||
|
docker manifest create ${{ env.CONTAINER_NAME }}:latest \
|
||||||
|
--amend ${{ env.CONTAINER_NAME }}@sha256:$(ls -p digests-linux-amd64/* | cut -d / -f 2) \
|
||||||
|
--amend ${{ env.CONTAINER_NAME }}@sha256:$(ls -p digests-linux-arm64/* | cut -d / -f 2)
|
||||||
|
#docker manifest annotate --arch amd64 --os linux ${{ env.CONTAINER_NAME }}:latest ${{ env.CONTAINER_NAME }}@sha256:$(ls -p digests-linux-amd64/* | cut -d / -f 2)
|
||||||
|
#docker manifest annotate --arch arm64 --os linux ${{ env.CONTAINER_NAME }}:latest ${{ env.CONTAINER_NAME }}@sha256:$(ls -p digests-linux-arm64/* | cut -d / -f 2)
|
||||||
|
docker manifest inspect ${{ env.CONTAINER_NAME }}:latest
|
||||||
|
|
||||||
|
docker manifest push ${{ env.CONTAINER_NAME }}:latest
|
||||||
|
- name: Create manifest tagged
|
||||||
|
working-directory: /tmp/digests
|
||||||
|
run: |
|
||||||
|
docker manifest create ${{ env.CONTAINER_NAME }}:${{ env.RELEASE_VERSION }} \
|
||||||
|
--amend ${{ env.CONTAINER_NAME }}@sha256:$(ls -p digests-linux-amd64/* | cut -d / -f 2) \
|
||||||
|
--amend ${{ env.CONTAINER_NAME }}@sha256:$(ls -p digests-linux-arm64/* | cut -d / -f 2)
|
||||||
|
#docker manifest annotate --arch amd64 --os linux ${{ env.CONTAINER_NAME }}:${{ env.RELEASE_VERSION }} ${{ env.CONTAINER_NAME }}@sha256:$(ls -p digests-linux-amd64/* | cut -d / -f 2)
|
||||||
|
#docker manifest annotate --arch arm64 --os linux ${{ env.CONTAINER_NAME }}:${{ env.RELEASE_VERSION }} ${{ env.CONTAINER_NAME }}@sha256:$(ls -p digests-linux-arm64/* | cut -d / -f 2)
|
||||||
|
docker manifest inspect ${{ env.CONTAINER_NAME }}:${{ env.RELEASE_VERSION }}
|
||||||
|
|
||||||
|
docker manifest push ${{ env.CONTAINER_NAME }}:${{ env.RELEASE_VERSION }}
|
||||||
|
# Disabled due to https://github.com/go-gitea/gitea/issues/29563
|
||||||
|
#- name: Create manifest list and push
|
||||||
|
# working-directory: /tmp/digests
|
||||||
|
# run: |
|
||||||
|
# echo $DOCKER_METADATA_OUTPUT_JSON
|
||||||
|
# echo $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
|
||||||
|
# $(printf '${{ env.CONTAINER_NAME }}@sha256:%s ' $(ls -p */* | cut -d / -f 2))
|
||||||
|
# docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
|
||||||
|
# $(printf '${{ env.CONTAINER_NAME }}@sha256:%s ' $(ls -p */* | cut -d / -f 2))
|
||||||
|
#- name: Inspect image
|
||||||
|
# run: |
|
||||||
|
# docker buildx imagetools inspect ${{ env.CONTAINER_NAME }}:${{ steps.meta.outputs.version }}
|
||||||
|
- name: Notify
|
||||||
|
uses: rjstone/discord-webhook-notify@v1
|
||||||
|
if: failure()
|
||||||
|
with:
|
||||||
|
severity: ${{ job.status == 'success' && 'info' || (job.status == 'cancelled' && 'warn' || 'error') }}
|
||||||
|
details: Build ${{ job.status == 'success' && 'succeeded' || (job.status == 'cancelled' && 'cancelled' || 'failed') }}!
|
||||||
|
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
|
||||||
|
username: Gitea
|
||||||
|
avatarUrl: ${{ vars.RUNNER_ICON_URL }}
|
||||||
|
|
||||||
|
Create-Release:
|
||||||
|
runs-on: [ubuntu-latest, linux/amd64]
|
||||||
|
needs: [Merge-Images]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Get tag
|
||||||
|
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||||
|
- name: Prepare tea
|
||||||
|
run: |
|
||||||
|
# Download tea from Gitea release page
|
||||||
|
echo "Downloading Tea v${{ env.TEA_VERSION }}" && \
|
||||||
|
wget -q -O tea https://gitea.com/gitea/tea/releases/download/v${{ env.TEA_VERSION }}/tea-${{ env.TEA_VERSION }}-linux-amd64 && \
|
||||||
|
echo "Downloaded Tea" && \
|
||||||
|
chmod +x tea && \
|
||||||
|
# Login to Gitea
|
||||||
|
echo "Logging in to Gitea using Tea" && \
|
||||||
|
./tea login add --name SimpleLogin --url https://git.mrmeeb.stream --token ${{ secrets.GITHUB_TOKEN }} && \
|
||||||
|
echo "Done"
|
||||||
|
- name: Make release
|
||||||
|
run: |
|
||||||
|
echo "Creating release" && \
|
||||||
|
./tea release create --login "SimpleLogin" --repo ${{ env.GITHUB_REPOSITORY }} --tag ${{ env.RELEASE_VERSION }} -t ${{ env.RELEASE_VERSION }} -n "Triggered by release of v${{ env.RELEASE_VERSION }} by the SimpleLogin team. <a href=\"https://github.com/simple-login/app/releases/tag/v${{ env.RELEASE_VERSION }}\" target=\"_blank\">View the changelog</a>" && \
|
||||||
|
echo "Done"
|
||||||
|
- name: Notify
|
||||||
|
uses: rjstone/discord-webhook-notify@v1
|
||||||
|
if: failure()
|
||||||
|
with:
|
||||||
|
severity: ${{ job.status == 'success' && 'info' || (job.status == 'cancelled' && 'warn' || 'error') }}
|
||||||
|
details: Release ${{ job.status == 'success' && 'succeeded' || (job.status == 'cancelled' && 'cancelled' || 'failed') }}!
|
||||||
|
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
|
||||||
|
username: Gitea
|
||||||
|
avatarUrl: ${{ vars.RUNNER_ICON_URL }}
|
||||||
|
|
||||||
|
Notify:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [Build-Image, Merge-Images, Create-Release]
|
||||||
|
steps:
|
||||||
|
- name: Notify
|
||||||
|
uses: rjstone/discord-webhook-notify@v1
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
severity: ${{ job.status == 'success' && 'info' || (job.status == 'cancelled' && 'warn' || 'error') }}
|
||||||
|
details: Release ${{ job.status == 'success' && 'succeeded' || (job.status == 'cancelled' && 'cancelled' || 'failed') }}!
|
||||||
|
webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
|
||||||
|
username: Gitea
|
||||||
|
avatarUrl: ${{ vars.RUNNER_ICON_URL }}
|
||||||
@ -168,6 +168,8 @@ class NewUserStrategy(ClientMergeStrategy):
|
|||||||
|
|
||||||
class ExistingUnlinkedUserStrategy(ClientMergeStrategy):
|
class ExistingUnlinkedUserStrategy(ClientMergeStrategy):
|
||||||
def process(self) -> LinkResult:
|
def process(self) -> LinkResult:
|
||||||
|
# IF it was scheduled to be deleted. Unschedule it.
|
||||||
|
self.user.delete_on = None
|
||||||
partner_user = ensure_partner_user_exists_for_user(
|
partner_user = ensure_partner_user_exists_for_user(
|
||||||
self.link_request, self.user, self.partner
|
self.link_request, self.user, self.partner
|
||||||
)
|
)
|
||||||
@ -246,6 +248,8 @@ def link_user(
|
|||||||
) -> LinkResult:
|
) -> LinkResult:
|
||||||
# Sanitize email just in case
|
# Sanitize email just in case
|
||||||
link_request.email = sanitize_email(link_request.email)
|
link_request.email = sanitize_email(link_request.email)
|
||||||
|
# If it was scheduled to be deleted. Unschedule it.
|
||||||
|
current_user.delete_on = None
|
||||||
partner_user = ensure_partner_user_exists_for_user(
|
partner_user = ensure_partner_user_exists_for_user(
|
||||||
link_request, current_user, partner
|
link_request, current_user, partner
|
||||||
)
|
)
|
||||||
|
|||||||
@ -33,6 +33,9 @@ def authorize_request() -> Optional[Tuple[str, int]]:
|
|||||||
if g.user.disabled:
|
if g.user.disabled:
|
||||||
return jsonify(error="Disabled account"), 403
|
return jsonify(error="Disabled account"), 403
|
||||||
|
|
||||||
|
if not g.user.is_active():
|
||||||
|
return jsonify(error="Account does not exist"), 401
|
||||||
|
|
||||||
g.api_key = api_key
|
g.api_key = api_key
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ from app.config import URL, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET
|
|||||||
from app.db import Session
|
from app.db import Session
|
||||||
from app.log import LOG
|
from app.log import LOG
|
||||||
from app.models import User, File, SocialAuth
|
from app.models import User, File, SocialAuth
|
||||||
from app.utils import random_string, sanitize_email
|
from app.utils import random_string, sanitize_email, sanitize_next_url
|
||||||
from .login_utils import after_login
|
from .login_utils import after_login
|
||||||
|
|
||||||
_authorization_base_url = "https://accounts.google.com/o/oauth2/v2/auth"
|
_authorization_base_url = "https://accounts.google.com/o/oauth2/v2/auth"
|
||||||
@ -29,7 +29,7 @@ def google_login():
|
|||||||
# to avoid flask-login displaying the login error message
|
# to avoid flask-login displaying the login error message
|
||||||
session.pop("_flashes", None)
|
session.pop("_flashes", None)
|
||||||
|
|
||||||
next_url = request.args.get("next")
|
next_url = sanitize_next_url(request.args.get("next"))
|
||||||
|
|
||||||
# Google does not allow to append param to redirect_url
|
# Google does not allow to append param to redirect_url
|
||||||
# we need to pass the next url by session
|
# we need to pass the next url by session
|
||||||
|
|||||||
@ -727,6 +727,11 @@ class User(Base, ModelMixin, UserMixin, PasswordOracle):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def is_active(self) -> bool:
|
||||||
|
if self.delete_on is None:
|
||||||
|
return True
|
||||||
|
return self.delete_on < arrow.now()
|
||||||
|
|
||||||
def in_trial(self):
|
def in_trial(self):
|
||||||
"""return True if user does not have lifetime licence or an active subscription AND is in trial period"""
|
"""return True if user does not have lifetime licence or an active subscription AND is in trial period"""
|
||||||
if self.lifetime_or_active_subscription():
|
if self.lifetime_or_active_subscription():
|
||||||
@ -828,6 +833,9 @@ class User(Base, ModelMixin, UserMixin, PasswordOracle):
|
|||||||
Whether user can create a new alias. User can't create a new alias if
|
Whether user can create a new alias. User can't create a new alias if
|
||||||
- has more than 15 aliases in the free plan, *even in the free trial*
|
- has more than 15 aliases in the free plan, *even in the free trial*
|
||||||
"""
|
"""
|
||||||
|
if not self.is_active():
|
||||||
|
return False
|
||||||
|
|
||||||
if self.disabled:
|
if self.disabled:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@ -140,7 +140,7 @@ def authorize():
|
|||||||
Scope=Scope,
|
Scope=Scope,
|
||||||
)
|
)
|
||||||
else: # POST - user allows or denies
|
else: # POST - user allows or denies
|
||||||
if not current_user.is_authenticated or not current_user.is_active:
|
if not current_user.is_authenticated or not current_user.is_active():
|
||||||
LOG.i(
|
LOG.i(
|
||||||
"Attempt to validate a OAUth allow request by an unauthenticated user"
|
"Attempt to validate a OAUth allow request by an unauthenticated user"
|
||||||
)
|
)
|
||||||
|
|||||||
13
app/cron.py
13
app/cron.py
@ -62,6 +62,8 @@ from app.proton.utils import get_proton_partner
|
|||||||
from app.utils import sanitize_email
|
from app.utils import sanitize_email
|
||||||
from server import create_light_app
|
from server import create_light_app
|
||||||
|
|
||||||
|
DELETE_GRACE_DAYS = 30
|
||||||
|
|
||||||
|
|
||||||
def notify_trial_end():
|
def notify_trial_end():
|
||||||
for user in User.filter(
|
for user in User.filter(
|
||||||
@ -1126,14 +1128,19 @@ def notify_hibp():
|
|||||||
Session.commit()
|
Session.commit()
|
||||||
|
|
||||||
|
|
||||||
def clear_users_scheduled_to_be_deleted():
|
def clear_users_scheduled_to_be_deleted(dry_run=False):
|
||||||
users = User.filter(
|
users = User.filter(
|
||||||
and_(User.delete_on.isnot(None), User.delete_on < arrow.now())
|
and_(
|
||||||
|
User.delete_on.isnot(None),
|
||||||
|
User.delete_on <= arrow.now().shift(days=-DELETE_GRACE_DAYS),
|
||||||
|
)
|
||||||
).all()
|
).all()
|
||||||
for user in users:
|
for user in users:
|
||||||
LOG.i(
|
LOG.i(
|
||||||
f"Scheduled deletion of user {user} with scheduled delete on {user.delete_on}"
|
f"Scheduled deletion of user {user} with scheduled delete on {user.delete_on}"
|
||||||
)
|
)
|
||||||
|
if dry_run:
|
||||||
|
continue
|
||||||
User.delete(user.id)
|
User.delete(user.id)
|
||||||
Session.commit()
|
Session.commit()
|
||||||
|
|
||||||
@ -1206,4 +1213,4 @@ if __name__ == "__main__":
|
|||||||
load_unsent_mails_from_fs_and_resend()
|
load_unsent_mails_from_fs_and_resend()
|
||||||
elif args.job == "delete_scheduled_users":
|
elif args.job == "delete_scheduled_users":
|
||||||
LOG.d("Deleting users scheduled to be deleted")
|
LOG.d("Deleting users scheduled to be deleted")
|
||||||
clear_users_scheduled_to_be_deleted()
|
clear_users_scheduled_to_be_deleted(dry_run=True)
|
||||||
|
|||||||
@ -62,7 +62,7 @@ jobs:
|
|||||||
captureStderr: true
|
captureStderr: true
|
||||||
|
|
||||||
- name: SimpleLogin delete users scheduled to be deleted
|
- name: SimpleLogin delete users scheduled to be deleted
|
||||||
command: echo disabled_user_deletion #python /code/cron.py -j delete_scheduled_users
|
command: python /code/cron.py -j delete_scheduled_users
|
||||||
shell: /bin/bash
|
shell: /bin/bash
|
||||||
schedule: "15 11 * * *"
|
schedule: "15 11 * * *"
|
||||||
captureStderr: true
|
captureStderr: true
|
||||||
|
|||||||
@ -236,15 +236,16 @@ def get_or_create_contact(from_header: str, mail_from: str, alias: Alias) -> Con
|
|||||||
Session.commit()
|
Session.commit()
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
contact_email_for_reply = (
|
||||||
|
contact_email if is_valid_email(contact_email) else ""
|
||||||
|
)
|
||||||
contact = Contact.create(
|
contact = Contact.create(
|
||||||
user_id=alias.user_id,
|
user_id=alias.user_id,
|
||||||
alias_id=alias.id,
|
alias_id=alias.id,
|
||||||
website_email=contact_email,
|
website_email=contact_email,
|
||||||
name=contact_name,
|
name=contact_name,
|
||||||
mail_from=mail_from,
|
mail_from=mail_from,
|
||||||
reply_email=generate_reply_email(contact_email, alias)
|
reply_email=generate_reply_email(contact_email_for_reply, alias),
|
||||||
if is_valid_email(contact_email)
|
|
||||||
else NOREPLY,
|
|
||||||
automatic_created=True,
|
automatic_created=True,
|
||||||
)
|
)
|
||||||
if not contact_email:
|
if not contact_email:
|
||||||
@ -636,6 +637,10 @@ def handle_forward(envelope, msg: Message, rcpt_to: str) -> List[Tuple[bool, str
|
|||||||
|
|
||||||
user = alias.user
|
user = alias.user
|
||||||
|
|
||||||
|
if not user.is_active():
|
||||||
|
LOG.w(f"User {user} has been soft deleted")
|
||||||
|
return False, status.E502
|
||||||
|
|
||||||
if not user.can_send_or_receive():
|
if not user.can_send_or_receive():
|
||||||
LOG.i(f"User {user} cannot receive emails")
|
LOG.i(f"User {user} cannot receive emails")
|
||||||
if should_ignore_bounce(envelope.mail_from):
|
if should_ignore_bounce(envelope.mail_from):
|
||||||
@ -1055,6 +1060,9 @@ def handle_reply(envelope, msg: Message, rcpt_to: str) -> (bool, str):
|
|||||||
if not contact:
|
if not contact:
|
||||||
LOG.w(f"No contact with {reply_email} as reverse alias")
|
LOG.w(f"No contact with {reply_email} as reverse alias")
|
||||||
return False, status.E502
|
return False, status.E502
|
||||||
|
if not contact.user.is_active():
|
||||||
|
LOG.w(f"User {contact.user} has been soft deleted")
|
||||||
|
return False, status.E502
|
||||||
|
|
||||||
alias = contact.alias
|
alias = contact.alias
|
||||||
alias_address: str = contact.alias.email
|
alias_address: str = contact.alias.email
|
||||||
@ -1921,6 +1929,9 @@ def handle_bounce(envelope, email_log: EmailLog, msg: Message) -> str:
|
|||||||
contact,
|
contact,
|
||||||
alias,
|
alias,
|
||||||
)
|
)
|
||||||
|
if not email_log.user.is_active():
|
||||||
|
LOG.d(f"User {email_log.user} is not active")
|
||||||
|
return status.E510
|
||||||
|
|
||||||
if email_log.is_reply:
|
if email_log.is_reply:
|
||||||
content_type = msg.get_content_type().lower()
|
content_type = msg.get_content_type().lower()
|
||||||
@ -1982,6 +1993,9 @@ def send_no_reply_response(mail_from: str, msg: Message):
|
|||||||
if not mailbox:
|
if not mailbox:
|
||||||
LOG.d("Unknown sender. Skipping reply from {}".format(NOREPLY))
|
LOG.d("Unknown sender. Skipping reply from {}".format(NOREPLY))
|
||||||
return
|
return
|
||||||
|
if not mailbox.user.is_active():
|
||||||
|
LOG.d(f"User {mailbox.user} is soft-deleted. Skipping sending reply response")
|
||||||
|
return
|
||||||
send_email_at_most_times(
|
send_email_at_most_times(
|
||||||
mailbox.user,
|
mailbox.user,
|
||||||
ALERT_TO_NOREPLY,
|
ALERT_TO_NOREPLY,
|
||||||
|
|||||||
@ -7460,9 +7460,7 @@ villain
|
|||||||
vindicate
|
vindicate
|
||||||
vineyard
|
vineyard
|
||||||
vintage
|
vintage
|
||||||
violate
|
|
||||||
violation
|
violation
|
||||||
violator
|
|
||||||
violet
|
violet
|
||||||
violin
|
violin
|
||||||
viper
|
viper
|
||||||
|
|||||||
53
app/oneshot/replace_noreply_in_cotnacts.py
Normal file
53
app/oneshot/replace_noreply_in_cotnacts.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import argparse
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
from app import config
|
||||||
|
from app.email_utils import generate_reply_email
|
||||||
|
from app.email_validation import is_valid_email
|
||||||
|
from app.models import Alias
|
||||||
|
from app.db import Session
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
prog=f"Replace {config.NOREPLY}",
|
||||||
|
description=f"Replace {config.NOREPLY} from contacts reply email",
|
||||||
|
)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
el_query = "SELECT id, alias_id, website_email from contact where id>=:last_id AND reply_email=:reply_email ORDER BY id ASC LIMIT :step"
|
||||||
|
update_query = "UPDATE contact SET reply_email=:reply_email WHERE id=:contact_id "
|
||||||
|
updated = 0
|
||||||
|
start_time = time.time()
|
||||||
|
step = 100
|
||||||
|
last_id = 0
|
||||||
|
print(f"Replacing contacts with reply_email={config.NOREPLY}")
|
||||||
|
while True:
|
||||||
|
rows = Session.execute(
|
||||||
|
el_query, {"last_id": last_id, "reply_email": config.NOREPLY, "step": step}
|
||||||
|
)
|
||||||
|
loop_updated = 0
|
||||||
|
for row in rows:
|
||||||
|
contact_id = row[0]
|
||||||
|
alias_id = row[1]
|
||||||
|
last_id = contact_id
|
||||||
|
website_email = row[2]
|
||||||
|
contact_email_for_reply = website_email if is_valid_email(website_email) else ""
|
||||||
|
alias = Alias.get(alias_id)
|
||||||
|
if alias is None:
|
||||||
|
print(f"CANNOT find alias {alias_id} in database for contact {contact_id}")
|
||||||
|
reply_email = generate_reply_email(contact_email_for_reply, alias)
|
||||||
|
print(
|
||||||
|
f"Replacing contact {contact_id} with {website_email} reply_email for {reply_email}"
|
||||||
|
)
|
||||||
|
Session.execute(
|
||||||
|
update_query, {"contact_id": row[0], "reply_email": reply_email}
|
||||||
|
)
|
||||||
|
Session.commit()
|
||||||
|
updated += 1
|
||||||
|
loop_updated += 1
|
||||||
|
elapsed = time.time() - start_time
|
||||||
|
print(f"\rContact {last_id} done")
|
||||||
|
if loop_updated == 0:
|
||||||
|
break
|
||||||
|
print("")
|
||||||
@ -228,6 +228,8 @@ def load_user(alternative_id):
|
|||||||
sentry_sdk.set_user({"email": user.email, "id": user.id})
|
sentry_sdk.set_user({"email": user.email, "id": user.id})
|
||||||
if user.disabled:
|
if user.disabled:
|
||||||
return None
|
return None
|
||||||
|
if not user.is_active():
|
||||||
|
return None
|
||||||
|
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|||||||
@ -6,16 +6,27 @@ from tests.utils import create_new_user
|
|||||||
|
|
||||||
|
|
||||||
def test_unactivated_user_login(flask_client):
|
def test_unactivated_user_login(flask_client):
|
||||||
user = create_new_user()
|
"""
|
||||||
user.activated = False
|
Test function for logging in with an unactivated user.
|
||||||
Session.commit()
|
|
||||||
|
|
||||||
|
Steps:
|
||||||
|
1. Creates a new user.
|
||||||
|
2. Sets the user's activated status to False.
|
||||||
|
3. Sends a POST request to the login route with user credentials.
|
||||||
|
4. Checks the response status code and content for expected messages.
|
||||||
|
"""
|
||||||
|
user = create_new_user() # Creating a new user
|
||||||
|
user.activated = False # Setting the user's activated status to False
|
||||||
|
Session.commit() # Committing the session changes
|
||||||
|
|
||||||
|
# Sending a POST request to the login route with user credentials and following redirects
|
||||||
r = flask_client.post(
|
r = flask_client.post(
|
||||||
url_for("auth.login"),
|
url_for("auth.login"),
|
||||||
data={"email": user.email, "password": "password"},
|
data={"email": user.email, "password": "password"},
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Asserting the response status code and content for expected messages
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert (
|
assert (
|
||||||
b"Please check your inbox for the activation email. You can also have this email re-sent"
|
b"Please check your inbox for the activation email. You can also have this email re-sent"
|
||||||
@ -24,59 +35,98 @@ def test_unactivated_user_login(flask_client):
|
|||||||
|
|
||||||
|
|
||||||
def test_non_canonical_login(flask_client):
|
def test_non_canonical_login(flask_client):
|
||||||
email = f"pre.{random_string(10)}@gmail.com"
|
"""
|
||||||
name = f"NAME-{random_string(10)}"
|
Test function for logging in with a non-canonical email.
|
||||||
user = create_new_user(email, name)
|
|
||||||
Session.commit()
|
|
||||||
|
|
||||||
|
Steps:
|
||||||
|
1. Creates a new user with a non-canonical email.
|
||||||
|
2. Sends a POST request to the login route with user credentials.
|
||||||
|
3. Checks the response status code and content for expected messages.
|
||||||
|
4. Checks the canonicalization of the email.
|
||||||
|
5. Logs out the user.
|
||||||
|
6. Sends a POST request to the login route with the canonicalized email.
|
||||||
|
7. Checks the response status code and content for expected messages.
|
||||||
|
"""
|
||||||
|
email = f"pre.{random_string(10)}@gmail.com" # Generating a non-canonical email
|
||||||
|
name = f"NAME-{random_string(10)}" # Generating a random name
|
||||||
|
user = create_new_user(
|
||||||
|
email, name
|
||||||
|
) # Creating a new user with the generated email and name
|
||||||
|
Session.commit() # Committing the session changes
|
||||||
|
|
||||||
|
# Sending a POST request to the login route with user credentials and following redirects
|
||||||
r = flask_client.post(
|
r = flask_client.post(
|
||||||
url_for("auth.login"),
|
url_for("auth.login"),
|
||||||
data={"email": user.email, "password": "password"},
|
data={"email": user.email, "password": "password"},
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Asserting the response status code and content for expected messages
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert name.encode("utf-8") in r.data
|
assert name.encode("utf-8") in r.data
|
||||||
|
|
||||||
|
# Canonicalizing the email
|
||||||
canonical_email = canonicalize_email(email)
|
canonical_email = canonicalize_email(email)
|
||||||
assert canonical_email != email
|
assert (
|
||||||
|
canonical_email != email
|
||||||
|
) # Checking if the canonical email is different from the original email
|
||||||
|
|
||||||
flask_client.get(url_for("auth.logout"))
|
flask_client.get(url_for("auth.logout")) # Logging out the user
|
||||||
|
|
||||||
|
# Sending a POST request to the login route with the canonicalized email and following redirects
|
||||||
r = flask_client.post(
|
r = flask_client.post(
|
||||||
url_for("auth.login"),
|
url_for("auth.login"),
|
||||||
data={"email": canonical_email, "password": "password"},
|
data={"email": canonical_email, "password": "password"},
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Asserting the response status code and content for expected messages
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert name.encode("utf-8") not in r.data
|
assert name.encode("utf-8") not in r.data
|
||||||
|
|
||||||
|
|
||||||
def test_canonical_login_with_non_canonical_email(flask_client):
|
def test_canonical_login_with_non_canonical_email(flask_client):
|
||||||
suffix = f"{random_string(10)}@gmail.com"
|
"""
|
||||||
canonical_email = f"pre{suffix}"
|
Test function for logging in with a canonical email and a non-canonical email.
|
||||||
non_canonical_email = f"pre.{suffix}"
|
|
||||||
name = f"NAME-{random_string(10)}"
|
|
||||||
create_new_user(canonical_email, name)
|
|
||||||
Session.commit()
|
|
||||||
|
|
||||||
|
Steps:
|
||||||
|
1. Generates canonical and non-canonical email addresses.
|
||||||
|
2. Creates a new user with the canonical email.
|
||||||
|
3. Sends a POST request to the login route with the non-canonical email.
|
||||||
|
4. Checks the response status code and content for expected messages.
|
||||||
|
5. Logs out the user.
|
||||||
|
6. Sends a POST request to the login route with the canonical email.
|
||||||
|
7. Checks the response status code and content for expected messages.
|
||||||
|
"""
|
||||||
|
suffix = f"{random_string(10)}@gmail.com" # Generating a random suffix for emails
|
||||||
|
canonical_email = f"pre{suffix}" # Generating a canonical email
|
||||||
|
non_canonical_email = f"pre.{suffix}" # Generating a non-canonical email
|
||||||
|
name = f"NAME-{random_string(10)}" # Generating a random name
|
||||||
|
create_new_user(
|
||||||
|
canonical_email, name
|
||||||
|
) # Creating a new user with the canonical email
|
||||||
|
Session.commit() # Committing the session changes
|
||||||
|
|
||||||
|
# Sending a POST request to the login route with the non-canonical email and following redirects
|
||||||
r = flask_client.post(
|
r = flask_client.post(
|
||||||
url_for("auth.login"),
|
url_for("auth.login"),
|
||||||
data={"email": non_canonical_email, "password": "password"},
|
data={"email": non_canonical_email, "password": "password"},
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Asserting the response status code and content for expected messages
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert name.encode("utf-8") in r.data
|
assert name.encode("utf-8") in r.data
|
||||||
|
|
||||||
flask_client.get(url_for("auth.logout"))
|
flask_client.get(url_for("auth.logout")) # Logging out the user
|
||||||
|
|
||||||
|
# Sending a POST request to the login route with the canonical email and following redirects
|
||||||
r = flask_client.post(
|
r = flask_client.post(
|
||||||
url_for("auth.login"),
|
url_for("auth.login"),
|
||||||
data={"email": canonical_email, "password": "password"},
|
data={"email": canonical_email, "password": "password"},
|
||||||
follow_redirects=True,
|
follow_redirects=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Asserting the response status code and content for expected messages
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert name.encode("utf-8") in r.data
|
assert name.encode("utf-8") in r.data
|
||||||
|
|||||||
@ -39,15 +39,17 @@ def test_cleanup_tokens(flask_client):
|
|||||||
|
|
||||||
def test_cleanup_users():
|
def test_cleanup_users():
|
||||||
u_delete_none_id = create_new_user().id
|
u_delete_none_id = create_new_user().id
|
||||||
u_delete_after = create_new_user()
|
u_delete_grace_has_expired = create_new_user()
|
||||||
u_delete_after_id = u_delete_after.id
|
u_delete_grace_has_expired_id = u_delete_grace_has_expired.id
|
||||||
u_delete_before = create_new_user()
|
u_delete_grace_has_not_expired = create_new_user()
|
||||||
u_delete_before_id = u_delete_before.id
|
u_delete_grace_has_not_expired_id = u_delete_grace_has_not_expired.id
|
||||||
now = arrow.now()
|
now = arrow.now()
|
||||||
u_delete_after.delete_on = now.shift(minutes=1)
|
u_delete_grace_has_expired.delete_on = now.shift(days=-(cron.DELETE_GRACE_DAYS + 1))
|
||||||
u_delete_before.delete_on = now.shift(minutes=-1)
|
u_delete_grace_has_not_expired.delete_on = now.shift(
|
||||||
|
days=-(cron.DELETE_GRACE_DAYS - 1)
|
||||||
|
)
|
||||||
Session.flush()
|
Session.flush()
|
||||||
cron.clear_users_scheduled_to_be_deleted()
|
cron.clear_users_scheduled_to_be_deleted()
|
||||||
assert User.get(u_delete_none_id) is not None
|
assert User.get(u_delete_none_id) is not None
|
||||||
assert User.get(u_delete_after_id) is not None
|
assert User.get(u_delete_grace_has_not_expired_id) is not None
|
||||||
assert User.get(u_delete_before_id) is None
|
assert User.get(u_delete_grace_has_expired_id) is None
|
||||||
|
|||||||
Reference in New Issue
Block a user