Beispiel #1
0
class ForgotPasswordForm(Form, EmailFormMixin):
    "  The default forgot password form. "

    submit = SubmitField(_("Recover Password"))

    def to_dict(self):
        return dict(email=self.email.data)
Beispiel #2
0
class MemberForm(Form):

    name = TextField(_("Name"), validators=[Required()])
    weight = CommaDecimalField(_("Weight"), default=1)
    submit = SubmitField(_("Add"))

    def __init__(self, project, edit=False, *args, **kwargs):
        super(MemberForm, self).__init__(*args, **kwargs)
        self.project = project
        self.edit = edit

    def validate_name(form, field):
        if field.data == form.name.default:
            raise ValidationError(_("User name incorrect"))
        if (not form.edit and Person.query.filter(
                Person.name == field.data, Person.project == form.project,
                Person.activated == True).all()):
            raise ValidationError(_("This project already have this member"))

    def save(self, project, person):
        # if the user is already bound to the project, just reactivate him
        person.name = self.name.data
        person.project = project
        person.weight = self.weight.data

        return person

    def fill(self, member):
        self.name.data = member.name
        self.weight.data = member.weight
Beispiel #3
0
class PasswordReminder(Form):
    id = TextField(_("Project identifier"), validators=[Required()])
    submit = SubmitField(_("Send me the code by email"))

    def validate_id(form, field):
        if not Project.query.get(field.data):
            raise ValidationError(_("This project does not exists"))
Beispiel #4
0
class LoginForm(Form):
    def __init__(self, *args, **kwargs):
        Form.__init__(self, *args, **kwargs)
        self.user = None

    login = TextField(u'Login', validators=[
        validators.required(),
    ])
    password = PasswordField(u'Password', validators=[
        validators.required(),
    ])
    remember = BooleanField(u'Remember me')
    submit = SubmitField(u'Validate')

    def validate(self):
        rv = Form.validate(self)
        if not rv:
            return False

        pseudo = self.login.data
        password = self.password.data

        try:
            user_exists(self, self.login)
            user = check_password(pseudo, password)
            if user is None:
                self.password.errors.append('Wrong password.')
                return False
        except ValidationError:
            self.login.errors.append('Unknow user.')
            return False

        self.user = user

        return True
Beispiel #5
0
class ChangePasswordForm(Form, PasswordFormMixin):
    """The default change password form"""

    new_password = PasswordField(
        get_form_field_label('new_password'),
        validators=[password_required,
                    Length(min=6, max=128)])

    new_password_confirm = PasswordField(
        get_form_field_label('retype_password'),
        validators=[
            EqualTo('new_password', message='RETYPE_PASSWORD_MISMATCH')
        ])

    submit = SubmitField(get_form_field_label('change_password'))

    def validate(self):
        if not super(ChangePasswordForm, self).validate():
            return False

        if self.password.data.strip() == '':
            self.password.errors.append(
                get_message('PASSWORD_NOT_PROVIDED')[0])
            return False
        if not verify_and_update_password(self.password.data, current_user):
            self.password.errors.append(get_message('INVALID_PASSWORD')[0])
            return False
        return True
Beispiel #6
0
class BookmarkForm(AjaxForm):
    id = HiddenField(u'Id')
    link = URLField(u'Link',
                    validators=[
                        validators.required(),
                        validators.url(),
                    ])
    title = TextField(u'Title', validators=[
        validators.required(),
    ])
    description = TextAreaField(u'Description')
    tags = TextField(u'Tags')
    submit = SubmitField(u'Add')
    edit = SubmitField(u'Edit')

    def __init__(self, formdata=None, *args, **kwargs):
        self.id.data = kwargs.get('id', None)
        super(BookmarkForm, self).__init__(formdata, *args, **kwargs)

    def validate(self):
        rv = Form.validate(self)
        if not rv:
            return False

        _id = self.id.data
        link = self.link.data
        title = self.title.data
        description = self.description.data
        tags = map(lambda x: {'name': x.strip()}, self.tags.data.split(','))

        if _id is None or _id == '' or int(_id) < 1:
            self.bookmark = ItemBookmark(tags=tags,
                                         link=link,
                                         title=title,
                                         description=description)
        else:
            self.bookmark = get_bookmark_by_id(_id)
            if self.bookmark is None:
                abort(404)
            self.bookmark.title = title
            self.bookmark.description = description
            self.bookmark.set_tags(tags)

        return True
