module Sinatra::Authentication::Validations

Constants

EMAIL_FORMAT

Public Instance Methods

validate() click to toggle source
Calls superclass method
# File lib/sinatra/authentication/validations.rb, line 6
def validate
    login_field = Sinatra::Authentication::LoginField.attr_name

    if login_field == :email
        assert_login_using_email :email
    else
        assert_present(login_field) and assert_unique(login_field)
    end

    assert_password :password

    super
end

Protected Instance Methods

assert_login_using_email(attribute, error = [att, :not_email]) click to toggle source
# File lib/sinatra/authentication/validations.rb, line 21
def assert_login_using_email(attribute, error = [att, :not_email])
    if assert_present attribute
        if assert_format attribute, EMAIL_FORMAT, error
            assert_unique attribute
        end
    end
end
assert_password(attribute, error = [attribute, :not_present]) click to toggle source
# File lib/sinatra/authentication/validations.rb, line 29
def assert_password(attribute, error = [attribute, :not_present])
    confirmation_attribute = :"#{ attribute }_confirmation"

    if new? && assert_present(attribute) || !send(attribute).to_s.empty?
        assert send(attribute) == send(confirmation_attribute), [attribute, :not_confirmed]
    end
end