1
0
mirror of https://github.com/Mailu/Mailu.git synced 2024-12-14 10:53:30 +02:00
Mailu/core/admin/mailu/ui/forms.py

174 lines
6.8 KiB
Python
Raw Normal View History

2016-03-19 21:37:48 +02:00
from wtforms import validators, fields, widgets
from wtforms_components import fields as fields_
2016-10-02 14:37:06 +02:00
from flask_babel import lazy_gettext as _
2016-08-13 20:51:54 +02:00
import flask_login
import flask_wtf
import re
LOCALPART_REGEX = "^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+$"
class DestinationField(fields.SelectMultipleField):
""" Allow for multiple emails selection from current user choices and
additional email addresses.
"""
validator = re.compile(r'^.+@([^.@][^@]+)$', re.IGNORECASE)
def iter_choices(self):
managed = [
str(email)
for email in flask_login.current_user.get_managed_emails()
]
for email in managed:
selected = self.data is not None and self.coerce(email) in self.data
yield (email, email, selected)
for email in self.data or ():
if email not in managed:
yield (email, email, True)
def pre_validate(self, form):
for item in self.data:
if not self.validator.match(item):
2016-10-02 14:37:06 +02:00
raise validators.ValidationError(_('Invalid email address.'))
2016-03-19 21:37:48 +02:00
2016-10-02 14:53:01 +02:00
class ConfirmationForm(flask_wtf.FlaskForm):
2016-10-02 14:37:06 +02:00
submit = fields.SubmitField(_('Confirm'))
class LoginForm(flask_wtf.FlaskForm):
2016-10-02 14:37:06 +02:00
email = fields.StringField(_('E-mail'), [validators.Email()])
pw = fields.PasswordField(_('Password'), [validators.DataRequired()])
submit = fields.SubmitField(_('Sign in'))
2016-03-19 21:37:48 +02:00
class DomainForm(flask_wtf.FlaskForm):
2016-10-02 14:37:06 +02:00
name = fields.StringField(_('Domain name'), [validators.DataRequired()])
max_users = fields_.IntegerField(_('Maximum user count'), default=10)
max_aliases = fields_.IntegerField(_('Maximum alias count'), default=10)
max_quota_bytes = fields_.IntegerSliderField(_('Maximum user quota'), default=0)
2017-12-03 13:01:25 +02:00
signup_enabled = fields.BooleanField(_('Enable sign-up'), default=False)
2016-10-02 14:37:06 +02:00
comment = fields.StringField(_('Comment'))
submit = fields.SubmitField(_('Save'))
2016-03-19 21:37:48 +02:00
2018-04-18 20:31:32 +02:00
class DomainSignupForm(flask_wtf.FlaskForm):
name = fields.StringField(_('Domain name'), [validators.DataRequired()])
localpart = fields.StringField(_('Initial admin'), [validators.DataRequired()])
pw = fields.PasswordField(_('Admin password'), [validators.DataRequired()])
pw2 = fields.PasswordField(_('Confirm password'), [validators.EqualTo('pw')])
captcha = flask_wtf.RecaptchaField()
submit = fields.SubmitField(_('Create'))
class AlternativeForm(flask_wtf.FlaskForm):
name = fields.StringField(_('Alternative name'), [validators.DataRequired()])
submit = fields.SubmitField(_('Save'))
class RelayForm(flask_wtf.FlaskForm):
name = fields.StringField(_('Relayed domain name'), [validators.DataRequired()])
smtp = fields.StringField(_('Remote host'))
comment = fields.StringField(_('Comment'))
submit = fields.SubmitField(_('Save'))
class UserForm(flask_wtf.FlaskForm):
localpart = fields.StringField(_('E-mail'), [validators.DataRequired(), validators.Regexp(LOCALPART_REGEX)])
2016-10-02 14:37:06 +02:00
pw = fields.PasswordField(_('Password'), [validators.DataRequired()])
pw2 = fields.PasswordField(_('Confirm password'), [validators.EqualTo('pw')])
quota_bytes = fields_.IntegerSliderField(_('Quota'), default=1000000000)
enable_imap = fields.BooleanField(_('Allow IMAP access'), default=True)
enable_pop = fields.BooleanField(_('Allow POP3 access'), default=True)
comment = fields.StringField(_('Comment'))
2018-04-15 11:35:37 +02:00
enabled = fields.BooleanField(_('Enabled'), default=True)
2016-10-02 14:37:06 +02:00
submit = fields.SubmitField(_('Save'))
2016-03-19 21:37:48 +02:00
2017-12-03 13:01:25 +02:00
class UserSignupForm(flask_wtf.FlaskForm):
localpart = fields.StringField(_('Email address'), [validators.DataRequired(), validators.Regexp(LOCALPART_REGEX)])
2017-12-03 13:01:25 +02:00
pw = fields.PasswordField(_('Password'), [validators.DataRequired()])
pw2 = fields.PasswordField(_('Confirm password'), [validators.EqualTo('pw')])
2018-04-11 21:08:44 +02:00
captcha = flask_wtf.RecaptchaField()
2017-12-03 13:01:25 +02:00
submit = fields.SubmitField(_('Sign up'))
class UserSettingsForm(flask_wtf.FlaskForm):
2016-10-02 14:37:06 +02:00
displayed_name = fields.StringField(_('Displayed name'))
spam_enabled = fields.BooleanField(_('Enable spam filter'))
spam_threshold = fields_.IntegerSliderField(_('Spam filter tolerance'))
forward_enabled = fields.BooleanField(_('Enable forwarding'))
forward_keep = fields.BooleanField(_('Keep a copy of the emails'))
forward_destination = fields.StringField(
_('Destination'), [validators.Optional(), validators.Email()]
)
2016-10-02 14:37:06 +02:00
submit = fields.SubmitField(_('Save settings'))
2016-03-20 12:09:06 +02:00
class UserPasswordForm(flask_wtf.FlaskForm):
2016-10-02 14:37:06 +02:00
pw = fields.PasswordField(_('Password'), [validators.DataRequired()])
pw2 = fields.PasswordField(_('Password check'), [validators.DataRequired()])
submit = fields.SubmitField(_('Update password'))
2016-03-19 21:37:48 +02:00
class UserReplyForm(flask_wtf.FlaskForm):
2016-10-02 14:37:06 +02:00
reply_enabled = fields.BooleanField(_('Enable automatic reply'))
reply_subject = fields.StringField(_('Reply subject'))
reply_body = fields.StringField(_('Reply body'),
widget=widgets.TextArea())
reply_enddate = fields.html5.DateField(_('End of vacation'))
2016-10-02 14:37:06 +02:00
submit = fields.SubmitField(_('Update'))
class TokenForm(flask_wtf.FlaskForm):
2017-10-29 16:39:01 +02:00
displayed_password = fields.StringField(
_('Your token (write it down, as it will never be displayed again)')
)
2017-10-29 16:39:01 +02:00
raw_password = fields.HiddenField([validators.DataRequired()])
comment = fields.StringField(_('Comment'))
ip = fields.StringField(
_('Authorized IP'), [validators.Optional(), validators.IPAddress()]
)
submit = fields.SubmitField(_('Save'))
class AliasForm(flask_wtf.FlaskForm):
2016-10-02 14:37:06 +02:00
localpart = fields.StringField(_('Alias'), [validators.DataRequired()])
2016-08-15 21:01:53 +02:00
wildcard = fields.BooleanField(
2016-10-02 14:37:06 +02:00
_('Use SQL LIKE Syntax (e.g. for catch-all aliases)'))
destination = DestinationField(_('Destination'))
comment = fields.StringField(_('Comment'))
submit = fields.SubmitField(_('Save'))
2016-04-24 19:17:40 +02:00
class AdminForm(flask_wtf.FlaskForm):
2016-10-02 14:37:06 +02:00
admin = fields.SelectField(_('Admin email'), choices=[])
submit = fields.SubmitField(_('Submit'))
2016-04-24 19:17:40 +02:00
class ManagerForm(flask_wtf.FlaskForm):
2016-10-02 14:37:06 +02:00
manager = fields.SelectField(_('Manager email'))
submit = fields.SubmitField(_('Submit'))
2016-04-28 20:07:38 +02:00
class FetchForm(flask_wtf.FlaskForm):
2016-10-02 14:37:06 +02:00
protocol = fields.SelectField(_('Protocol'), choices=[
2016-04-28 20:07:38 +02:00
('imap', 'IMAP'), ('pop3', 'POP3')
])
2016-10-02 14:37:06 +02:00
host = fields.StringField(_('Hostname or IP'))
port = fields.IntegerField(_('TCP port'))
tls = fields.BooleanField(_('Enable TLS'))
username = fields.StringField(_('Username'))
password = fields.StringField(_('Password'))
2017-02-02 23:45:43 +02:00
keep = fields.BooleanField(_('Keep emails on the server'))
2016-10-02 14:37:06 +02:00
submit = fields.SubmitField(_('Submit'))
2016-11-10 11:48:37 +02:00
class AnnouncementForm(flask_wtf.FlaskForm):
announcement_subject = fields.StringField(_('Announcement subject'),
[validators.DataRequired()])
announcement_body = fields.StringField(_('Announcement body'),
[validators.DataRequired()], widget=widgets.TextArea())
submit = fields.SubmitField(_('Send'))