Beispiel #7
0
class InviteForm(Form):
    emails = TextAreaField(_("People to notify"))
    submit = SubmitField(_("Send invites"))

    def validate_emails(form, field):
        validator = Email()
        for email in [email.strip() for email in form.emails.data.split(",")]:
            if not validator.regex.match(email):
                raise ValidationError(
                    _("The email %(email)s is not valid", email=email))
Beispiel #8
0
class RegisterFormMixin():
    submit = SubmitField(get_form_field_label('register'))

    def to_dict(form):
        def is_field_and_user_attr(member):
            return isinstance(member, Field) and \
                hasattr(_datastore.user_model, member.name)

        fields = inspect.getmembers(form, is_field_and_user_attr)
        return dict((key, value.data) for key, value in fields)
Beispiel #9
0
class LoginForm(Form, EmailFormMixin, PasswordFormMixin):
    " The default login form. "

    remember = BooleanField(_("Remember Me"), default=True)
    next = HiddenField()
    submit = SubmitField(_("Login"))

    def __init__(self, *args, **kwargs):
        super(LoginForm, self).__init__(*args, **kwargs)

        if request.method == 'GET':
            self.next.data = request.args.get('next', None)
Beispiel #10
0
class PasswordlessLoginForm(Form, UserEmailFormMixin):
    """The passwordless login form"""

    submit = SubmitField(get_form_field_label('send_login_link'))

    def __init__(self, *args, **kwargs):
        super(PasswordlessLoginForm, self).__init__(*args, **kwargs)

    def validate(self):
        if not super(PasswordlessLoginForm, self).validate():
            return False
        if not self.user.is_active():
            self.email.errors.append(get_message('DISABLED_ACCOUNT')[0])
            return False
        return True
Beispiel #11
0
class BillForm(Form):
    date = DateField(_("Date"), validators=[Required()], default=datetime.now)
    what = TextField(_("What?"), validators=[Required()])
    payer = SelectField(_("Payer"), validators=[Required()], coerce=int)
    amount = CommaDecimalField(_("Amount paid"), validators=[Required()])
    payed_for = SelectMultipleField(_("For whom?"),
                                    validators=[Required()],
                                    widget=select_multi_checkbox,
                                    coerce=int)
    submit = SubmitField(_("Submit"))
    submit2 = SubmitField(_("Submit and add a new one"))

    def save(self, bill, project):
        bill.payer_id = self.payer.data
        bill.amount = self.amount.data
        bill.what = self.what.data
        bill.date = self.date.data
        bill.owers = [
            Person.query.get(ower, project) for ower in self.payed_for.data
        ]

        return bill

    def fill(self, bill):
        self.payer.data = bill.payer_id
        self.amount.data = bill.amount
        self.what.data = bill.what
        self.date.data = bill.date
        self.payed_for.data = [int(ower.id) for ower in bill.owers]

    def set_default(self):
        self.payed_for.data = self.payed_for.default

    def validate_amount(self, field):
        if field.data == 0:
            raise ValidationError(_("Bills can't be null"))
Beispiel #12
0
class ProjectForm(EditProjectForm):
    id = TextField(_("Project identifier"), validators=[Required()])
    password = PasswordField(_("Private code"), validators=[Required()])
    submit = SubmitField(_("Create the project"))

    def validate_id(form, field):
        form.id.data = slugify(field.data)
        if (form.id.data == "dashboard") or Project.query.get(form.id.data):
            raise ValidationError(
                Markup(
                    _("The project identifier is used "
                      "to log in and for the URL of the project. "
                      "We tried to generate an identifier for you but a project "
                      "with this identifier already exists. "
                      "Please create a new identifier "
                      "that you will be able to remember.")))
Beispiel #13
0
class SendConfirmationForm(Form, UserEmailFormMixin):
    """The default forgot password form"""

    submit = SubmitField(get_form_field_label('send_confirmation'))

    def __init__(self, *args, **kwargs):
        super(SendConfirmationForm, self).__init__(*args, **kwargs)
        if request.method == 'GET':
            self.email.data = request.args.get('email', None)

    def validate(self):
        if not super(SendConfirmationForm, self).validate():
            return False
        if self.user.confirmed_at is not None:
            self.email.errors.append(get_message('ALREADY_CONFIRMED')[0])
            return False
        return True
