Class: UserCredentials
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- UserCredentials
show all
- Defined in:
- app/models/user_credentials.rb
Defined Under Namespace
Classes: AccountLocked, InsufficientPermissions, InvalidCredentials, MissingCredentials
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.for(service) ⇒ Object
14
15
16
17
18
19
20
|
# File 'app/models/user_credentials.rb', line 14
def self.for(service)
credentials = where(service: service).first || (raise MissingCredentials)
[credentials.login, credentials.password.decrypt(Houston.config.passphrase)]
rescue OpenSSL::PKey::RSAError
credentials.delete
raise MissingCredentials
end
|
Instance Method Details
#test_connection ⇒ Object
24
25
26
27
28
29
30
|
# File 'app/models/user_credentials.rb', line 24
def test_connection
case service
when "Unfuddle" then test_unfuddle_connection
when "Github" then test_github_connection
else raise NotImplementedError, "The service #{service.inspect} is not recognized"
end
end
|
#test_github_connection ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'app/models/user_credentials.rb', line 32
def test_github_connection
password = self.password.decrypt(Houston.config.passphrase)
Octokit::Client.new(login: login, password: password).user
rescue Octokit::Forbidden
errors.add(:base, "Account locked")
rescue Octokit::Unauthorized
errors.add(:base, "Invalid credentials")
end
|
#test_unfuddle_connection ⇒ Object
41
42
43
44
45
46
|
# File 'app/models/user_credentials.rb', line 41
def test_unfuddle_connection
password = self.password.decrypt(Houston.config.passphrase)
Unfuddle.with_config(username: login, password: password) { Unfuddle.instance.get("people/current") }
rescue Unfuddle::UnauthorizedError
errors.add(:base, "Invalid credentials")
end
|