sticapi_client 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
 - data/lib/generators/sticapi_client/install_generator.rb +0 -0
 - data/lib/generators/sticapi_client/templates/sticapi.yml +0 -0
 - data/lib/sticapi_client/etjpi.rb +0 -0
 - data/lib/sticapi_client/intranet.rb +7 -0
 - data/lib/sticapi_client/sticapi_controller.rb +0 -0
 - data/lib/sticapi_client/sticapi_devise_strategy.rb +65 -39
 - data/lib/sticapi_client/version.rb +1 -1
 - data/lib/sticapi_client.rb +0 -1
 - metadata +4 -4
 - data/lib/sticapi_client/sip.rb +0 -7
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: '084c3daf5fec27576f77895e5584dbee80c923fd3658b55d189c43c56eb52f45'
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: cfef2715e6012f123bef69796bd08aaeb9209e6212a3c14b542dfa51e29a760e
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 72d3591bf062171141f150753baf8fed511e344ec1f7b3769802107911c8e632f9f1bcc86953348529fc4c0137d67c5d9c9396fdf8bf59941601da03b78c08f7
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: ce697b3373443a3824743db757921d364b34bff715a3fbfa167009d0a4c222a2ed0a369e530ca446a0c97fd2f81f95a4ddecde0b4687d4c7a944d81e3e1935df
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
    
        data/lib/sticapi_client/etjpi.rb
    CHANGED
    
    | 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
| 
         @@ -11,49 +11,75 @@ module Devise 
     | 
|
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
                  def authenticate!
         
     | 
| 
       13 
13 
     | 
    
         
             
                    if params[:user]
         
     | 
| 
       14 
     | 
    
         
            -
                       
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                         
     | 
| 
       17 
     | 
    
         
            -
                         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 14 
     | 
    
         
            +
                      if params[:user].has_key?(:username) || params[:user].has_key?(:email)
         
     | 
| 
      
 15 
     | 
    
         
            +
                        field = params[:user][:username]
         
     | 
| 
      
 16 
     | 
    
         
            +
                        field ||= params[:user][:email]
         
     | 
| 
      
 17 
     | 
    
         
            +
                        if field.include? '@'
         
     | 
| 
      
 18 
     | 
    
         
            +
                          resource  = password.present? && mapping.to.find_for_database_authentication(authentication_hash)
         
     | 
| 
      
 19 
     | 
    
         
            +
                          hashed = false
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                      request['client'] = Sticapi::SticapiClient.instance.client
         
     | 
| 
       27 
     | 
    
         
            -
                      request['uid'] = Sticapi::SticapiClient.instance.uid
         
     | 
| 
       28 
     | 
    
         
            -
                      request.body = { data: token }.to_json
         
     | 
| 
       29 
     | 
    
         
            -
                      response = http.request(request)
         
     | 
| 
       30 
     | 
    
         
            -
                      Sticapi::SticapiClient.instance.update_token(response)
         
     | 
| 
      
 21 
     | 
    
         
            +
                          if validate(resource){ hashed = true; resource.valid_password?(password) }
         
     | 
| 
      
 22 
     | 
    
         
            +
                            remember_me(resource)
         
     | 
| 
      
 23 
     | 
    
         
            +
                            resource.after_database_authentication
         
     | 
| 
      
 24 
     | 
    
         
            +
                            success!(resource)
         
     | 
| 
      
 25 
     | 
    
         
            +
                          end
         
     | 
| 
       31 
26 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                          if data['user']
         
     | 
| 
       36 
     | 
    
         
            -
                            unless user = User.find_by(username: data['user']['username'])
         
     | 
| 
       37 
     | 
    
         
            -
                              user = User.new
         
     | 
| 
       38 
     | 
    
         
            -
                              user.name = data['user']['name'] if user.respond_to? :name
         
     | 
| 
       39 
     | 
    
         
            -
                              user.username = data['user']['username'] if user.respond_to? :username
         
     | 
| 
       40 
     | 
    
         
            -
                              user.email = data['user']['email']
         
     | 
| 
       41 
     | 
    
         
            -
                              user.cpf = data['user']['cpf'] if user.respond_to? :cpf
         
     | 
| 
       42 
     | 
    
         
            -
                              user.password = params[:user][:password]
         
     | 
