Class: CompositionEngine::LoginHandler
- Inherits:
-
Object
- Object
- CompositionEngine::LoginHandler
- Defined in:
- lib/composition_engine.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
Returns the value of attribute env.
Class Method Summary collapse
Instance Method Summary collapse
- #create_login ⇒ Object
- #handle ⇒ Object
-
#initialize(_env) ⇒ LoginHandler
constructor
A new instance of LoginHandler.
- #logged_in? ⇒ Boolean
-
#new_login(message = nil) ⇒ Object
TODO: require form key so they can’t spam POSTs.
Constructor Details
#initialize(_env) ⇒ LoginHandler
Returns a new instance of LoginHandler.
81 82 83 |
# File 'lib/composition_engine.rb', line 81 def initialize(_env) self.env = _env end |
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
58 59 60 |
# File 'lib/composition_engine.rb', line 58 def env @env end |
Class Method Details
.force_login(_env) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/composition_engine.rb', line 64 def self.force_login(_env) inst = self.new(_env) if inst.logged_in? false else inst.new_login end end |
.handle(_env) ⇒ Object
60 61 62 |
# File 'lib/composition_engine.rb', line 60 def self.handle(_env) self.new(_env).handle end |
.prefixed_path ⇒ Object
77 78 79 |
# File 'lib/composition_engine.rb', line 77 def self.prefixed_path PATH_PREFIX+self.resource_path end |
.resource_path ⇒ Object
73 74 75 |
# File 'lib/composition_engine.rb', line 73 def self.resource_path '/login' end |
Instance Method Details
#create_login ⇒ Object
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/composition_engine.rb', line 110 def create_login nickname = params['login']['nickname'] if nickname.nil? || nickname.empty? new_login("Nickname must not be blank!") else user = ::CompositionEngine::User.new(:nickname => nickname, :uuid => UUIDTools::UUID.random_create) ::CompositionEngine.assign_user_to_session(session,user) [302,{'Location'=>'/'},[]] end end |
#handle ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/composition_engine.rb', line 85 def handle if request.get? new_login elsif request.post? create_login end end |
#logged_in? ⇒ Boolean
121 122 123 |
# File 'lib/composition_engine.rb', line 121 def logged_in? ::CompositionEngine.extract_user_from_session(session) end |
#new_login(message = nil) ⇒ Object
TODO: require form key so they can’t spam POSTs
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/composition_engine.rb', line 93 def new_login( = nil) #TODO: require form key so they can't spam POSTs body = <<HTML <html> <body> <h1>New User!</h1> #{"<em>#{}</em>" if } <p>Select a handle and click Login</p> <form action='#{self.class.prefixed_path}' method='POST'> <label for='login_nickname'>Nickname: </label><input type='text' name='login[nickname]' id='login_nickname'/> <input type='submit' value='Login' /> </form> </body> </html> HTML [200,{'ContentType' => 'text/html'},[body]] end |