diff options
author | HombreLaser <sebastian-440@live.com> | 2023-02-25 00:20:47 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2023-02-25 00:20:47 -0600 |
commit | 6f0540d9de018f7dc9f474bdc619c8231282f19d (patch) | |
tree | 7f9fb2c6a9f5ec5d237161be49bac8e3eeed29c0 /app | |
parent | a64b2dfeb543ef38f4c7cd38eb05baec9e84a2d9 (diff) |
Arregla controlador de usuarios
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/api/user_accounts_controller.rb | 15 | ||||
-rw-r--r-- | app/models/user_account.rb | 3 |
2 files changed, 7 insertions, 11 deletions
diff --git a/app/controllers/api/user_accounts_controller.rb b/app/controllers/api/user_accounts_controller.rb index b95105f..3e03cf9 100644 --- a/app/controllers/api/user_accounts_controller.rb +++ b/app/controllers/api/user_accounts_controller.rb @@ -10,24 +10,17 @@ module Api end def create - @user_account = UserAccount.new(permitted_params) + @token = logic(permitted_params).call - unless @user_account.save - render json: { errors: @user_account.errors.full_messages }, status: :unprocessable_entity - return - end + render json: @token, status: :ok and return if @token - render json: Serializers::UserAccountSerializer.new(@user_account).serializable_hash + render json: { errors: @logic.user_account.errors.full_messages }, status: :unprocessable_entity end private def permitted_params - params.require(:user_account).permit(:email, :first_name, :last_name, :password) - end - - def serialized_user_account - @serialized_user_account ||= Serializers::UserAccountSerializer.new(current_user_account) + params.require(:user_account).permit(:role, :email, :first_name, :last_name, :password) end end end diff --git a/app/models/user_account.rb b/app/models/user_account.rb index ceb8334..e50961b 100644 --- a/app/models/user_account.rb +++ b/app/models/user_account.rb @@ -9,6 +9,9 @@ class UserAccount < ApplicationRecord has_secure_password validations: false validates :email, presence: true + validates :password, presence: true + validates_format_of :email, + with: /\A(|(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6})\z/i validates :first_name, presence: true validates :last_name, presence: true validates :role, presence: true, inclusion: { in: %w[master regular] } |