Beispiel #1
0
    def validate_on_submit(self):
        if not CustomForm.validate_on_submit(self):
            return self.validation_error()

        self.user = g.datastore.find_user(username=self.username.data)

        if self.user is None:
            self.user = g.datastore.find_user(email=self.username.data)

        if self.user is None:
            self.username.errors.append(
                current_app.config['SECURITY_MSG_USER_DOES_NOT_EXIST'][0])
            return self.validation_error()
        if not self.user.password:
            self.password.errors.append(
                current_app.config['SECURITY_MSG_PASSWORD_NOT_SET'][0])
            return self.validation_error()
        if not verify_and_update_password(self.password.data, self.user):
            self.password.errors.append(
                current_app.config['SECURITY_MSG_INVALID_PASSWORD'][0])
            return self.validation_error()
        if requires_confirmation(self.user):
            do_flash(*get_message('CONFIRMATION_REQUIRED'))
            return self.validation_error()
        if not self.user.is_active:
            do_flash(*current_app.config['SECURITY_MSG_DISABLED_ACCOUNT'])
            return self.validation_error()
        return self.validation_success()
Beispiel #2
0
    def validate_on_submit(self):
        if not CustomForm.validate_on_submit(self):
            return self.validation_error()

        if current_app.config['REGISTRATION_BY_INVITE_ONLY']:
            if not g.datastore.find_invitation_email(email=self.email.data):
                do_flash(
                    *current_app.config['MSG_REGISTRATION_BY_INVITE_ONLY'])
                return self.validation_error()

        user = g.datastore.find_user(email=self.email.data)
        if user:
            self.email.errors.append(current_app.config['MSG_EMAIL_CLAIMED'])
            return self.validation_error()
        user = g.datastore.find_user(username=self.username.data)
        if user:
            self.email.errors.append(
                current_app.config['MSG_USERNAME_CLAIMED'])
            return self.validation_error()
        if self.email.data:
            self.kwargs['email'] = self.email.data
        if self.password.data:
            self.kwargs['password'] = self.password.data
        if self.first_name.data:
            self.kwargs['first_name'] = self.first_name.data
        if self.last_name.data:
            self.kwargs['last_name'] = self.last_name.data
        if self.username.data:
            self.kwargs['username'] = self.username.data

        return self.validation_success()
Beispiel #3
0
 def validate_on_submit(self):
     if not CustomForm.validate_on_submit(self):
         return self.validation_error()
     self.faq = g.datastore.find_faq(id=self.faq_id.data)
     if not self.faq:
         self.faq_id.errors.append('Invalid FAQ')
         return self.validation_error()
     if self.order.data != self.faq.order:
         if g.datastore.find_faq(order=self.order.data):
             self.order.errors.append('That FAQ order is already assigned')
             return self.validation_error()
         self.kwargs.update({'order': self.order.data})
     if self.question.data != self.faq.question:
         self.kwargs.update({'question': self.question.data})
     if self.answer.data != self.faq.answer:
         self.kwargs.update({'answer': self.answer.data})
     if self.active.data == 'on':
         active = True
     else:
         active = False
     if active != self.faq.active:
         self.toggle_active = True
     if len(self.kwargs) == 0 and self.toggle_active is False:
         self.faq_id.errors.append(current_app.config['NO_DATA_CHANGED'])
         return self.validation_error()
     return self.validation_success()
Beispiel #4
0
 def validate_on_submit(self):
     if not CustomForm.validate_on_submit(self):
         return self.validation_error()
     self.kwargs.update({'title': remove_whitespace(self.title.data)})
     self.kwargs.update({'body': remove_whitespace(self.body.data)})
     self.kwargs.update({'user': current_user})
     return self.validation_success()
Beispiel #5
0
 def update_success(self):
     self.render_html.update({
         'post_html':
         render_template('blog/admin/post_list_collapse_row.html',
                         chevron='fa fa-chevron-down',
                         post=self.post)
     })
     return CustomForm.update_success(self)
Beispiel #6
0
 def validate_on_submit(self):
     if not CustomForm.validate_on_submit(self):
         return self.validation_error()
     self.user = current_user
     if self.username.data != self.user.username:
         self.kwargs.update({'username': self.username.data})
     if len(self.kwargs) == 0:
         self.username.errors.append(current_app.config['NO_DATA_CHANGED'])
         return self.validation_error()
     return self.validation_success()
Beispiel #7
0
 def validate_on_submit(self):
     self.submit.data = True  # TODO: remove this (means we need to have it submit via the form button, or set it via JS)
     if not CustomForm.validate_on_submit(self):
         return self.validation_error()
     try:
         decodestring(self.image.data)
     except Exception, e:
         current_app.logger.error('String was not valid base64: {}'.format(e))
         self.image_id.errors.append(current_app.config['GENERIC_FORM_ERROR_MESSAGE'])
         return self.validation_error()
