Sha256: ea4d3f58136572b16cb74b1b6ef6e3fc412aedd728560c18ca8ae8a45d55ee59

Contents?: true

Size: 1.06 KB

Versions: 8

Compression:

Stored size: 1.06 KB

Contents

require_dependency "cadenero/application_controller"
#NameSpace for the V1 API in Cadenero
module Cadenero::V1
  # Controller for managing sessions for the API if you are using the :password Strategy
  class Account::SessionsController < Cadenero::ApplicationController
    # create the session for the user using the password strategy and returning the user JSON
    def create
      if env['warden'].authenticate(:password, :scope => :user)
        #return the user JSON on success
        render json: current_user, status: :created
      else
        #return error mesage in a JSON on error
        render json: {errors: {user:["Invalid email or password"]}}, status: :unprocessable_entity
      end
    end

    # destroy the session for the user using params id
    def delete
      user = Cadenero::User.find_by_id(params[:id])
      if user_signed_in?
        env['warden'].logout(:user)
        render json: {message: "Successful logout"}, status: :ok
      else
        render json: {message: "Unsuccessful logout user with id"}, status: :forbidden
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
cadenero-0.0.2.b10 app/controllers/cadenero/v1/account/sessions_controller.rb
cadenero-0.0.2.b8 app/controllers/cadenero/v1/account/sessions_controller.rb
cadenero-0.0.2.b7 app/controllers/cadenero/v1/account/sessions_controller.rb
cadenero-0.0.2.b6 app/controllers/cadenero/v1/account/sessions_controller.rb
cadenero-0.0.2.b5 app/controllers/cadenero/v1/account/sessions_controller.rb
cadenero-0.0.2.b4 app/controllers/cadenero/v1/account/sessions_controller.rb
cadenero-0.0.2.b2 app/controllers/cadenero/v1/account/sessions_controller.rb
cadenero-0.0.2.b1 app/controllers/cadenero/v1/account/sessions_controller.rb