Sha256: 07b878d2097d1bb125b8154e3b2337fbdd439432e6a5c4f7c4aa72951473f235

Contents?: true

Size: 1.3 KB

Versions: 23

Compression:

Stored size: 1.3 KB

Contents

module GraphqlDevise
  module Resolvers
    class CheckPasswordToken < Base
      argument :reset_password_token, String, required: true
      argument :redirect_url,         String, required: false

      def resolve(reset_password_token:, redirect_url: nil)
        resource = resource_class.with_reset_password_token(reset_password_token)
        raise_user_error(I18n.t('graphql_devise.passwords.reset_token_not_found')) if resource.blank?

        if resource.reset_password_period_valid?
          token_info = client_and_token(resource.create_token)

          resource.skip_confirmation! if confirmable_enabled? && !resource.confirmed_at
          resource.allow_password_change = true if recoverable_enabled?

          resource.save!

          yield resource if block_given?

          redirect_header_options = { reset_password: true }
          built_redirect_headers = redirect_headers(
            token_info,
            redirect_header_options
          )

          if redirect_url.present?
            controller.redirect_to(resource.build_auth_url(redirect_url, built_redirect_headers))
          else
            set_auth_headers(resource)
          end

          resource
        else
          raise_user_error(I18n.t('graphql_devise.passwords.reset_token_expired'))
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
graphql_devise-0.12.3 lib/graphql_devise/resolvers/check_password_token.rb
graphql_devise-0.12.2 lib/graphql_devise/resolvers/check_password_token.rb
graphql_devise-0.12.1 lib/graphql_devise/resolvers/check_password_token.rb
graphql_devise-0.12.0 lib/graphql_devise/resolvers/check_password_token.rb
graphql_devise-0.11.4 lib/graphql_devise/resolvers/check_password_token.rb
graphql_devise-0.11.3 lib/graphql_devise/resolvers/check_password_token.rb
graphql_devise-0.11.2 lib/graphql_devise/resolvers/check_password_token.rb
graphql_devise-0.11.1 lib/graphql_devise/resolvers/check_password_token.rb
graphql_devise-0.11.0 lib/graphql_devise/resolvers/check_password_token.rb
graphql_devise-0.10.1 app/graphql/graphql_devise/resolvers/check_password_token.rb
graphql_devise-0.10.0 app/graphql/graphql_devise/resolvers/check_password_token.rb
graphql_devise-0.9.2 app/graphql/graphql_devise/resolvers/check_password_token.rb
graphql_devise-0.9.1 app/graphql/graphql_devise/resolvers/check_password_token.rb
graphql_devise-0.9.0 app/graphql/graphql_devise/resolvers/check_password_token.rb
graphql_devise-0.8.1 app/graphql/graphql_devise/resolvers/check_password_token.rb
graphql_devise-0.8.0 app/graphql/graphql_devise/resolvers/check_password_token.rb
graphql_devise-0.7.0 app/graphql/graphql_devise/resolvers/check_password_token.rb
graphql_devise-0.6.0 app/graphql/graphql_devise/resolvers/check_password_token.rb
graphql_devise-0.5.0 app/graphql/graphql_devise/resolvers/check_password_token.rb
graphql_devise-0.4.1 app/graphql/graphql_devise/resolvers/check_password_token.rb