Class: CompositionEngine::LoginHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/composition_engine.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#envObject

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.(_env)
  inst = self.new(_env)
  if inst.logged_in?
    false
  else
    inst.
  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_pathObject



77
78
79
# File 'lib/composition_engine.rb', line 77

def self.prefixed_path
  PATH_PREFIX+self.resource_path
end

.resource_pathObject



73
74
75
# File 'lib/composition_engine.rb', line 73

def self.resource_path
  '/login'
end

Instance Method Details

#create_loginObject



110
111
112
113
114
115
116
117
118
119
# File 'lib/composition_engine.rb', line 110

def 
  nickname = params['login']['nickname']
  if nickname.nil? || nickname.empty?
    ("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

#handleObject



85
86
87
88
89
90
91
# File 'lib/composition_engine.rb', line 85

def handle
  if request.get?
    
  elsif request.post?
    
  end
end

#logged_in?Boolean

Returns:

  • (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 (message = nil) #TODO: require form key so they can't spam POSTs
  body = <<HTML
<html>
  <body>
<h1>New User!</h1>
#{"<em>#{message}</em>" if message}
<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