Class: HaveAPI::Authentication::Token::Resources::Token::Request
- Inherits:
-
HaveAPI::Action
- Object
- Common
- HaveAPI::Action
- HaveAPI::Authentication::Token::Resources::Token::Request
- Defined in:
- lib/haveapi/authentication/token/resources.rb
Instance Attribute Summary
Attributes inherited from HaveAPI::Action
#errors, #flags, #message, #version
Instance Method Summary collapse
Methods inherited from HaveAPI::Action
authorize, #authorized?, build_route, #current_user, delayed_inherited, describe, example, from_context, inherit_attrs_from_resource, inherited, #initialize, initialize, #input, input, meta, #meta, model_adapter, output, #params, #pre_exec, #prepare, #request, resolve_url_params, #safe_exec, #safe_output, #set_meta, #v?, #validate!, validate_build
Methods included from Hookable
Methods inherited from Common
check_build, has_attr, inherit_attrs
Constructor Details
This class inherits a constructor from HaveAPI::Action
Instance Method Details
#exec ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/haveapi/authentication/token/resources.rb', line 40 def exec klass = self.class.resource.token_instance[@version] user = klass.send( :find_user_by_credentials, request, input[:login], input[:password] ) error('bad login or password') unless user token = expiration = nil loop do begin token = klass.send(:generate_token) expiration = klass.send(:save_token, @request, user, token, params[:token][:lifetime], params[:token][:interval]) break rescue TokenExists next end end {token: token, valid_to: expiration} end |