Beispiel #14
0
class StatForm(Form):
    stat = HiddenField('stat_select',
                       id='stat_select',
                       validators=[Required()])
    benchmarks = SelectMultipleField('benchmark_select',
                                     id='benchmark_select',
                                     validators=[Required()])
    runs = SelectMultipleField('run_select',
                               id='run_select',
                               validators=[Required()],
                               coerce=str)
    normalize = BooleanField('normalize',
                             id='normalize',
                             validators=[Required()])
    average = BooleanField('average', id='average', validators=[Required()])
    hmean = BooleanField('hmean', id='hmean', validators=[Required()])
    submit = SubmitField('Update', id='Update')
Beispiel #15
0
class ResetPasswordForm(Form, EmailFormMixin, PasswordFormMixin,
                        PasswordConfirmFormMixin):
    "  The default reset password form. "

    token = HiddenField(validators=[Required()])

    submit = SubmitField(_("Reset Password"))

    def __init__(self, *args, **kwargs):
        super(ResetPasswordForm, self).__init__(*args, **kwargs)

        if request.method == 'GET':
            self.token.data = request.args.get('token', None)
            self.email.data = request.args.get('email', None)

    def to_dict(self):
        return dict(token=self.token.data,
                    email=self.email.data,
                    password=self.password.data)
Beispiel #16
0
class RegisterForm(Form):
    login = TextField(u'Login',
                      validators=[
                          validators.required(),
                          unique_user,
                      ])
    password = PasswordField(
        u'Password',
        validators=[
            validators.required(),
            validators.length(min=app.config['MIN_PASSWORD_LENGTH']),
        ])
    password_confirmation = PasswordField(
        u'Password confirmation',
        validators=[
            validators.required(),
            validators.length(min=app.config['MIN_PASSWORD_LENGTH']),
        ])
    submit = SubmitField(u'Register')

    def __init__(self, *args, **kwargs):
        Form.__init__(self, *args, **kwargs)
        self.user = None

    def validate(self):
        rv = Form.validate(self)
        if not rv:
            return False

        pseudo = self.login.data
        password = self.password.data
        password_confirmation = self.password_confirmation.data

        if password != password_confirmation:
            self.password.errors.append('Passwords mismatch')
            self.password_confirmation.errors.append('Passwords mismatch')
            return False

        self.user = User(pseudo, password)

        return True
Beispiel #17
0
class LoginForm(Form, NextFormMixin):
    """The default login form"""

    email = TextField(get_form_field_label('email'))
    password = PasswordField(get_form_field_label('password'))
    remember = BooleanField(get_form_field_label('remember_me'))
    submit = SubmitField(get_form_field_label('login'))

    def __init__(self, *args, **kwargs):
        super(LoginForm, self).__init__(*args, **kwargs)

    def validate(self):
        if not super(LoginForm, self).validate():
            return False

        if self.email.data.strip() == '':
            self.email.errors.append(get_message('EMAIL_NOT_PROVIDED')[0])
            return False

        if self.password.data.strip() == '':
            self.password.errors.append(
                get_message('PASSWORD_NOT_PROVIDED')[0])
            return False

        self.user = _datastore.find_user(email=self.email.data)

        if self.user is None:
            self.email.errors.append(get_message('USER_DOES_NOT_EXIST')[0])
            return False
        if not verify_and_update_password(self.password.data, self.user):
            self.password.errors.append(get_message('INVALID_PASSWORD')[0])
            return False
        if requires_confirmation(self.user):
            self.email.errors.append(get_message('CONFIRMATION_REQUIRED')[0])
            return False
        if not self.user.is_active():
            self.email.errors.append(get_message('DISABLED_ACCOUNT')[0])
            return False
        return True
Beispiel #18
0
class ResetPasswordForm(Form, NewPasswordFormMixin, PasswordConfirmFormMixin):
    """The default reset password form"""

    submit = SubmitField(get_form_field_label('reset_password'))
Beispiel #19
0
class ForgotPasswordForm(Form, UserEmailFormMixin):
    """The default forgot password form"""

    submit = SubmitField(get_form_field_label('recover_password'))
class LoginForm(Form):
    username = TextField('username')
    password = PasswordField('password')
    submit = SubmitField('Login')
Beispiel #21
0
class AuthenticationForm(Form):
    id = TextField(_("Project identifier"), validators=[Required()])
    password = PasswordField(_("Private code"), validators=[Required()])
    submit = SubmitField(_("Get in"))
Beispiel #22
0
class ContactForm(Form):
	name = TextField("Name", [validators.required("Please enter your Name")])
	email = TextField("Email", [validators.required("Please enter your Email"), validators.Email()])
	subject = TextField("Subject", [validators.required("Please enter a Subject")])
	message = TextAreaField("Message", [validators.required("Please enter a Message")])
	submit = SubmitField("Send")