app/controllers/cadenero/v1/account/sessions_controller.rb in cadenero-0.0.2.a2 vs app/controllers/cadenero/v1/account/sessions_controller.rb in cadenero-0.0.2.a3

- old
+ new

@@ -1,27 +1,26 @@ 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 - Rails.logger.info "params: #{params}" if env['warden'].authenticate(:password, :scope => :user) - render json: current_user, status: 201 + #return the user JSON on success + render json: current_user, status: :created else - render json: {errors: {user:["Invalid email or password"]}}, status: 422 + #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]) - Rails.logger.info "id: #{params[:id]}" - Rails.logger.info "user: #{user.to_json}" - Rails.logger.info "current_user.id: #{current_user}" - Rails.logger.info "user_signed_in?: #{user_signed_in?}" - if user_signed_in? + if user_signed_in? env['warden'].logout(:user) - render json: {message: "Successful logout"}, status: 201 + render json: {message: "Successful logout"}, status: :ok else - render json: {message: "Unsuccessful logout user with id"}, status: 401 + render json: {message: "Unsuccessful logout user with id"}, status: :forbidden end end end end