Class: GameMachine::Handlers::Authentication
- Inherits:
-
Object
- Object
- GameMachine::Handlers::Authentication
- Defined in:
- lib/game_machine/handlers/authentication.rb
Constant Summary collapse
- AUTHTOKEN =
'authorized'- AUTHENTICATED_USERS =
java.util.concurrent.ConcurrentHashMap.new
Class Method Summary collapse
Instance Method Summary collapse
- #authenticate!(player) ⇒ Object
- #authtoken_for_player(player_id) ⇒ Object
- #register_player(player_id) ⇒ Object
- #valid_authtoken?(player) ⇒ Boolean
Class Method Details
.authenticated?(player) ⇒ Boolean
8 9 10 11 12 13 |
# File 'lib/game_machine/handlers/authentication.rb', line 8 def self.authenticated?(player) if authtoken = AUTHENTICATED_USERS.fetch(player.id,nil) return player.authtoken == authtoken end false end |
.unregister_player(player_id) ⇒ Object
15 16 17 |
# File 'lib/game_machine/handlers/authentication.rb', line 15 def self.unregister_player(player_id) AUTHENTICATED_USERS.delete(player_id) end |
Instance Method Details
#authenticate!(player) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/game_machine/handlers/authentication.rb', line 34 def authenticate!(player) @player = player if valid_authtoken?(player) register_player(player.id) player.set_authenticated(true) else false end end |
#authtoken_for_player(player_id) ⇒ Object
25 26 27 |
# File 'lib/game_machine/handlers/authentication.rb', line 25 def authtoken_for_player(player_id) Handlers::PlayerAuthentication.instance.authtoken_for(player_id) end |
#register_player(player_id) ⇒ Object
19 20 21 22 23 |
# File 'lib/game_machine/handlers/authentication.rb', line 19 def register_player(player_id) AUTHENTICATED_USERS[player_id] = authtoken_for_player(player_id) end |
#valid_authtoken?(player) ⇒ Boolean
29 30 31 |
# File 'lib/game_machine/handlers/authentication.rb', line 29 def valid_authtoken?(player) player.authtoken == authtoken_for_player(player.id) end |