Class: Api::V1::UserController

Inherits:
ApiController
  • Object
show all
Defined in:
app/controllers/api/v1/user_controller.rb

Instance Method Summary collapse

Instance Method Details

#showObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/api/v1/user_controller.rb', line 6

def show
  if doorkeeper_token.scopes.exists?(:name)
    @name = current_user.name
  end

  if doorkeeper_token.scopes.exists?(:email)
    @email = current_user.email
  end

  @id = current_user.id
  @created_at = current_user.created_at
  @updated_at = current_user.updated_at
  @verified = current_user.verified

  if doorkeeper_token.scopes.exists?(:admin)
    @admin = current_user.admin
  end
end

#updateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/api/v1/user_controller.rb', line 25

def update
  redirected = false

  if params[:name]
    if doorkeeper_authorize! :name_write
      redirected = true
    else
      current_user.update!(name: params[:name])
    end
  end

  if params[:email]
    if doorkeeper_authorize! :email_write
      redirected = true
    else
      current_user.update!(email: params[:email])
    end
  end

  if !redirected
    show
    render "show"
  end
end