Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

65 lines (52 sloc) 2.548 kb
module Newscloud
module Util
# Thanks to restful_auth authentication.rb for these
mattr_accessor :email_name_regex, :domain_head_regex, :domain_tld_regex, :email_regex, :bad_email_message, :login_regex, :bad_login_message, :name_regex, :bad_name_message, :url_regex
self.name_regex = /\A[^[:cntrl:]\\<>\/&]*\z/ # Unicode, permissive
self.bad_name_message = "avoid non-printing characters and \\&gt;&lt;&amp;/ please.".freeze
self.bad_login_message = "use only letters, numbers, and .-_@ please.".freeze
self.login_regex = /\A\w[\w\.\-_@]+\z/ # ASCII, strict
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
self.url_regex = /http(s?):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/i
def current_user
@current_user ||= User.active.find(session[:user_id]) if session[:user_id]
end
# Store the given user id in the session.
def set_current_user(new_user)
session[:user_id] = new_user ? new_user.id : nil
@current_user = new_user || false
end
def current_facebook_user
(current_user and current_user.facebook_user?) ? current_user : nil
end
def current_facebook_graph_user
current_user and current_user.mogli_user
end
def logged_in?
!! current_user
end
def authorized?
false
end
# Store the URI of the current request in the session.
#
# We can return to this location by calling #redirect_back_or_default.
def store_location location = nil
session[:return_to] = location || request.fullpath
end
# Redirect to the URI stored by the most recent store_location call or
# to the passed default. Set an appropriately modified
# after_filter :store_location, :only => [:index, :new, :show, :edit]
# for any controller you want to be bounce-backable.
def redirect_back_or_default(default)
redirect_to(session.delete(:return_to) || default)
end
def self.included(base)
base.send :helper_method, :current_user, :current_user=, :logged_in?, :authorized?, :store_location, :redirect_back_or_default if base.respond_to? :helper_method
end
end
end
Jump to Line
Something went wrong with that request. Please try again.