mirror of
https://github.com/Mailu/Mailu.git
synced 2025-01-26 03:52:50 +02:00
Use SQLAlchemy Session.get instead of filter_by
This commit is contained in:
parent
3eca6864c3
commit
d3b13c2412
@ -13,7 +13,7 @@ from freeposte.admin import models
|
||||
|
||||
# Register the login components
|
||||
login_manager.login_view = "admin.login"
|
||||
login_manager.user_loader(models.User.get_by_email)
|
||||
login_manager.user_loader(models.User.query.get)
|
||||
|
||||
@app.context_processor
|
||||
def inject_user():
|
||||
|
@ -70,10 +70,6 @@ class Email(Base):
|
||||
primary_key=True, nullable=False,
|
||||
default=updater)
|
||||
|
||||
@classmethod
|
||||
def get_by_email(cls, email):
|
||||
return cls.query.filter_by(email=email).first()
|
||||
|
||||
def __str__(self):
|
||||
return self.email
|
||||
|
||||
@ -134,7 +130,7 @@ class User(Email):
|
||||
|
||||
@classmethod
|
||||
def login(cls, email, password):
|
||||
user = cls.get_by_email(email)
|
||||
user = cls.query.get(email)
|
||||
return user if (user and user.check_password(password)) else None
|
||||
|
||||
|
||||
|
@ -5,7 +5,7 @@ import flask
|
||||
|
||||
|
||||
def get_domain_admin(domain_name):
|
||||
domain = models.Domain.query.filter_by(name=domain_name).first()
|
||||
domain = models.Domain.query.get(domain_name)
|
||||
if not domain:
|
||||
flask.abort(404)
|
||||
if not domain in flask_login.current_user.get_managed_domains():
|
||||
@ -22,7 +22,7 @@ def get_user(user_email, admin=False):
|
||||
if user_email is None:
|
||||
user = flask_login.current_user
|
||||
else:
|
||||
user = models.User.get_by_email(user_email)
|
||||
user = models.User.query.get(user_email)
|
||||
if not user:
|
||||
flask.abort(404)
|
||||
if not user.domain in flask_login.current_user.get_managed_domains():
|
||||
@ -34,7 +34,7 @@ def get_user(user_email, admin=False):
|
||||
|
||||
|
||||
def get_alias(alias):
|
||||
alias = models.Alias.get_by_email(alias)
|
||||
alias = models.Alias.query.get(alias)
|
||||
if not alias:
|
||||
flask.abort(404)
|
||||
if not alias.domain in flask_login.current_user.get_managed_domains():
|
||||
@ -43,7 +43,7 @@ def get_alias(alias):
|
||||
|
||||
|
||||
def get_fetch(fetch_id):
|
||||
fetch = models.Fetch.query.filter_by(id=fetch_id).first()
|
||||
fetch = models.Fetch.query.get(fetch_id)
|
||||
if not fetch:
|
||||
flask.abort(404)
|
||||
if not fetch.user.domain in flask_login.current_user.get_managed_domains():
|
||||
|
@ -19,7 +19,7 @@ def admin_list():
|
||||
def admin_create():
|
||||
form = forms.AdminForm()
|
||||
if form.validate_on_submit():
|
||||
user = models.User.query.filter_by(email=form.admin.data).first()
|
||||
user = models.User.query.get(form.admin.data)
|
||||
if user:
|
||||
user.global_admin = True
|
||||
db.session.add(user)
|
||||
@ -34,7 +34,7 @@ def admin_create():
|
||||
@app.route('/admin/delete/<admin>', methods=['GET'])
|
||||
@flask_login.login_required
|
||||
def admin_delete(admin):
|
||||
user = models.User.query.filter_by(email=admin).first()
|
||||
user = models.User.query.get(admin)
|
||||
if user:
|
||||
user.global_admin = False
|
||||
db.session.add(user)
|
||||
|
@ -18,7 +18,7 @@ def domain_create():
|
||||
utils.require_global_admin()
|
||||
form = forms.DomainForm()
|
||||
if form.validate_on_submit():
|
||||
if models.Domain.query.filter_by(name=form.name.data).first():
|
||||
if models.Domain.query.get(form.name.data):
|
||||
flask.flash('Domain %s is already used' % form.name.data, 'error')
|
||||
else:
|
||||
domain = models.Domain(name=form.name.data)
|
||||
|
Loading…
x
Reference in New Issue
Block a user