<commit_before>class LoginsController < ApplicationController
  before_action :authenticate_login!
  before_action :set_person, except: :index
  after_action :verify_authorized

  def new
    @login = @person.build_login email: @person.contact.email
    authorize @login
  end

  def create
    authorize Login
    @login = LoginGenerator.new(@person).call

    if @login.valid?
      redirect_to @role, notice: t('.success')
    else
      render 'new'
    end
  end

  def edit
    @login = @person.login
  end

  def update
    @login = Login.find(params[:id])
    authorize @login
    if @login.update_attributes(login_params)
      redirect_to @role, notice: t('.success')
    else
      render :edit
      # redirect_to logins_path, :alert => "Unable to update login."
    end
  end

  def destroy
    login = @person.login
    authorize login
    login.destroy
    redirect_to @role, notice: t('.success')
  end

  def toggle
    login = @person.login
    authorize login
    login.toggle!
    redirect_to @role, notice: ( login.account_active? ? t('.activated') : t('.deactivated') )
  end

  private

  def set_person
    @role = role
    @person = @role.person
  end

  def role
    if params[:teacher_id].present?
      Teacher.find params[:teacher_id]
    elsif params[:student_id].present?
      Student.find params[:student_id]
    end
  end

  def login_params
    params.require(:login).permit(:email, :password, :password_confirmation)
  end

end
<commit_msg>fix overriding email in manual login creation<commit_after>class LoginsController < ApplicationController
  before_action :authenticate_login!
  before_action :set_person, except: :index
  after_action :verify_authorized

  def new
    @login = @person.build_login email: @person.contact.email
    authorize @login
  end

  def create
    authorize Login
    @login = LoginGenerator.new(@person, email: login_params[:email]).call

    if @login.valid?
      redirect_to @role, notice: t('.success')
    else
      render 'new'
    end
  end

  def edit
    @login = @person.login
  end

  def update
    @login = Login.find(params[:id])
    authorize @login
    if @login.update_attributes(login_params)
      redirect_to @role, notice: t('.success')
    else
      render :edit
      # redirect_to logins_path, :alert => "Unable to update login."
    end
  end

  def destroy
    login = @person.login
    authorize login
    login.destroy
    redirect_to @role, notice: t('.success')
  end

  def toggle
    login = @person.login
    authorize login
    login.toggle!
    redirect_to @role, notice: ( login.account_active? ? t('.activated') : t('.deactivated') )
  end

  private

  def set_person
    @role = role
    @person = @role.person
  end

  def role
    if params[:teacher_id].present?
      Teacher.find params[:teacher_id]
    elsif params[:student_id].present?
      Student.find params[:student_id]
    end
  end

  def login_params
    params.require(:login).permit(:email, :password, :password_confirmation)
  end

end

{'fraction_non_alphanumeric': 0.0985728509790906, 'fraction_numerical': 0.0, 'mean_word_length': 3.0565275908479137, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2347273', 'n_tokens_mistral': 955, 'n_tokens_neox': 924, 'n_words': 246}