Sha256: c949456c869ba0d45a2c53ead627c2a48e6c725e427e889849ebd2242bf873e8

Contents?: true

Size: 953 Bytes

Versions: 9

Compression:

Stored size: 953 Bytes

Contents

module ApiUserAuth
  # Auth user helper
  module AuthUserHelper
    extend ActiveSupport::Concern

    # Class methods
    module ClassMethods
      def create_by_params(params)
        email_exception if params[:email].blank?
        password_exception if params[:password].blank?

        auth_user = AuthUser.find_or_initialize_by(email: params[:email])

        if auth_user.new_record?
          auth_user.is_new = true
          auth_user.update_password(params[:password])
        else
          user_exist_exception
        end
        auth_user
      end

      private

      def email_exception
        raise Exceptions::WrongParams, I18n.t('api_user_auth.errors.email')
      end

      def password_exception
        raise Exceptions::WrongParams, I18n.t('api_user_auth.errors.password')
      end

      def user_exist_exception
        raise Exceptions::WrongParams, I18n.t('api_user_auth.errors.user_exist')
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
api_user_auth-0.1.9 app/models/concerns/api_user_auth/auth_user_helper.rb
api_user_auth-0.1.8 app/models/concerns/api_user_auth/auth_user_helper.rb
api_user_auth-0.1.7 app/models/concerns/api_user_auth/auth_user_helper.rb
api_user_auth-0.1.6 app/models/concerns/api_user_auth/auth_user_helper.rb
api_user_auth-0.1.5 app/models/concerns/api_user_auth/auth_user_helper.rb
api_user_auth-0.1.4 app/models/concerns/api_user_auth/auth_user_helper.rb
api_user_auth-0.1.2 app/models/concerns/api_user_auth/auth_user_helper.rb
api_user_auth-0.1.1 app/models/concerns/api_user_auth/auth_user_helper.rb
api_user_auth-0.1.0 app/models/concerns/api_user_auth/auth_user_helper.rb