Class: Securial::AccountsController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- Securial::AccountsController
- Defined in:
- app/controllers/securial/accounts_controller.rb
Overview
AccountsController
This controller handles user account-related operations including:
- User registration
- Profile viewing and management
- Account updates
- Account deletion
Routes typically mounted at Securial/accounts/* in the host application.
Instance Method Summary collapse
-
#delete_account ⇒ void
Permanently deletes the current user’s account.
-
#me ⇒ void
Retrieves the current user’s profile.
-
#register ⇒ void
Registers a new user account.
-
#render_user_profile ⇒ void
private
Renders the user profile or a not found response.
-
#show ⇒ void
Shows a specific user’s profile by username.
-
#update_profile ⇒ void
Updates the current user’s profile information.
-
#user_params ⇒ ActionController::Parameters
private
Permits and extracts user parameters from the request.
Methods inherited from ApplicationController
Instance Method Details
#delete_account ⇒ void
This method returns an undefined value.
Permanently deletes the current user’s account.
Removes the user account and all associated data after password verification.
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/controllers/securial/accounts_controller.rb', line 93 def delete_account @securial_user = Current.user if @securial_user.authenticate(params.expect(securial_user: [:current_password]).dig(:current_password)) @securial_user.destroy render json: { message: "Account deleted successfully" }, status: :ok else render json: { errors: ["Current password is incorrect"], instructions: "Please verify your current password and try again.", }, status: :unprocessable_entity end end |
#me ⇒ void
This method returns an undefined value.
Retrieves the current user’s profile.
Provides the authenticated user’s complete profile information. Requires authentication via the Identity concern.
20 21 22 23 24 |
# File 'app/controllers/securial/accounts_controller.rb', line 20 def me @securial_user = Current.user render :show, status: :ok, location: @securial_user end |
#register ⇒ void
This method returns an undefined value.
Registers a new user account.
Creates a new user in the system with the provided registration information.
51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/securial/accounts_controller.rb', line 51 def register @securial_user = Securial::User.new(user_params) if @securial_user.save render :show, status: :created, location: @securial_user else render json: { errors: @securial_user.errors. }, status: :unprocessable_entity end end |
#render_user_profile ⇒ void (private)
This method returns an undefined value.
Renders the user profile or a not found response.
120 121 122 123 124 125 126 127 128 129 |
# File 'app/controllers/securial/accounts_controller.rb', line 120 def render_user_profile if @securial_user render :show, status: :ok, location: @securial_user else render json: { errors: ["User not found"], instructions: "Please check the username and try again.", }, status: :not_found end end |
#show ⇒ void
This method returns an undefined value.
Shows a specific user’s profile by username.
Retrieves and displays public profile information for the requested user. Requires the ‘enable_other_profiles` configuration to be true.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/securial/accounts_controller.rb', line 33 def show if Securial.configuration.enable_other_profiles @securial_user = Securial::User.find_by(username: params.expect(:username)) render_user_profile else render json: { errors: ["User profiles are not enabled"], instructions: "Please contact support for assistance.", }, status: :forbidden end end |
#update_profile ⇒ void
This method returns an undefined value.
Updates the current user’s profile information.
Allows users to modify their profile after authenticating with their current password.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/securial/accounts_controller.rb', line 68 def update_profile @securial_user = Current.user if @securial_user.authenticate(params[:securial_user][:current_password]) if @securial_user.update(user_params) render :show, status: :ok, location: @securial_user else render json: { errors: @securial_user.errors., instructions: "Please ensure all required fields are filled out correctly.", }, status: :unprocessable_entity end else render json: { errors: ["Current password is incorrect"], instructions: "Please verify your current password and try again.", }, status: :unprocessable_entity end end |
#user_params ⇒ ActionController::Parameters (private)
Permits and extracts user parameters from the request.
112 113 114 |
# File 'app/controllers/securial/accounts_controller.rb', line 112 def user_params params.expect(securial_user: [:email_address, :password, :password_confirmation, :first_name, :last_name, :phone, :username, :bio]) end |