def test_flash_different_categories(self):
     """Ensure all 4 categories work properly"""
     success(self.simple_message)
     warning(self.simple_message)
     info(self.simple_message)
     danger(self.simple_message)
     self.assert_flashes(self.simple_message, 'success')
     self.assert_flashes(self.simple_message, 'warning')
     self.assert_flashes(self.simple_message, 'info')
     self.assert_flashes(self.simple_message, 'danger')
 def test_flash_different_categories(self):
     """
     Ensure all 4 categories work properly
     """
     success(self.simple_message)
     warning(self.simple_message)
     info(self.simple_message)
     danger(self.simple_message)
     self.assert_flashes(self.simple_message, 'success')
     self.assert_flashes(self.simple_message, 'warning')
     self.assert_flashes(self.simple_message, 'info')
     self.assert_flashes(self.simple_message, 'danger')
示例#3
0
def login():
    form = uforms.LoginForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            user = umodels.User.objects.filter(
                username=form.username.data).first()
            if user and check_password_hash(user.password, form.password.data):
                login_user(user)
                flash.info('Welcome {}.'.format(str(user)))
                return redirect(request.args.get('next', url_for('app.home')))
            else:
                flash.warning('Invalid Credentials. Please try again.')

    return render_template('user/login.html', form=form)
示例#4
0
def user_toggle(user_id=None, action=None):
    try:
        user = umodels.User.get_user(user_id)
        if action == "remove":
            user.delete()
            flash.success("User \"{}\" was successfully deleted!"
                          "".format(str(user)))
        elif action == "is_admin":
            user.is_admin = not user.is_admin
            user.save()
            flash.success("User \"{}\" field \"{}\" was successfully "
                          "updated to \"{}\"!".format(str(user), action,
                                                      user.is_admin))
    except (me.DoesNotExist, me.ValidationError) as e:
        flash.warning("User with id \"{}\" does not exist."
                      "".format(user_id))

    return redirect(url_for("admin.home"))
    def login(cls, form):
        """
        Login user by giving "LoginForm" form and validate if username+password pair is valid
        """
        if not form.validate_on_submit():
            flash.danger(u'Form is not valid.')
            return False

        user = UserFinder.by_username(form.username.data)
        if not user:
            flash.danger(u'User {} does not exists.'.format(form.username.data))
            return False

        if not check_password_hash(user.password, form.password.data):
            flash.warning(u'Invalid Credentials. Please try again.')
            return False

        LoginUserService(user).call()
        return user
    def login(cls, form):
        """
        Login user by giving "LoginForm" form and validate if username+password pair is valid
        """
        if not form.validate_on_submit():
            flash.danger(u'Form is not valid.')
            return False

        user = UserFinder.by_username(form.username.data)
        if not user:
            flash.danger(u'User {} does not exists.'.format(
                form.username.data))
            return False

        if not check_password_hash(user.password, form.password.data):
            flash.warning(u'Invalid Credentials. Please try again.')
            return False

        LoginUserService(user).call()
        return user