Sha256: f5eaaa8331f598439cba75d248d1e05c8887929589842a15ff88906383c5efa8

Contents?: true

Size: 992 Bytes

Versions: 1

Compression:

Stored size: 992 Bytes

Contents

require_dependency "cadenero/application_controller"
# COntroller for managing sessions for the API if you are using the :password Strategy
module Cadenero::V1
  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

    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

1 entries across 1 versions & 1 rubygems

Version Path
cadenero-0.0.2.a3 app/controllers/cadenero/v1/account/sessions_controller.rb