<commit_before>module DiabeticToolbox::Members
  class Session
    require 'digest'
    require 'cgi'

    def initialize(env, params)
      @env     = env
      @params  = params
      @member  = nil
      @success = false
    end

    ##
    # Returns the DiabeticToolbox::Member upon successful session creation.
    #
    # :call-seq:
    #   create(member_params) => DiabeticToolbox::Member
    #
    def create
      @member = DiabeticToolbox::Member.find_by_email @params['email']

      if @member.present?
        @success = true
        return @member if authenticates?(@params['password']) && housekeeping?
      end
    end

    def in_progress?
      @success
    end

    def result_message
      if in_progress?
        I18n.t('views.member_sessions.messages.login_success')
      else
        I18n.t('views.member_sessions.messages.login_failure')
      end
    end

    ##
    # Returns the DiabeticToolbox::Member that matches the session token.
    #
    # :call-seq:
    #   find(session_token) => DiabeticToolbox::Member
    #
    def self.find(session_token)
      @member = DiabeticToolbox::Member.find_by_session_token(session_token) if session_token.present?
      @member
    end

    ##
    # Destroy the member with the provided session token.
    #
    # :call-seq:
    #   destroy(session_token) => Boolean
    #
    def self.destroy(session_token)
      @member = self.find(session_token)
      return true if @member && self.clear
    end

    # :enddoc:
    private
      def authenticates?(password)
        @member && @member.authenticate(password)
      end

      def housekeeping?
        updates = {
            last_session_began_at: @member.current_session_began_at,
            last_session_ip: @member.current_session_ip,
            session_token: new_session_token,
            current_session_began_at: Time.now,
            current_session_ip: @env['REMOTE_ADDR']
        }

        @member.update_attributes updates
      end
<commit_msg>authenticate! is now used as the preferred method.<commit_after>module DiabeticToolbox::Members
  class Session
    require 'digest'
    require 'cgi'

    def initialize(env, params)
      @env     = env
      @params  = params
      @member  = nil
      @success = false
    end

    ##
    # Returns the DiabeticToolbox::Member upon successful session creation.
    #
    # :call-seq:
    #   create(member_params) => DiabeticToolbox::Member
    #
    def create
      @member = DiabeticToolbox::Member.find_by_email @params['email']

      if @member.present?
        @success = true
        return @member if authenticates?(@params['password']) && housekeeping?
      end
    end

    def in_progress?
      @success
    end

    def result_message
      if in_progress?
        I18n.t('views.member_sessions.messages.login_success')
      else
        I18n.t('views.member_sessions.messages.login_failure')
      end
    end

    ##
    # Returns the DiabeticToolbox::Member that matches the session token.
    #
    # :call-seq:
    #   find(session_token) => DiabeticToolbox::Member
    #
    def self.find(session_token)
      @member = DiabeticToolbox::Member.find_by_session_token(session_token) if session_token.present?
      @member
    end

    ##
    # Destroy the member with the provided session token.
    #
    # :call-seq:
    #   destroy(session_token) => Boolean
    #
    def self.destroy(session_token)
      @member = self.find(session_token)
      return true if @member && self.clear
    end

    # :enddoc:
    private
      def authenticates?(password)
        @member && @member.authenticate!(password)
      end

      def housekeeping?
        updates = {
            last_session_began_at: @member.current_session_began_at,
            last_session_ip: @member.current_session_ip,
            session_token: new_session_token,
            current_session_began_at: Time.now,
            current_session_ip: @env['REMOTE_ADDR']
        }

        @member.update_attributes updates
      end

{'fraction_non_alphanumeric': 0.09152119700748129, 'fraction_numerical': 0.00199501246882793, 'mean_word_length': 2.413617021276596, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4256702', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1185, 'n_words': 251}