mirror of
https://github.com/simple-login/app.git
synced 2025-02-25 08:13:16 +08:00
Merge pull request #165 from simple-login/same-mailbox-different-user
Same mailbox different user
This commit is contained in:
commit
a785e664e9
4 changed files with 37 additions and 4 deletions
|
@ -64,7 +64,7 @@ def custom_alias():
|
|||
|
||||
# check if mailbox is not tempered with
|
||||
if mailbox_email != current_user.email:
|
||||
mailbox = Mailbox.get_by(email=mailbox_email)
|
||||
mailbox = Mailbox.get_by(email=mailbox_email, user_id=current_user.id)
|
||||
if not mailbox or mailbox.user_id != current_user.id:
|
||||
flash("Something went wrong, please retry", "warning")
|
||||
return redirect(url_for("dashboard.custom_alias"))
|
||||
|
@ -91,7 +91,7 @@ def custom_alias():
|
|||
"warning",
|
||||
)
|
||||
else:
|
||||
mailbox = Mailbox.get_by(email=mailbox_email)
|
||||
mailbox = Mailbox.get_by(email=mailbox_email, user_id=current_user.id)
|
||||
|
||||
alias = Alias.create(
|
||||
user_id=current_user.id,
|
||||
|
|
|
@ -376,7 +376,7 @@ def email_already_used(email: str) -> bool:
|
|||
|
||||
|
||||
def mailbox_already_used(email: str, user) -> bool:
|
||||
if Mailbox.get_by(email=email):
|
||||
if Mailbox.get_by(email=email, user_id=user.id):
|
||||
return True
|
||||
|
||||
# support the case user wants to re-add their real email as mailbox
|
||||
|
|
|
@ -1114,7 +1114,7 @@ class Job(db.Model, ModelMixin):
|
|||
|
||||
class Mailbox(db.Model, ModelMixin):
|
||||
user_id = db.Column(db.ForeignKey(User.id, ondelete="cascade"), nullable=False)
|
||||
email = db.Column(db.String(256), unique=True, nullable=False)
|
||||
email = db.Column(db.String(256), nullable=False)
|
||||
verified = db.Column(db.Boolean, default=False, nullable=False)
|
||||
|
||||
# used when user wants to update mailbox email
|
||||
|
@ -1123,6 +1123,8 @@ class Mailbox(db.Model, ModelMixin):
|
|||
pgp_public_key = db.Column(db.Text, nullable=True)
|
||||
pgp_finger_print = db.Column(db.String(512), nullable=True)
|
||||
|
||||
__table_args__ = (db.UniqueConstraint("user_id", "email", name="uq_mailbox_user"),)
|
||||
|
||||
def nb_alias(self):
|
||||
return Alias.filter_by(mailbox_id=self.id).count()
|
||||
|
||||
|
|
31
migrations/versions/2020_050721_925b93d92809_.py
Normal file
31
migrations/versions/2020_050721_925b93d92809_.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: 925b93d92809
|
||||
Revises: 026e7a782ed6
|
||||
Create Date: 2020-05-07 21:42:05.406865
|
||||
|
||||
"""
|
||||
import sqlalchemy_utils
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '925b93d92809'
|
||||
down_revision = '026e7a782ed6'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_unique_constraint('uq_mailbox_user', 'mailbox', ['user_id', 'email'])
|
||||
op.drop_constraint('mailbox_email_key', 'mailbox', type_='unique')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_unique_constraint('mailbox_email_key', 'mailbox', ['email'])
|
||||
op.drop_constraint('uq_mailbox_user', 'mailbox', type_='unique')
|
||||
# ### end Alembic commands ###
|
Loading…
Reference in a new issue