Class: Impostor::Auth
- Inherits:
-
Object
- Object
- Impostor::Auth
- Defined in:
- lib/impostor/auth.rb
Instance Attribute Summary collapse
-
#authenticated ⇒ Object
(also: #authenticated?)
readonly
Returns the value of attribute authenticated.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#fetch_login_page ⇒ Object
get the page for logging in.
-
#get_login_form(page) ⇒ Object
returns the login form from the login page.
-
#initialize(config) ⇒ Auth
constructor
Auth is initialized with the config of the impostor.
-
#logged_in?(page) ⇒ Boolean
given the state of the page, are we logged in to the forum?.
-
#login ⇒ Object
Login to the impostor’s forum.
- #login_with_raises ⇒ Object
-
#logout ⇒ Object
logot of the impostor’s forum.
-
#post_login(form) ⇒ Object
does the work of posting the login form.
-
#set_username_and_password(form) ⇒ Object
Sets the user name and pass word on the loing form.
Constructor Details
#initialize(config) ⇒ Auth
Auth is initialized with the config of the impostor
10 11 12 13 |
# File 'lib/impostor/auth.rb', line 10 def initialize(config) @config = config self.extend eval("Impostor::#{config.type.to_s.capitalize}::Auth") end |
Instance Attribute Details
#authenticated ⇒ Object (readonly) Also known as: authenticated?
Returns the value of attribute authenticated.
4 5 6 |
# File 'lib/impostor/auth.rb', line 4 def authenticated @authenticated end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/impostor/auth.rb', line 3 def config @config end |
Instance Method Details
#fetch_login_page ⇒ Object
get the page for logging in
68 69 70 71 72 73 74 |
# File 'lib/impostor/auth.rb', line 68 def fetch_login_page begin self.config.agent.get(self.config.login_page) rescue StandardError => err raise Impostor::LoginError.new(err) end end |
#get_login_form(page) ⇒ Object
returns the login form from the login page
79 80 81 |
# File 'lib/impostor/auth.rb', line 79 def get_login_form(page) raise Impostor::MissingTemplateMethodError.new("get_login_form must be implemented") end |
#logged_in?(page) ⇒ Boolean
given the state of the page, are we logged in to the forum?
61 62 63 |
# File 'lib/impostor/auth.rb', line 61 def logged_in?(page) raise Impostor::MissingTemplateMethodError.new("logged_in? must be implemented") end |
#login ⇒ Object
Login to the impostor’s forum. #login is comprised of the following template methods to allow implementation for specific forum applications:
-
fetch_login_page
-
logged_in?(page)
-
get_login_form(page)
-
set_username_and_password(form)
-
post_login(form)
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/impostor/auth.rb', line 25 def login return true if self.authenticated? page = self.fetch_login_page return true if self.logged_in?(page) form = self.get_login_form(page) self.set_username_and_password(form) page = self.post_login(form) @authenticated = self.logged_in?(page) end |
#login_with_raises ⇒ Object
38 39 40 41 42 |
# File 'lib/impostor/auth.rb', line 38 def login_with_raises return true if self.login raise Impostor::LoginError.new("not logged in") end |
#logout ⇒ Object
logot of the impostor’s forum
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/impostor/auth.rb', line 47 def logout return false unless self.authenticated? self.config.save_topics self.config. @authenticated = false not self.authenticated? end |
#post_login(form) ⇒ Object
does the work of posting the login form
93 94 95 96 97 98 99 100 |
# File 'lib/impostor/auth.rb', line 93 def post_login(form) begin config.sleep_before_post page = form.submit rescue StandardError => err raise Impostor::LoginError.new(err) end end |
#set_username_and_password(form) ⇒ Object
Sets the user name and pass word on the loing form.
86 87 88 |
# File 'lib/impostor/auth.rb', line 86 def set_username_and_password(form) raise Impostor::MissingTemplateMethodError.new("set_username_and_password must be implemented") end |