Class: Unsakini::UsersController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Unsakini::UsersController
- Includes:
- ActionController::Serialization, LoggedInControllerConcern
- Defined in:
- app/controllers/unsakini/users_controller.rb
Instance Method Summary collapse
-
#confirm ⇒ Object
confirm user account.
-
#create ⇒ Object
Creates a new user.
-
#search ⇒ Object
Returns the user with matching email.
-
#show ⇒ Object
Renders the current user as json.
Instance Method Details
#confirm ⇒ Object
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 |
#create ⇒ Object
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.confirm_account(user).deliver_now render json: user, status: :created else render json: user.errors, status: 422 end end |
#search ⇒ Object
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 |
#show ⇒ Object
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 |