Class: Ishapi::UsersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ishapi/users_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#home, #long_term_token, #vote

Instance Method Details

#accountObject



11
12
13
14
15
16
17
18
19
# File 'app/controllers/ishapi/users_controller.rb', line 11

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

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/ishapi/users_controller.rb', line 21

def create
  authorize! :open_permission, Ishapi
  new_user_params = params[:user].permit!

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

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

#fb_sign_inObject



38
39
40
41
42
# File 'app/controllers/ishapi/users_controller.rb', line 38

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