Class: ApiUserAuth::AuthController

Inherits:
ActionController::API
  • Object
show all
Defined in:
app/controllers/api_user_auth/auth_controller.rb

Overview

Registration/Login controller

Instance Method Summary collapse

Instance Method Details

#add_providerObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/api_user_auth/auth_controller.rb', line 53

def add_provider
  if request.headers['Authorization'].blank?
    raise Exceptions::Unauthorized,
          'Header [Authorization] can not be blank!'
  end
  token = request.headers['Authorization'].sub(/Bearer\s*=?/, '')
  auth_user = AuthUser.find_fy_token(token)
  if auth_user.present?
    if auth_user.(params)
      render json: auth_user.as_user_json, status: 200
    else
      render json: {}, status: 400
    end
  else
    render json: {}, status: 400
  end
end

#createObject



10
11
12
13
# File 'app/controllers/api_user_auth/auth_controller.rb', line 10

def create
  auth_user = AuthUser.create_by_params(base_params)
  render json: auth_user.to_json, status: 201
end

#forgot_passwordObject



27
28
29
30
31
32
# File 'app/controllers/api_user_auth/auth_controller.rb', line 27

def forgot_password
  auth_user = AuthUser.forgot_password(
    params.permit(:email)
  )
  render json: auth_user.to_json
end

#loginObject



15
16
17
18
# File 'app/controllers/api_user_auth/auth_controller.rb', line 15

def 
  auth_user = AuthUser.(base_params)
  render json: auth_user.to_json, status: 200
end

#logoutObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/api_user_auth/auth_controller.rb', line 34

def logout
  if request.headers['Authorization'].blank?
    raise Exceptions::Unauthorized,
          'Header [Authorization] can not be blank!'
  end
  token = request.headers['Authorization'].sub(/Bearer\s*=?/, '')
  auth_user = AuthUser.find_fy_token(token)
  if auth_user.present? && auth_user.logout(token)
    render json: {}, status: 200
  else
    render json: {}, status: 400
  end
end

#passwordObject



20
21
22
23
24
25
# File 'app/controllers/api_user_auth/auth_controller.rb', line 20

def password
  auth_user = AuthUser.update_password(
    params.permit(:email, :password, :code).to_h
  )
  render json: auth_user.to_json, status: 200
end

#providerObject



48
49
50
51
# File 'app/controllers/api_user_auth/auth_controller.rb', line 48

def provider
  auth_user = AuthUser.create_by_provider(params)
  render json: auth_user.to_json
end