Class: Chowder::Base

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/chowder.rb

Direct Known Subclasses

Basic, OpenID

Constant Summary collapse

LOGIN_VIEW =
"  <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n  <html lang='en-us' xmlns='http://www.w3.org/1999/xhtml'>\n  <head><title>Log In</title></head>\n  <body>\n    <form action=\"/login\" method=\"post\">\n      <div id=\"basic_login_field\">\n        <label for=\"login\">Login: </label>\n        <input id=\"login\" type=\"text\" name=\"login\" /><br />\n      </div>\n      <div id=\"basic_password_field\">\n        <label for=\"password\">Password: </label>\n        <input id=\"password\" type=\"password\" name=\"password\" /><br />\n      </div>\n      <div id=\"basic_login_button\">\n        <input type=\"submit\" value=\"Login\" />\n      </div>\n    </form>\n    <p>OpenID:</p>\n    <form action=\"/openid/initiate\" method=\"post\">\n      <div id=\"openid_login_field\">\n        <label for=\"openid_identifier\">URL: </label>\n        <input id=\"openid_identifier\" type=\"text\" name=\"openid_identifier\" /><br />\n      </div>\n      <div id=\"openid_login_button\">\n        <input type=\"submit\" value=\"Login\" />\n      </div>\n    </form>\n  </body></html>\n"
SIGNUP_VIEW =
"  <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n  <html lang='en-us' xmlns='http://www.w3.org/1999/xhtml'>\n  <head><title>Sign Up</title></head>\n  <body>\n    __ERRORS__\n    <form action=\"/signup\" method=\"post\">\n      <div id=\"basic_login_field\">\n        <label for=\"login\">Login: </label>\n        <input id=\"login\" type=\"text\" name=\"login\" /><br />\n      </div>\n      <div id=\"basic_password_field\">\n        <label for=\"password\">Password: </label>\n        <input id=\"password\" type=\"password\" name=\"password\" /><br />\n      </div>\n      <div id=\"basic_signup_button\">\n        <input type=\"submit\" value=\"Sign Up\" />\n      </div>\n    </form>\n  </body></html>\n"

Class Method Summary collapse

Instance Method Summary collapse

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 authorize(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.options.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