Beispiel #8
0
 def validate_on_submit(self):
     if not CustomForm.validate_on_submit(self):
         return self.validation_error()
     if g.datastore.find_faq(order=self.order.data):
         self.order.errors.append('That FAQ order is already assigned')
         return self.validation_error()
     self.kwargs.update({'order': self.order.data})
     self.kwargs.update({'question': self.question.data})
     self.kwargs.update({'answer': self.answer.data})
     return self.validation_success()
Beispiel #9
0
    def validate_on_submit(self):
        if not CustomForm.validate_on_submit(self):
            return self.validation_error()

        self.user = g.datastore.find_user(email=self.email.data)
        if not self.user:
            do_flash(*current_app.config['SECURITY_MSG_USER_DOES_NOT_EXIST'])
            return self.validation_error()

        return self.validation_success()
Beispiel #10
0
 def validate_on_submit(self):
     if not CustomForm.validate_on_submit(self):
         return self.validation_error()
     if self.name.data:
         name_role = g.datastore.find_admin_role(name=self.name.data)
         if name_role:
             self.name.errors.append(current_app.config['MSG_ROLE_EXISTS'])
             return self.validation_error()
     self.kwargs.update({'name': self.name.data})
     self.kwargs.update({'description': self.description.data})
     return self.validation_success()
Beispiel #11
0
    def validate_on_submit(self):
        if not CustomForm.validate_on_submit(self):
            return self.validation_error()

        self.user = g.datastore.find_user(email=self.email.data)
        if not self.user:
            self.email.errors.append('Email Not Found')
            return self.validation_error()
        if requires_confirmation(self.user):
            do_flash(*get_message('CONFIRMATION_REQUIRED'))
            return self.validation_error()
        return self.update_success()
Beispiel #12
0
 def validate_on_submit(self):
     if not CustomForm.validate_on_submit(self):
         return self.validation_error()
     self.content = g.datastore.find_content(field_name=self.field_name.data, draft=True)
     if not self.content:
         self.field_name.errors.append(current_app.config['GENERIC_FORM_ERROR_MESSAGE'])
         return self.validation_error()
     if remove_whitespace(self.content_text.data) != remove_whitespace(self.content.text):
         self.kwargs.update({'text': remove_whitespace(self.content_text.data)})
     if len(self.kwargs) == 0:
         self.content_text.errors.append(current_app.config['NO_DATA_CHANGED'])
         return self.validation_error()
     return self.validation_success()
Beispiel #13
0
 def validate_on_submit(self):
     if not CustomForm.validate_on_submit(self):
         return self.validation_error()
     self.post = g.datastore.find_post(id=self.post_id.data)
     if not self.post:
         self.post_id.errors.append('Invalid post')
         return self.validation_error()
     if self.title.data != self.post.title:
         self.kwargs.update({'title': remove_whitespace(self.title.data)})
     if self.body.data != self.post.body:
         self.kwargs.update({'body': remove_whitespace(self.body.data)})
     if self.active.data != self.post.active:
         g.datastore.toggle_active(self.post)
     return self.validation_success()
Beispiel #14
0
    def validate_on_submit(self):
        if not CustomForm.validate_on_submit(self):
            return self.validation_error()
        self.user = g.datastore.find_user(id=self.user_id.data)
        if not self.user:
            self.user_id.errors.append('Invalid User')
            return self.validation_error()
        if self.username.data:
            username_user = g.datastore.find_user(username=self.username.data)
            if username_user and username_user.id != self.user.id:
                self.username.errors.append('This username has already been claimed')
                return self.validation_error()
        if self.email.data:
            email_user = g.datastore.find_user(email=self.email.data)
            if email_user and email_user.id != self.user.id:
                self.email.errors.append(current_app.config['MSG_EMAIL_CLAIMED'])
                return self.validation_error()

        if self.first_name.data != self.user.first_name:
            self.kwargs.update({'first_name': self.first_name.data})
        if self.last_name.data != self.user.last_name:
            self.kwargs.update({'last_name': self.last_name.data})
        if self.username.data != self.user.username:
            self.kwargs.update({'username': self.username.data})
        if self.email.data != self.user.email:
            self.kwargs.update({'email': self.email.data})
        if self.bio.data != self.user.bio:
            self.kwargs.update({'bio': self.bio.data})
        if self.active.data == 'on':
            active = True
        else:
            active = False
        if active != self.user.active:
            self.toggle_active = True
        if self.roles.data:
            role_list = []
            for role in self.roles.data.strip(',').split(','):
                role_obj = g.datastore.find_admin_role(name=role)
                if role_obj:
                    role_list.append(role_obj)
            if role_list != self.user.roles:
                self.kwargs.update({'roles': role_list})
        if len(self.kwargs) == 0 and self.toggle_active is False:
            self.user_id.errors.append(current_app.config['NO_DATA_CHANGED'])
            return self.validation_error()

        return self.validation_success()
