Class: Chowder::Base
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Chowder::Base
- Defined in:
- lib/chowder.rb
Constant Summary collapse
- LOGIN_VIEW =
<<-HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang='en-us' xmlns='http://www.w3.org/1999/xhtml'> <head><title>Log In</title></head> <body> <form action="/login" method="post"> <div id="basic_login_field"> <label for="login">Login: </label> <input id="login" type="text" name="login" /><br /> </div> <div id="basic_password_field"> <label for="password">Password: </label> <input id="password" type="password" name="password" /><br /> </div> <div id="basic_login_button"> <input type="submit" value="Login" /> </div> </form> <p>OpenID:</p> <form action="/openid/initiate" method="post"> <div id="openid_login_field"> <label for="openid_identifier">URL: </label> <input id="openid_identifier" type="text" name="openid_identifier" /><br /> </div> <div id="openid_login_button"> <input type="submit" value="Login" /> </div> </form> </body></html> HTML
- SIGNUP_VIEW =
<<-HTML <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang='en-us' xmlns='http://www.w3.org/1999/xhtml'> <head><title>Sign Up</title></head> <body> __ERRORS__ <form action="/signup" method="post"> <div id="basic_login_field"> <label for="login">Login: </label> <input id="login" type="text" name="login" /><br /> </div> <div id="basic_password_field"> <label for="password">Password: </label> <input id="password" type="password" name="password" /><br /> </div> <div id="basic_signup_button"> <input type="submit" value="Sign Up" /> </div> </form> </body></html> HTML
Class Method Summary collapse
Instance Method Summary collapse
- #authorize(user) ⇒ Object
-
#initialize(app = nil, args = {}, &block) ⇒ Base
constructor
A new instance of Base.
- #render_custom_template(type) ⇒ Object
- #return_or_redirect_to(path) ⇒ Object
Constructor Details
#initialize(app = nil, args = {}, &block) ⇒ Base
Returns a new instance of Base.
68 69 70 71 72 |
# File 'lib/chowder.rb', line 68 def initialize(app=nil, args={}, &block) @signup_callback = args[:signup] @login_callback = args[:login] || block super(app) end |
Class Method Details
.new(app = nil, args = {}, &block) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/chowder.rb', line 61 def self.new(app=nil, args={}, &block) builder = Rack::Builder.new builder.use Rack::Session::Cookie, :secret => args[:secret] builder.run super builder.to_app end |
Instance Method Details
#authorize(user) ⇒ Object
74 75 76 |
# File 'lib/chowder.rb', line 74 def (user) session[:current_user] = user end |
#render_custom_template(type) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/chowder.rb', line 82 def render_custom_template(type) views_dir = self..views || "./views" template = Dir[File.join(views_dir, "#{type}.*")].first if template engine = File.extname(template)[1..-1] send(engine, type) end end |
#return_or_redirect_to(path) ⇒ Object
78 79 80 |
# File 'lib/chowder.rb', line 78 def return_or_redirect_to(path) redirect(session[:return_to] || request.script_name + path) end |