Class: DragonsKeep::AccountController
- Inherits:
-
Object
- Object
- DragonsKeep::AccountController
- Defined in:
- lib/dragons_keep/account_controller.rb
Instance Attribute Summary collapse
-
#database ⇒ Object
Returns the value of attribute database.
-
#encrypt_pass ⇒ Object
Returns the value of attribute encrypt_pass.
Instance Method Summary collapse
- #decrypt!(account) ⇒ Object
- #delete(account) ⇒ Object
- #establish_connection ⇒ Object
- #get(id) ⇒ Object
-
#initialize(database = nil, password = nil) ⇒ AccountController
constructor
A new instance of AccountController.
- #list ⇒ Object
- #save!(account) ⇒ Object
-
#validate_connection ⇒ Object
Check the first record in the database and decrypt the password to see if the password is valid.
Constructor Details
#initialize(database = nil, password = nil) ⇒ AccountController
Returns a new instance of AccountController.
42 43 44 45 46 47 48 49 50 |
# File 'lib/dragons_keep/account_controller.rb', line 42 def initialize(database=nil, password=nil) @connection = false if(!(database.nil?)) self.database = File. database end if (!(password.nil?)) self.encrypt_pass = password end end |
Instance Attribute Details
#database ⇒ Object
Returns the value of attribute database.
12 13 14 |
# File 'lib/dragons_keep/account_controller.rb', line 12 def database @database end |
#encrypt_pass ⇒ Object
Returns the value of attribute encrypt_pass.
11 12 13 |
# File 'lib/dragons_keep/account_controller.rb', line 11 def encrypt_pass @encrypt_pass end |
Instance Method Details
#decrypt!(account) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/dragons_keep/account_controller.rb', line 73 def decrypt!(account) begin account.decrpyt_password self.encrypt_pass rescue OpenSSL::Cipher::CipherError raise PasswordException, "Password is invalid" end end |
#delete(account) ⇒ Object
81 82 83 |
# File 'lib/dragons_keep/account_controller.rb', line 81 def delete(account) account.destroy end |
#establish_connection ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dragons_keep/account_controller.rb', line 18 def establish_connection migrate = false if !(File.exist?(self.database)) migrate = true end #DataMapper::Logger.new $stdout, :debug DataMapper.setup :default, "sqlite3://#{self.database}" if migrate DataMapper.auto_migrate! else validate_connection end @connection = true end |
#get(id) ⇒ Object
67 68 69 70 71 |
# File 'lib/dragons_keep/account_controller.rb', line 67 def get(id) if @connection return Account.get id end end |
#list ⇒ Object
52 53 54 55 56 57 |
# File 'lib/dragons_keep/account_controller.rb', line 52 def list() if @connection return Account.all end end |
#save!(account) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/dragons_keep/account_controller.rb', line 58 def save!(account) if @connection if account.unencrypted? account.encrypt_password(self.encrypt_pass) end return account.save() end end |
#validate_connection ⇒ Object
Check the first record in the database and decrypt the password to see if the password is valid
35 36 37 38 39 40 |
# File 'lib/dragons_keep/account_controller.rb', line 35 def validate_connection account = Account.first if ! account.nil? self.decrypt!(account) end end |