Module: DohRails::Login

Defined in:
lib/doh/rails/login.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#index_pageObject

Returns the value of attribute index_page.



6
7
8
# File 'lib/doh/rails/login.rb', line 6

def index_page
  @index_page
end

#login_controllerObject

set the attr_accessors or override them



10
11
12
# File 'lib/doh/rails/login.rb', line 10

def 
  @login_controller
end

#login_db_nameObject

Returns the value of attribute login_db_name.



6
7
8
# File 'lib/doh/rails/login.rb', line 6

def 
  @login_db_name
end

#login_modelObject

Returns the value of attribute login_model.



6
7
8
# File 'lib/doh/rails/login.rb', line 6

def 
  @login_model
end

#login_pageObject

Returns the value of attribute login_page.



6
7
8
# File 'lib/doh/rails/login.rb', line 6

def 
  @login_page
end

#login_tableObject

Returns the value of attribute login_table.



6
7
8
# File 'lib/doh/rails/login.rb', line 6

def 
  @login_table
end

#password_db_nameObject

Returns the value of attribute password_db_name.



6
7
8
# File 'lib/doh/rails/login.rb', line 6

def password_db_name
  @password_db_name
end

#password_fieldnameObject

Returns the value of attribute password_fieldname.



6
7
8
# File 'lib/doh/rails/login.rb', line 6

def password_fieldname
  @password_fieldname
end

#username_fieldnameObject

Returns the value of attribute username_fieldname.



6
7
8
# File 'lib/doh/rails/login.rb', line 6

def username_fieldname
  @username_fieldname
end

Instance Method Details

#authenticate_username_key(username, key) ⇒ Object

override this to have custom behavior



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/doh/rails/login.rb', line 82

def authenticate_username_key(username, key)
  begin
    row = DohDb::select_optional_row("SELECT * FROM #{} WHERE #{} = #{username.to_sql}")
    if row
      if key == get_session_key(username, row[password_db_name])
        self.instance_variable_set("@#{}_row", row)
        dohlog.debug("authenticate_username returning true")
        return true
      end
    end
  rescue Exception => e
    dohlog.warn("got error: #{e.inspect} (called from authenticate_username_key) -- are you missing the table: #{.inspect}?")
  end
  dohlog.debug("authenticate_username returning nil")
  return nil
end

#authenticated?Boolean

Returns:

  • (Boolean)


71
72
73
74
75
76
77
78
79
# File 'lib/doh/rails/login.rb', line 71

def authenticated?
  if @authentication_checked
    return @authenticated
  end
  dohlog.debug("authenticated? called -- session[:dohrails_login_username] = #{session[:dohrails_login_username]}")
  @authenticated = authenticate_username_key(session[:dohrails_login_username], session[:dohrails_login_key]) if !session[:dohrails_login_username].to_s.strip.empty? && !session[:dohrails_login_key].to_s.strip.empty?
  @authentication_checked = true
  return @authenticated
end

#get_session_key(username, password) ⇒ Object



99
100
101
# File 'lib/doh/rails/login.rb', line 99

def get_session_key(username, password)
  Digest::SHA1.hexdigest("#{username}**#{password}")
end

#logged_in?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/doh/rails/login.rb', line 103

def logged_in?
  authenticated?
end

#logged_outObject



131
132
133
# File 'lib/doh/rails/login.rb', line 131

def logged_out
  flash[:notice] = 'You are now logged out'
end

#loginObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/doh/rails/login.rb', line 107

def 
  
  if request.post?
     = params[]
    session[:dohrails_login_username] = [username_fieldname]
    session[:dohrails_login_key] = get_session_key([username_fieldname], [password_fieldname])
    if authenticated?
      
      if session[:dohrails_original_uri]
        dohlog.debug("redirecting to original uri: #{session[:dohrails_original_uri].inspect}")
        redirect_to session[:dohrails_original_uri]
        session[:dohrails_original_uri] = nil
      else
        dohlog.debug("no original uri, redirecting to index")
        redirect_to :controller => , :action => index_page
      end
    else
      dohlog.debug("login_helper called, not authenticated -- redirecting to login page")
      
      redirect_to :controller => , :action => 
    end
  end
end

#login_failedObject



49
50
51
# File 'lib/doh/rails/login.rb', line 49

def 
  flash[:notice] = 'Please enter a valid username / password'
end

#login_page_hitObject



46
47
# File 'lib/doh/rails/login.rb', line 46

def 
end

#login_redirectObject



56
57
58
# File 'lib/doh/rails/login.rb', line 56

def 
  flash[:notice] = 'Please log in'
end

#login_requiredObject



60
61
62
63
64
65
66
67
68
69
# File 'lib/doh/rails/login.rb', line 60

def 
  if !authenticated?
    dohlog.debug "not authenticated, redirecting to  #{}"
    session[:dohrails_original_uri] = request.request_uri
    dohlog.debug("storing original uri #{request.request_uri.inspect}")
    
    redirect_to :controller => , :action => 
    return false
  end
end

#login_succeededObject



53
54
# File 'lib/doh/rails/login.rb', line 53

def 
end

#logoutObject



135
136
137
138
139
140
# File 'lib/doh/rails/login.rb', line 135

def logout
  session[:dohrails_login_username] = ''
  session[:dohrails_login_key] = ''
  logged_out
  redirect_to :controller => , :action => 
end