Class: Pixiurge::Authentication::FileAccountStorage

Inherits:
AccountStorage show all
Defined in:
lib/pixiurge/authentication.rb

Overview

Store account data as a JSON file. Not multithread-safe. This is the default built-in account storage if you don't specify.

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initialize(pathname, oldpathname = pathname + ".old") ⇒ FileAccountStorage

Constructor

Since:

  • 0.1.0



307
308
309
310
311
312
# File 'lib/pixiurge/authentication.rb', line 307

def initialize(pathname, oldpathname = pathname + ".old")
  @accounts_json_filename = pathname
  @accounts_old_json_filename = oldpathname

  
end

Instance Method Details

#data_for(username) ⇒ Hash{String=>String}?

Get user data for the named account.

Parameters:

  • username (String)

    The account's username

Returns:

  • (Hash{String=>String}, nil)

    The account's user data or nil if it does not exist

Since:

  • 0.1.0



332
333
334
# File 'lib/pixiurge/authentication.rb', line 332

def data_for(username)
  @account_state[username]
end

#register(username, account_data) ⇒ void

This method returns an undefined value.

Create an account. The account_data hash will contain information about the encrypted password hash in the default setup, but it's allowed to contain any JSON-serializable Hash in general.

Parameters:

  • username (String)

    The account's username; see AuthenticatedApp::USERNAME_REGEX for legal format

  • account_data (Hash{String})

    The user's data, normally including login info

Since:

  • 0.1.0



322
323
324
325
# File 'lib/pixiurge/authentication.rb', line 322

def register(username, )
  @account_state[username] = 
  
end

#set_data_for(username, new_data) ⇒ void

This method returns an undefined value.

Set user data for the named account. Any fields not included in the new value are deleted. Raise an error if the username does not exist.

Parameters:

  • username (String)

    The account's username

  • new_data (Hash{String=>String})

    The account's new user data

Since:

  • 0.1.0



344
345
346
347
# File 'lib/pixiurge/authentication.rb', line 344

def set_data_for(username, new_data)
  @account_state[username] = new_data
  
end

#unregister(username) ⇒ void

This method returns an undefined value.

Unregister the named account; delete it from the AccountStorage.

Parameters:

  • username (String)

    The account's username

Since:

  • 0.1.0



354
355
356
357
358
359
360
# File 'lib/pixiurge/authentication.rb', line 354

def unregister(username)
  unless @account_state[username]
    raise "No such account username as #{username.inspect}!"
  end
  @account_state.delete(username)
  
end