Class: Unsakini::UsersController

Inherits:
BaseController
  • Object
show all
Includes:
ActionController::Serialization, LoggedInControllerConcern
Defined in:
app/controllers/unsakini/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#confirmObject

confirm user account



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

def confirm
  token = params[:token].to_s

  user = User.find_by(confirmation_token: token)

  if user.present? && user.confirmation_token_valid?
    if user.mark_as_confirmed!
      render json: {status: 'User confirmed successfully'}, status: :ok
    else
      render json: user.errors, status: 422
    end
  else
    render json: ['Invalid token'], status: :not_found
  end
end

#createObject

Creates a new user



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

def create
  user = User.new(user_params)

  if user.save
    UserMailer.(user).deliver_now
    render json: user, status: :created
  else
    render json: user.errors, status: 422
  end
end

#searchObject

Returns the user with matching email

‘GET /api/users/search?email=xxx`



51
52
53
54
55
56
57
58
# File 'app/controllers/unsakini/users_controller.rb', line 51

def search
  user = User.where("email = ? AND id != ?", params[:email], @user.id).first
  if user
    render json: user
  else
    render json: {}, status: :not_found
  end
end

#showObject

Renders the current user as json

‘GET /api/user/:id`



43
44
45
# File 'app/controllers/unsakini/users_controller.rb', line 43

def show
  render json: @user
end