Sha256: d082bf09530baa94177bf062f75eeb6c420c1545f0fd7765e92841f019b205a9

Contents?: true

Size: 1.42 KB

Versions: 9

Compression:

Stored size: 1.42 KB

Contents

require_dependency "ishapi/application_controller"

module Ishapi
  class UsersController < ApplicationController

    skip_authorization_check only: %i| create fb_sign_in login |

    before_action :check_profile_hard, only: %i| account |

    def account
      @profile = current_user&.profile
      authorize! :show, @profile
      render 'ishapi/users/account'
    rescue CanCan::AccessDenied
      render json: {
        status: :not_ok,
      }, status: 401
    end

    def create
      @profile = Profile.new( email: params[:email] )
      @user = User.new( email: params[:email], password: params[:password], profile: @profile )

      if @profile.save && @user.save
        @jwt_token = encode(user_id: @user.id.to_s)
        render 'login'
      else
        render json: {
          messages: [],
        }, status: 401
      end
    end

    def fb_sign_in
      authorize! :fb_sign_in, Ishapi
      # render :json => { :status => :ok }
      render :action => 'show'
    end

    def login
      @current_user = User.where( email: params[:email] ).first

      if !@current_user
        render json: { status: :not_ok }, status: 401
        return
      end
      if @current_user.valid_password?(params[:password])
        # from: application_controller#long_term_token

        # send the jwt to client
        @jwt_token = encode(user_id: @current_user.id.to_s)
        @profile = @current_user.profile
      end
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ishapi-0.1.8.181 app/controllers/ishapi/users_controller.rb
ishapi-0.1.8.180 app/controllers/ishapi/users_controller.rb
ishapi-0.1.8.178 app/controllers/ishapi/users_controller.rb
ishapi-0.1.8.177 app/controllers/ishapi/users_controller.rb
ishapi-0.1.8.176 app/controllers/ishapi/users_controller.rb
ishapi-0.1.8.175 app/controllers/ishapi/users_controller.rb
ishapi-0.1.8.174 app/controllers/ishapi/users_controller.rb
ishapi-0.1.8.173 app/controllers/ishapi/users_controller.rb
ishapi-0.1.8.172 app/controllers/ishapi/users_controller.rb