| 
       43 
     | 
    
         
            -
                            end
         
     | 
| 
       44 
     | 
    
         
            -
                            user.unities = data['user']['unities'] if user.respond_to? :unities
         
     | 
| 
       45 
     | 
    
         
            -
                            user.save
         
     | 
| 
       46 
     | 
    
         
            -
                            success!(user)
         
     | 
| 
       47 
     | 
    
         
            -
                            return
         
     | 
| 
       48 
     | 
    
         
            -
                          else
         
     | 
| 
       49 
     | 
    
         
            -
                            return fail(:invalid)
         
     | 
| 
      
 27 
     | 
    
         
            +
                          mapping.to.new.password = password if !hashed && Devise.paranoid
         
     | 
| 
      
 28 
     | 
    
         
            +
                          unless resource
         
     | 
| 
      
 29 
     | 
    
         
            +
                            Devise.paranoid ? fail(:invalid) : fail(:not_found_in_database)
         
     | 
| 
       50 
30 
     | 
    
         
             
                          end
         
     | 
| 
       51 
     | 
    
         
            -
                        when Net::HTTPUnauthorized
         
     | 
| 
       52 
     | 
    
         
            -
                          return fail(:invalid)
         
     | 
| 
       53 
     | 
    
         
            -
                        when Net::HTTPServerError
         
     | 
| 
       54 
     | 
    
         
            -
                          return fail(:invalid)
         
     | 
| 
       55 
31 
     | 
    
         
             
                        else
         
     | 
| 
       56 
     | 
    
         
            -
                           
     | 
| 
      
 32 
     | 
    
         
            +
                          secret = Sticapi::SticapiClient.instance.access_token
         
     | 
| 
      
 33 
     | 
    
         
            +
                          payload = {
         
     | 
| 
      
 34 
     | 
    
         
            +
                            user: field,
         
     | 
| 
      
 35 
     | 
    
         
            +
                            password: params[:user][:password]
         
     | 
| 
      
 36 
     | 
    
         
            +
                          }
         
     | 
| 
      
 37 
     | 
    
         
            +
                          token = JWT.encode payload, secret, 'HS256'
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                          uri = URI.parse("#{Sticapi::SticapiClient.instance.uri}/users/log_in")
         
     | 
| 
      
 40 
     | 
    
         
            +
                          http = Net::HTTP.new(uri.host, uri.port)
         
     | 
| 
      
 41 
     | 
    
         
            +
                          request = Net::HTTP::Post.new(uri.request_uri)
         
     | 
| 
      
 42 
     | 
    
         
            +
                          request['Content-Type'] = 'application/json'
         
     | 
| 
      
 43 
     | 
    
         
            +
                          request['access-token'] = Sticapi::SticapiClient.instance.access_token
         
     | 
| 
      
 44 
     | 
    
         
            +
                          request['client'] = Sticapi::SticapiClient.instance.client
         
     | 
| 
      
 45 
     | 
    
         
            +
                          request['uid'] = Sticapi::SticapiClient.instance.uid
         
     | 
| 
      
 46 
     | 
    
         
            +
                          request.body = { data: token }.to_json
         
     | 
| 
      
 47 
     | 
    
         
            +
                          response = http.request(request)
         
     | 
| 
      
 48 
     | 
    
         
            +
                          Sticapi::SticapiClient.instance.update_token(response)
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                          case response
         
     | 
| 
      
 51 
     | 
    
         
            +
                            when Net::HTTPSuccess
         
     | 
| 
      
 52 
     | 
    
         
            +
                              data = JSON.parse(response.body)
         
     | 
| 
      
 53 
     | 
    
         
            +
                              if data['user']
         
     | 
| 
      
 54 
     | 
    
         
            +
                                unless user = User.find_by(username: data['user']['username'])
         
     | 
| 
      
 55 
     | 
    
         
            +
                                  user = User.new
         
     | 
| 
      
 56 
     | 
    
         
            +
                                  user.name = data['user']['name'] if user.respond_to? :name
         
     | 
| 
      
 57 
     | 
    
         
            +
                                  user.username = data['user']['username'] if user.respond_to? :username
         
     | 
