Module: DohMerb::Login
- Defined in:
- lib/doh/merb/login.rb
Instance Attribute Summary collapse
-
#index_page ⇒ Object
Returns the value of attribute index_page.
-
#login_db_name ⇒ Object
Returns the value of attribute login_db_name.
-
#login_page ⇒ Object
Returns the value of attribute login_page.
-
#login_table ⇒ Object
Returns the value of attribute login_table.
-
#password_db_name ⇒ Object
Returns the value of attribute password_db_name.
-
#password_fieldname ⇒ Object
Returns the value of attribute password_fieldname.
-
#username_fieldname ⇒ Object
set the attr_accessors or override them.
Instance Method Summary collapse
-
#authenticate_username_key(username, key) ⇒ Object
override this to have custom behavior.
- #authenticated? ⇒ Boolean
- #get_session_key(username, password) ⇒ Object
- #logged_in? ⇒ Boolean
-
#login_helper ⇒ Object
kjmtodobb: figure out how to make it so login / logout can just exist here instead of having to get called as helpers – merb doesn’t recognize them as actions if they’re included via a module in regular fashion…
- #login_required ⇒ Object
- #logout_helper ⇒ Object
Instance Attribute Details
#index_page ⇒ Object
Returns the value of attribute index_page.
6 7 8 |
# File 'lib/doh/merb/login.rb', line 6 def index_page @index_page end |
#login_db_name ⇒ Object
Returns the value of attribute login_db_name.
6 7 8 |
# File 'lib/doh/merb/login.rb', line 6 def login_db_name @login_db_name end |
#login_page ⇒ Object
Returns the value of attribute login_page.
6 7 8 |
# File 'lib/doh/merb/login.rb', line 6 def login_page @login_page end |
#login_table ⇒ Object
Returns the value of attribute login_table.
6 7 8 |
# File 'lib/doh/merb/login.rb', line 6 def login_table @login_table end |
#password_db_name ⇒ Object
Returns the value of attribute password_db_name.
6 7 8 |
# File 'lib/doh/merb/login.rb', line 6 def password_db_name @password_db_name end |
#password_fieldname ⇒ Object
Returns the value of attribute password_fieldname.
6 7 8 |
# File 'lib/doh/merb/login.rb', line 6 def password_fieldname @password_fieldname end |
#username_fieldname ⇒ Object
set the attr_accessors or override them
9 10 11 |
# File 'lib/doh/merb/login.rb', line 9 def username_fieldname @username_fieldname end |
Instance Method Details
#authenticate_username_key(username, key) ⇒ Object
override this to have custom behavior
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/doh/merb/login.rb', line 53 def authenticate_username_key(username, key) begin row = DohDb::select_optional_row("SELECT * FROM #{login_table} WHERE #{login_db_name} = #{username.to_sql}") if row if key == get_session_key(username, row[password_db_name]) self.instance_variable_set("@#{login_table}_row", row) return true end end rescue Exception => e dohlog.warn("got error: #{e.inspect} (called from authenticate_username_key) -- are you missing the table: #{login_table.inspect}?") end return nil end |
#authenticated? ⇒ Boolean
47 48 49 50 |
# File 'lib/doh/merb/login.rb', line 47 def authenticated? dohlog.debug("authenticated? called -- session[:dohmerb_login_username] = #{session[:dohmerb_login_username]}, session[:dohmerb_login_key] = #{session[:dohmerb_login_key]}") authenticate_username_key(session[:dohmerb_login_username], session[:dohmerb_login_key]) if !session[:dohmerb_login_username].to_s.strip.empty? && !session[:dohmerb_login_key].to_s.strip.empty? end |
#get_session_key(username, password) ⇒ Object
68 69 70 |
# File 'lib/doh/merb/login.rb', line 68 def get_session_key(username, password) Digest::SHA1.hexdigest("#{username}**#{password}") end |
#logged_in? ⇒ Boolean
72 73 74 |
# File 'lib/doh/merb/login.rb', line 72 def logged_in? authenticated? end |
#login_helper ⇒ Object
kjmtodobb: figure out how to make it so login / logout can just exist here instead of having to get called as helpers – merb doesn’t recognize them as actions if they’re included via a module in regular fashion…
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/doh/merb/login.rb', line 77 def login_helper if request.post? session[:dohmerb_login_username] = params[username_fieldname] session[:dohmerb_login_key] = get_session_key(params[username_fieldname], params[password_fieldname]) if authenticated? if session[:dohmerb_original_uri] dohlog.debug("redirecting to original uri: #{session[:dohmerb_original_uri].inspect}") redirect session[:dohmerb_original_uri] else dohlog.debug("no original uri, redirecting to index") redirect index_page end else dohlog.debug("login_helper called, not authenticated -- redirecting to login page") redirect login_page end end render end |
#login_required ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/doh/merb/login.rb', line 37 def login_required if !authenticated? dohlog.debug "not authenticated, redirecting to #{login_page}" session[:dohmerb_original_uri] = request.uri dohlog.debug("storing original uri #{request.uri.inspect}") redirect login_page throw :halt end end |
#logout_helper ⇒ Object
97 98 99 100 101 102 |
# File 'lib/doh/merb/login.rb', line 97 def logout_helper session[:dohmerb_login_username] = '' session[:dohmerb_login_key] = '' redirect login_page render end |