<commit_before># encoding: UTF-8
# frozen_string_literal: true

# The User class provided by Parse with the required fields. You may
# add mixings to this class to add the app specific properties
require_relative '../object'
module Parse

  class UsernameMissingError < StandardError; end; # 200
  class PasswordMissingError < StandardError; end; # 201
  class UsernameTakenError < StandardError; end; # 202
  class EmailTakenError < StandardError; end; # 203
  class EmailMissing < StandardError; end; # 204

  class User < Parse::Object

    parse_class Parse::Model::CLASS_USER
    attr_accessor :session_token
    property :auth_data, :object
    property :email
    property :password
    property :username

    before_save do
      # You cannot specify user ACLs.
      self.clear_attribute_change!(:acl)
    end

    def anonymous?
      anonymous_id.nil?
    end

    def anonymous_id
      auth_data['anonymous']['id'] if auth_data.present? && auth_data["anonymous"].is_a?(Hash)
    end

    def link_auth_data!(service_name, **data)
      response = client.set_service_auth_data(id, service_name, data)
      apply_attributes!(response.result) if response.success?
      response.success?
    end

    def unlink_auth_data!(service_name)
      response = client.set_service_auth_data(id, service_name, nil)
      apply_attributes!(response.result) if response.success?
      response.success?
    end

    # So that apply_attributes! works with session_token for login
    def session_token_set_attribute!(token, track = false)
      @session_token = token.to_s
    end
    alias_method :sessionToken_set_attribute!, :session_token_set_attribute!

    def logged_in?
      self.session_token.present?
    end

    def request_password_reset
      return false if email.nil?
      Parse::User.request_password_reset(email)
    end

    def signup!(passwd = <PASSWORD>)
      self.password = <PASSWORD> || password
      if username.blank?
        raise Parse::UsernameMissingError, "Signup requires an username."
      end

      if password.blank?
        raise Parse::PasswordMissingError, "Signup requires a password."
      end

      signup_attrs = attributes_updates
      signup_attrs.except! *Parse::Properties::BASE_FIELD_MAP.flatten

      # first signup the user, then save any additional attributes
      response = client.signup signup_attrs

      if response.success?
        apply_attributes! response.result
        return true
      end

      case response.code
      when Parse::Response::ERROR_USERNAME_MISSING
        raise Parse::UsernameMissingError, response
      when Parse::Response::ERROR_PASSWORD_MISSING
        raise Parse::PasswordMissingError, response
      when Parse::Response::ERROR_USERNAME_TAKEN
        raise Parse::UsernameTakenError, response
      when Parse::Response::ERROR_EMAIL_TAKEN
        raise Parse::EmailTakenError, response<commit_msg>Fixes issues with signup.<commit_after># encoding: UTF-8
# frozen_string_literal: true

# The User class provided by Parse with the required fields. You may
# add mixings to this class to add the app specific properties
require_relative '../object'
module Parse

  class UsernameMissingError < StandardError; end; # 200
  class PasswordMissingError < StandardError; end; # 201
  class UsernameTakenError < StandardError; end; # 202
  class EmailTakenError < StandardError; end; # 203
  class EmailMissing < StandardError; end; # 204

  class User < Parse::Object

    parse_class Parse::Model::CLASS_USER
    attr_accessor :session_token
    property :auth_data, :object
    property :email
    property :password
    property :username

    before_save do
      # You cannot specify user ACLs.
      self.clear_attribute_change!(:acl)
    end

    def anonymous?
      anonymous_id.nil?
    end

    def anonymous_id
      auth_data['anonymous']['id'] if auth_data.present? && auth_data["anonymous"].is_a?(Hash)
    end

    def link_auth_data!(service_name, **data)
      response = client.set_service_auth_data(id, service_name, data)
      apply_attributes!(response.result) if response.success?
      response.success?
    end

    def unlink_auth_data!(service_name)
      response = client.set_service_auth_data(id, service_name, nil)
      apply_attributes!(response.result) if response.success?
      response.success?
    end

    # So that apply_attributes! works with session_token for login
    def session_token_set_attribute!(token, track = false)
      @session_token = token.to_s
    end
    alias_method :sessionToken_set_attribute!, :session_token_set_attribute!

    def logged_in?
      self.session_token.present?
    end

    def request_password_reset
      return false if email.nil?
      Parse::User.request_password_reset(email)
    end

    def signup!(passwd = <PASSWORD>)
      self.password = <PASSWORD> || password
      if username.blank?
        raise Parse::UsernameMissingError, "Signup requires an username."
      end

      if password.blank?
        raise Parse::PasswordMissingError, "Signup requires a password."
      end

      signup_attrs = attribute_updates
      signup_attrs.except! *Parse::Properties::BASE_FIELD_MAP.flatten

      # first signup the user, then save any additional attributes
      response = client.create_user signup_attrs

      if response.success?
        apply_attributes! response.result
        return true
      end

      case response.code
      when Parse::Response::ERROR_USERNAME_MISSING
        raise Parse::UsernameMissingError, response
      when Parse::Response::ERROR_PASSWORD_MISSING
        raise Parse::PasswordMissingError, response
      when Parse::Response::ERROR_USERNAME_TAKEN
        raise Parse::UsernameTakenError, response
      when Parse::Response::ERROR_EMAIL_TAKEN
        raise Parse::EmailTakenError, response
{'fraction_non_alphanumeric': 0.07479367262723521, 'fraction_numerical': 0.005502063273727648, 'mean_word_length': 3.464313123561013, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5263116', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1588, 'n_words': 434}