| 
      
 58 
     | 
    
         
            +
                                  user.email = data['user']['email']
         
     | 
| 
      
 59 
     | 
    
         
            +
                                  user.cpf = data['user']['cpf'] if user.respond_to? :cpf
         
     | 
| 
      
 60 
     | 
    
         
            +
                                  user.password = params[:user][:password]
         
     | 
| 
      
 61 
     | 
    
         
            +
                                  user.password_confirmation = params[:user][:password] if user.respond_to? :password_confirmation
         
     | 
| 
      
 62 
     | 
    
         
            +
                                end
         
     | 
| 
      
 63 
     | 
    
         
            +
                                user.unities = data['user']['unities'] if user.respond_to? :unities
         
     | 
| 
      
 64 
     | 
    
         
            +
                                user.skip_confirmation!
         
     | 
| 
      
 65 
     | 
    
         
            +
                                user.save
         
     | 
| 
      
 66 
     | 
    
         
            +
                                puts user.errors.full_messages
         
     | 
| 
      
 67 
     | 
    
         
            +
                                success!(user)
         
     | 
| 
      
 68 
     | 
    
         
            +
                                puts user.errors.full_messages
         
     | 
| 
      
 69 
     | 
    
         
            +
                                return
         
     | 
| 
      
 70 
     | 
    
         
            +
                              else
         
     | 
| 
      
 71 
     | 
    
         
            +
                                return fail(:invalid)
         
     | 
| 
      
 72 
     | 
    
         
            +
                              end
         
     | 
| 
      
 73 
     | 
    
         
            +
                            when Net::HTTPUnauthorized
         
     | 
| 
      
 74 
     | 
    
         
            +
                              return fail(:invalid)
         
     | 
| 
      
 75 
     | 
    
         
            +
                            when Net::HTTPServerError
         
     | 
| 
      
 76 
     | 
    
         
            +
                              return fail(:invalid)
         
     | 
| 
      
 77 
     | 
    
         
            +
                            else
         
     | 
| 
      
 78 
     | 
    
         
            +
                              return fail(:invalid)
         
     | 
| 
      
 79 
     | 
    
         
            +
                          end
         
     | 
| 
      
 80 
     | 
    
         
            +
                        end
         
     | 
| 
      
 81 
     | 
    
         
            +
                      else
         
     | 
| 
      
 82 
     | 
    
         
            +
                        return fail(:invalid)
         
     | 
| 
       57 
83 
     | 
    
         
             
                      end
         
     | 
| 
       58 
84 
     | 
    
         
             
                    end
         
     | 
| 
       59 
85 
     | 
    
         
             
                    return fail(:invalid)
         
     | 
    
        data/lib/sticapi_client.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: sticapi_client
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.8
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Ricardo Viana
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: exe
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2018- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2018-10-31 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rails
         
     | 
| 
         @@ -105,7 +105,7 @@ files: 
     | 
|
| 
       105 
105 
     | 
    
         
             
            - lib/generators/sticapi_client/templates/sticapi.yml
         
     | 
| 
       106 
106 
     | 
    
         
             
            - lib/sticapi_client.rb
         
     | 
| 
       107 
107 
     | 
    
         
             
            - lib/sticapi_client/etjpi.rb
         
     | 
| 
       108 
     | 
    
         
            -
            - lib/sticapi_client/ 
     | 
| 
      
 108 
     | 
    
         
            +
            - lib/sticapi_client/intranet.rb
         
     | 
| 
       109 
109 
     | 
    
         
             
            - lib/sticapi_client/sticapi_controller.rb
         
     | 
| 
       110 
110 
     | 
    
         
             
            - lib/sticapi_client/sticapi_devise_strategy.rb
         
     | 
| 
       111 
111 
     | 
    
         
             
            - lib/sticapi_client/version.rb
         
     | 
| 
         @@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       129 
129 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       130 
130 
     | 
    
         
             
            requirements: []
         
     | 
| 
       131 
131 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       132 
     | 
    
         
            -
            rubygems_version: 2. 
     | 
| 
      
 132 
     | 
    
         
            +
            rubygems_version: 2.7.7
         
     | 
| 
       133 
133 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       134 
134 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       135 
135 
     | 
    
         
             
            summary: Client to use TJPI sticapi services
         
     |