<commit_before>class User < ApplicationRecord
  has_one :user_profile, :dependent => :destroy
  has_many :user_roles
  has_many :roles, through: :user_roles
  has_many :notifications
  has_many :course_user_ships
  has_many :courses, through: :course_user_ships
  has_many :consults
  has_many :course_user_scores
  has_many :team_user_ships
  mount_uploader :avatar, AvatarUploader
  accepts_nested_attributes_for :user_profile, allow_destroy: true
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :timeoutable, :omniauthable, :omniauth_providers => [:cas]

  validates :nickname, presence: true, uniqueness: true, length: {in: 2..10}, format: {with: /\A[\u4e00-\u9fa5_a-zA-Z0-9]+\Z/i, message: '昵称只能包含中文、数字、字母、下划线'}
  validates :email, uniqueness: true, allow_blank: true, format: {with: /\A[^@\s]+@[^@\s]+\z/, message: '格式不正确'}


  def email_changed?
    false
  end

  def email_required?
    false
  end

  def send_devise_notification(notification, *args)
    devise_mailer.send(notification, self, *args).deliver_later
  end

  attr_accessor :email_info
  attr_accessor :email_code
  attr_accessor :mobile_info
  attr_accessor :return_url

  def self.find_for_database_authentication(warden_conditions)
    conditions = warden_conditions.dup
    if login = conditions.delete(:login)
      where(conditions).where(['nickname = :value OR email = :value OR mobile = :value', {:value => login}]).first
    else
      where(conditions).first
    end
  end

  def self.from_sso(auth)
    id = auth.extra.id
    user = find_by(id: id)
    mobile = auth.extra.try(:mobile)
    email = auth.info.try(:email)
    email = email.present? ? email.strip : ''
    mobile = mobile.present? ? mobile.strip : ''
    if user.nil?
      user = create(id: auth.extra.id, nickname: auth.info.nickname, mobile: mobile, email: email)
    else
      user.update_attributes(email: email, mobile: mobile)
    end
    user
  end

  private

end<commit_msg>fix login<commit_after>class User < ApplicationRecord
  has_one :user_profile, :dependent => :destroy
  has_many :user_roles
  has_many :roles, through: :user_roles
  has_many :notifications
  has_many :course_user_ships
  has_many :courses, through: :course_user_ships
  has_many :consults
  has_many :course_user_scores
  has_many :team_user_ships
  mount_uploader :avatar, AvatarUploader
  accepts_nested_attributes_for :user_profile, allow_destroy: true
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :timeoutable, :omniauthable, :omniauth_providers => [:cas]

  validates :nickname, presence: true, uniqueness: true, length: {in: 2..10}, format: {with: /\A[\u4e00-\u9fa5_a-zA-Z0-9]+\Z/i, message: '昵称只能包含中文、数字、字母、下划线'}
  validates :email, uniqueness: true, allow_blank: true, format: {with: /\A[^@\s]+@[^@\s]+\z/, message: '格式不正确'}


  def email_changed?
    false
  end

  def email_required?
    false
  end

  def send_devise_notification(notification, *args)
    devise_mailer.send(notification, self, *args).deliver_later
  end

  attr_accessor :email_info
  attr_accessor :email_code
  attr_accessor :mobile_info
  attr_accessor :return_url

  def self.find_for_database_authentication(warden_conditions)
    conditions = warden_conditions.dup
    if login = conditions.delete(:login)
      where(conditions).where(['nickname = :value OR email = :value OR mobile = :value', {:value => login}]).first
    else
      where(conditions).first
    end
  end

  def self.from_sso(auth)
    id = auth.extra.id
    user = find_by(id: id)
    mobile = auth.extra.try(:mobile)
    email = auth.info.try(:email)
    email = email.present? ? email.strip : ''
    mobile = mobile.present? ? mobile.strip : ''
    mobile = '' if mobile == "--- \n..."
    email = '' if email == "--- \n..."
    if user.nil?
      user = create(id: auth.extra.id, nickname: auth.info.nickname, mobile: mobile, email: email)
    else
      user.update_attributes(email: email, mobile: mobile)
    end
    user
  end

  private

end
{'fraction_non_alphanumeric': 0.11847879083373963, 'fraction_numerical': 0.0048756704046806435, 'mean_word_length': 4.015892420537897, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3663993', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1411, 'n_words': 324}