Sha256: 1fa429219b126f9d80013788ddd9ae9d0649c0d97ff0125471e58addc64b1aec

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

class Ishapi::Users::SessionsController < Devise::SessionsController
  skip_before_action :verify_authenticity_token

  def create
    self.resource = warden.authenticate!(auth_options)
    set_flash_message!(:notice, :signed_in)
    sign_in(resource_name, resource)
    yield resource if block_given?
    # respond_with resource, location: after_sign_in_path_for(resource)

    ## Send the jwt to client
    @jwt_token = encode(user_id: @current_user.id.to_s)
    @profile = @current_user.profile
    render 'ishapi/users/login', format: :json, layout: false
  end

  private

  ## copy-pasted from application_controller
  ## jwt
  def decode(token)
    decoded = JWT.decode(token, Rails.application.secrets.secret_key_base.to_s)[0]
    HashWithIndifferentAccess.new decoded
  end

  ## copy-pasted from application_controller
  ## jwt
  def encode(payload, exp = 48.hours.from_now) # @TODO: definitely change, right now I expire once in 2 days.
    payload[:exp] = exp.to_i
    JWT.encode(payload, Rails.application.secrets.secret_key_base.to_s)
  end


end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ishapi-0.1.8.188 app/controllers/ishapi/users/sessions_controller.rb
ishapi-0.1.8.187 app/controllers/ishapi/users/sessions_controller.rb
ishapi-0.1.8.185 app/controllers/ishapi/users/sessions_controller.rb
ishapi-0.1.8.184 app/controllers/ishapi/users/sessions_controller.rb
ishapi-0.1.8.183 app/controllers/ishapi/users/sessions_controller.rb
ishapi-0.1.8.182 app/controllers/ishapi/users/sessions_controller.rb