Sha256: 3fd7fccc637492ee5e2340c641ec4aacc2ca546999769da9ee525ecccff57d96

Contents?: true

Size: 1.51 KB

Versions: 70

Compression:

Stored size: 1.51 KB

Contents

module Authentication
  mattr_accessor :login_regex, :bad_login_message, 
    :name_regex, :bad_name_message,
    :email_name_regex, :domain_head_regex, :domain_tld_regex, :email_regex, :bad_email_message

  self.login_regex       = /\A\w[\w\.\-_@]+\z/                     # ASCII, strict
  # self.login_regex       = /\A[[:alnum:]][[:alnum:]\.\-_@]+\z/     # Unicode, strict
  # self.login_regex       = /\A[^[:cntrl:]\\<>\/&]*\z/              # Unicode, permissive

  self.bad_login_message = "use only letters, numbers, and .-_@ please.".freeze

  self.name_regex        = /\A[^[:cntrl:]\\<>\/&]*\z/              # Unicode, permissive
  self.bad_name_message  = "avoid non-printing characters and \\&gt;&lt;&amp;/ please.".freeze

  self.email_name_regex  = '[\w\.%\+\-]+'.freeze
  self.domain_head_regex = '(?:[A-Z0-9\-]+\.)+'.freeze
  self.domain_tld_regex  = '(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|jobs|museum)'.freeze
  self.email_regex       = /\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i
  self.bad_email_message = "should look like an email address.".freeze

  def self.included(recipient)
    recipient.extend(ModelClassMethods)
    recipient.class_eval do
      include ModelInstanceMethods
    end
  end

  module ModelClassMethods
    def secure_digest(*args)
      Digest::SHA1.hexdigest(args.flatten.join('--'))
    end

    def make_token
      secure_digest(Time.now, (1..10).map{ rand.to_s })
    end
  end # class methods

  module ModelInstanceMethods
  end # instance methods
end

Version data entries

70 entries across 70 versions & 13 rubygems

Version Path
caleb-restful-authentication-1.1.1 lib/authentication.rb
dwaite-restful-authentication-1.1.1 lib/authentication.rb
genki-restful-authentication-1.1.1 lib/authentication.rb
ggoodale-restful-authentication-1.1.1 lib/authentication.rb
simonmenke-mr_authentication-0.0.1 vendor/plugins/restful-authentication/lib/authentication.rb
smukherjee-openbill-0.1.5 vendor/plugins/restful-authentication/lib/authentication.rb
smukherjee-openbill-0.1.6 vendor/plugins/restful-authentication/lib/authentication.rb
smukherjee-openbill-0.1.7 vendor/plugins/restful-authentication/lib/authentication.rb
rails3-restful-authentication-3.0.1 lib/authentication.rb
tournament-5.0.0 webgui/vendor/plugins/restful_authentication/lib/authentication.rb
restful-authentication-1.2.1 lib/authentication.rb
branston-0.6.6 lib/branston/vendor/plugins/restful_authentication/lib/authentication.rb
branston-0.6.5 lib/branston/vendor/plugins/restful_authentication/lib/authentication.rb
branston-0.6.4 lib/branston/vendor/plugins/restful_authentication/lib/authentication.rb
branston-0.6.3 lib/branston/vendor/plugins/restful_authentication/lib/authentication.rb
branston-0.6.2 lib/branston/vendor/plugins/restful_authentication/lib/authentication.rb
tournament-4.2.0 webgui/vendor/plugins/restful_authentication/lib/authentication.rb
tournament-4.0.2 webgui/vendor/plugins/restful_authentication/lib/authentication.rb
tournament-4.0.0 webgui/vendor/plugins/restful_authentication/lib/authentication.rb
branston-0.6.1 lib/branston/vendor/plugins/restful_authentication/lib/authentication.rb