Beispiel #15
0
 def validate_on_submit(self):
     if not CustomForm.validate_on_submit(self):
         return self.validation_error()
     self.user = current_user
     password = Password(password=self.new_password.data,
                         old_password=self.current_password.data,
                         user=current_user)
     if not password.verify_and_update():
         self.new_password.errors.append(password.error_list)
         return self.validation_error()
     if self.new_password.data.strip() == self.current_password.data.strip(
     ):
         self.current_password.errors.append(
             current_app.config['MSG_TEXT_NOT_CHANGED'])
         return self.validation_error()
     self.validated = True
     return self.validation_success()
Beispiel #16
0
 def validate_on_submit(self):
     '''
     add requested email to the cache, delete based off config point
     :return:
     '''
     if not CustomForm.validate_on_submit(self):
         return self.validation_error()
     if g.datastore.find_user(email=self.email.data):
         flash(current_app.config['EMAIL_ALREADY_EXISTS'], 'error')
         return self.validation_error()
     self.user = current_user
     if self.email.data != self.user.email:
         self.kwargs.update({'email': self.email.data})
     if len(self.kwargs) == 0:
         self.email.errors.append(current_app.config['NO_DATA_CHANGED'])
         return self.validation_error()
     return self.validation_success()
Beispiel #17
0
 def validate_on_submit(self):
     if not CustomForm.validate_on_submit(self):
         return self.validation_error()
     if self.username.data:
         username_user = g.datastore.find_user(username=self.username.data)
         if username_user:
             self.username.errors.append(current_app.config['MSG_USERNAME_CLAIMED'])
             return self.validation_error()
     if self.email.data:
         email_user = g.datastore.find_user(email=self.email.data)
         if email_user:
             self.email.errors.append(current_app.config['MSG_EMAIL_CLAIMED'])
             return self.validation_error()
     self.kwargs.update({'username': self.username.data})
     self.kwargs.update({'first_name': self.first_name.data})
     self.kwargs.update({'last_name': self.last_name.data})
     self.kwargs.update({'email': self.email.data})
     return self.validation_success()
Beispiel #18
0
    def validate_on_submit(self):
        if not CustomForm.validate_on_submit(self):
            return self.validation_error()
        self.role = g.datastore.find_admin_role(id=self.admin_role_id.data)
        if not self.role:
            self.admin_role_id.errors.append('Invalid Admin Role')
            return self.validation_error()

        if self.name.data != self.role.name:
            self.kwargs.update({'name': self.name.data})
        if self.description.data != self.role.description:
            self.kwargs.update({'description': self.description.data})
        if self.active.data == 'on':
            active = True
        else:
            active = False
        if active != self.role.active:
            self.toggle_active = True
        if len(self.kwargs) == 0 and self.toggle_active is False:
            self.admin_role_id.errors.append(current_app.config['NO_DATA_CHANGED'])
            return self.validation_error()

        return self.validation_success()
Beispiel #19
0
 def validate_on_submit(self):
     if not CustomForm.validate_on_submit(self):
         return self.validation_error()
     return self.validation_success()
Beispiel #20
0
 def __init__(self, **kwargs):
     CustomForm.__init__(self, **kwargs)
     self.render_html = None
Beispiel #21
0
 def __init__(self, **kwargs):
     CustomForm.__init__(self, **kwargs)
Beispiel #22
0
 def __init__(self, **kwargs):
     CustomForm.__init__(self, **kwargs)
     self.content = None
     self.content_draft = None
     self.success_message = 'Content Published'
Beispiel #23
0
 def __init__(self, **kwargs):
     CustomForm.__init__(self, **kwargs)
     self.success_message = 'Instructions to reset your password have been sent to your email!'
     self.user = None
Beispiel #24
0
 def __init__(self, **kwargs):
     CustomForm.__init__(self, **kwargs)
     self.success_message = 'Confirmation Sent!'
     self.user = None
Beispiel #25
0
 def update_success(self):
     self.render_html['content_html'] = self.content.text
     return CustomForm.update_success(self)
Beispiel #26
0
 def __init__(self, **kwargs):
     CustomForm.__init__(self, **kwargs)
     self.success_message = 'You have been successfully registered! Please check your email to log in.'
     self.user = None
Beispiel #27
0
 def __init__(self, *args, **kwargs):
     CustomForm.__init__(self, **kwargs)
     self.user = None
     self.success_message = 'Created Admin User!'
Beispiel #28
0
 def __init__(self, **kwargs):
     CustomForm.__init__(self, **kwargs)
     self.user = None
     self.new_email = None
     self.success_message = current_app.config[
         'EMAIL_CHANGE_CONFIRMATION_SENT']
Beispiel #29
0
 def __init__(self, **kwargs):
     CustomForm.__init__(self, **kwargs)
     self.user = None
     self.success_message = current_app.config[
         'NAME_UPDATED_SUCCESS_MESSAGE']
Beispiel #30
0
 def __init__(self, **kwargs):
     CustomForm.__init__(self, **kwargs)
     self.remember.default = current_app.config[
         'SECURITY_DEFAULT_REMEMBER_ME']
     self.user = None