Class: Droom::Api::UsersController

Inherits:
ApiController show all
Defined in:
app/controllers/droom/api/users_controller.rb

Instance Method Summary collapse

Methods inherited from ApiController

#current_ability

Methods inherited from EngineController

#current_ability

Instance Method Details

#authenticateObject

This is a almost always a preliminary call at the initial auth stage, so the client is not yet setting auth headers. We look for a token in params too.



21
22
23
24
25
26
27
28
# File 'app/controllers/droom/api/users_controller.rb', line 21

def authenticate
  token = params[:tok]
  if @user = Droom::User.find_by(authentication_token: token)
    render json: @user
  else
    head :unauthorized
  end
end

#createObject



49
50
51
52
53
54
55
# File 'app/controllers/droom/api/users_controller.rb', line 49

def create
  if @user && @user.persisted?
    render json: @user
  else
    render json: { errors: @user.errors.to_a }
  end
end

#deauthenticateObject

deauth is used to achieve single-sign-out. It changes the auth token and session id so that neither the data room session cookie nor the domain auth cookie can identify a user.



33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/droom/api/users_controller.rb', line 33

def deauthenticate
  token = params[:tok]
  if @user = Droom::User.find_by(authentication_token: token)
    @user.clear_session_id!
    @user.reset_authentication_token!
    render json: @user
  else
    head :unauthorized
  end
end

#destroyObject



57
58
59
60
# File 'app/controllers/droom/api/users_controller.rb', line 57

def destroy
  @user.destroy
  head :ok
end

#indexObject



10
11
12
# File 'app/controllers/droom/api/users_controller.rb', line 10

def index
  render json: @users
end

#showObject



14
15
16
# File 'app/controllers/droom/api/users_controller.rb', line 14

def show
  render json: @user
end

#updateObject



44
45
46
47
# File 'app/controllers/droom/api/users_controller.rb', line 44

def update
  @user.update_attributes(user_params)
  render json: @user
end