<commit_before># frozen_string_literal: true

module Api
  class SignInForm
    include ActiveModel::Model

    attr_accessor :email, :password, :name, :device_type, :device_token

    validates :email, presence: true

    validates :password, presence: true

    validate :user_presence

    validate :user_password

    delegate :id, :token, to: :session

    def save
      return false if !valid?

      # TODO: add this
      # PushNotifications::NewSignIn.new(device, device_token, user.notifications_count).execute!

      session.save!
    end

    def user
      @user ||= User.where('LOWER(email) = LOWER(?)', email).first
    end

    def user_presence
      return if errors.any?

      errors.add(:base, 'Email and/or password is invalid') if !user
    end

    def user_password
      return if errors.any?

      errors.add(:base, 'Email and/or password is invalid') if user && !user.authenticate(password)
    end

    def session
      @session ||= user.sessions.build(name: name,
                                       device_type: device_type,
                                       device_token: device_token)
    end
  end
end
<commit_msg>Add todo note<commit_after># frozen_string_literal: true

module Api
  class SignInForm
    include ActiveModel::Model

    attr_accessor :email, :password, :name, :device_type, :device_token

    validates :email, presence: true

    validates :password, presence: true

    validate :user_presence

    validate :user_password

    delegate :id, :token, to: :session

    def save
      return false if !valid?

      # TODO: add this
      # PushNotifications::NewSignIn.new(device, device_token, user.notifications_count).execute!
      # Notifications::NewSignInMailer

      session.save!
    end

    def user
      @user ||= User.where('LOWER(email) = LOWER(?)', email).first
    end

    def user_presence
      return if errors.any?

      errors.add(:base, 'Email and/or password is invalid') if !user
    end

    def user_password
      return if errors.any?

      errors.add(:base, 'Email and/or password is invalid') if user && !user.authenticate(password)
    end

    def session
      @session ||= user.sessions.build(name: name,
                                       device_type: device_type,
                                       device_token: device_token)
    end
  end
end

{'fraction_non_alphanumeric': 0.08944467994913098, 'fraction_numerical': 0.0, 'mean_word_length': 2.4054834054834053, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3075884', 'n_tokens_mistral': 706, 'n_tokens_neox': 669, 'n_words': 191}