<commit_before>require 'soap/wsdlDriver'
require 'soap/mapping'
require 'defaultDriver'

class SecurityController < ApplicationController
  require 'digest/md5'
  filter_parameter_logging :password
  
  skip_before_filter :restrict_students
  skip_before_filter :set_user
  skip_before_filter :get_appln
  skip_before_filter :ensure_projects_app_created
  skip_before_filter :verify_event_group_chosen
  skip_before_filter :set_event_group

  before_filter :ensure_gcx_in_session, :only => [ :link_gcx, :do_link_gcx, :link_gcx_new, :do_link_gcx_new ]

  # makes a new viewer and person and links them to the gcx logged in
  def do_link_gcx
    result = login_by_cim
    if result[:keep_trying]
      result[:error] = "Sorry, couldn't find an intranet user '#{params[:username]}'.  Please try again."
    end

    if result[:error]
      flash[:notice] = result[:error]
      redirect_to :action => 'link_gcx'
      return
    end

    v = Viewer.find result[:viewer_id]
    if v.guid && !v.guid.empty? && v.guid != session[:gcx][:guid]
      flash[:notice] = "Error: Account '#{params[:username]}' already linked with a different gcx account."
      redirect_to :action => 'link_gcx'
      return
    end

    v.guid = session[:gcx][:guid]
    v.save!

    flash[:notice] = "Connected intranet user '#{params[:username]}' with gcx user '#{session[:gcx][:email]}'.  Now you can log in with your gcx user."
    flash.keep

    setup_given_viewer_id v.id
  end

  def do_link_gcx_new
    v = Viewer.create :guid => session[:gcx][:guid], :viewer_lastLogin => 0, :accountgroup_id => 15, :viewer_userID => params[:email]
    p = Person.create :person_fname => params[:first_name], :person_lname => params[:last_name]
    Access.create :viewer_id => v.id, :person_id => p.id

    flash[:notice] = "Account created."
    flash.keep
    setup_given_viewer_id v.id
  end

  def link_gcx
    redirect_to(:action => 'login') if session[:gcx].nil?

    flash.delete :gcx
    flash[:link] = "Congratulations, your GCX login worked!  There's just one more step.  We need to link GCX logins to the old intranet/project tool logins.  You only need to do this once.  If you don't have an intranet login, <A HREF='/security/link_gcx_new'>click here</A>.<BR /><BR />Please log in now the old way."
    @show_contact_emails_override = true
  end

  def link_gcx_new
    flash[:gcx] = "That's ok -- we just need the following information."
    @show_contact_emails_override = true
  end

  def index
    login
  end
  
  def read_login_message_confirm
    #if ['1', 1, 'true', true].include? params[:read_motd]
    #  session[:needs_read_login_message_confirm] = false
      redirect_to :controller => :main, :action => 'index'
    #else
    #  flash[:notice] = "For legal reasons, we need you to indicate that you've actually read this login message."
    #  render :action => 'motd'
    #end
  end
  
  def signup
  end

  def login
    if is_demo_host<commit_msg>improved notification message when linking logins; also added new intranet logins to be in the student accessgroup<commit_after>require 'soap/wsdlDriver'
require 'soap/mapping'
require 'defaultDriver'

class SecurityController < ApplicationController
  require 'digest/md5'
  filter_parameter_logging :password
  
  skip_before_filter :restrict_students
  skip_before_filter :set_user
  skip_before_filter :get_appln
  skip_before_filter :ensure_projects_app_created
  skip_before_filter :verify_event_group_chosen
  skip_before_filter :set_event_group

  before_filter :ensure_gcx_in_session, :only => [ :link_gcx, :do_link_gcx, :link_gcx_new, :do_link_gcx_new ]

  # makes a new viewer and person and links them to the gcx logged in
  def do_link_gcx
    result = login_by_cim
    if result[:keep_trying]
      result[:error] = "Sorry, couldn't find an intranet user '#{params[:username]}'.  Please try again."
    end

    if result[:error]
      flash[:notice] = result[:error]
      redirect_to :action => 'link_gcx'
      return
    end

    v = Viewer.find result[:viewer_id]
    if v.guid && !v.guid.empty? && v.guid != session[:gcx][:guid]
      flash[:notice] = "Error: Account '#{params[:username]}' already linked with a different gcx account."
      redirect_to :action => 'link_gcx'
      return
    end

    v.guid = session[:gcx][:guid]
    v.save!

    flash[:notice] = "Connected intranet user '#{params[:username]}' with gcx user '#{session[:gcx][:email]}'.  Now you can log in with your gcx user."
    flash.keep

    setup_given_viewer_id v.id
  end

  def do_link_gcx_new
    v = Viewer.create :guid => session[:gcx][:guid], :viewer_lastLogin => 0, :accountgroup_id => 15, :viewer_userID => params[:email]
    p = Person.create :person_fname => params[:first_name], :person_lname => params[:last_name]
    ag_st = Accessgroup.find_by_accessgroup_key '[accessgroup_student]'
    Vieweraccessgroup.create :viewer_id => v.id, :accessgroup_id => ag_st.id
    Access.create :viewer_id => v.id, :person_id => p.id

    flash[:notice] = "Account created."
    flash.keep
    setup_given_viewer_id v.id
  end

  def link_gcx
    redirect_to(:action => 'login') if session[:gcx].nil?

    flash.delete :gcx
    flash[:link] = "Congratulations, your GCX login worked!  There's just one more step.  We need to link GCX logins to the old intranet/project tool logins.  You only need to do this once.  If you don't have an intranet login, click the link below. Otherwise please log in now the old way."
    @show_contact_emails_override = true
  end

  def link_gcx_new
    flash[:gcx] = "That's ok -- we just need the following information."
    @show_contact_emails_override = true
  end

  def index
    login
  end
  
  def read_login_message_confirm
    #if ['1', 1, 'true', true].include? params[:read_motd]
    #  session[:needs_read_login_message_confirm] = false
      redirect_to :controller => :main, :action => 'index'
    #else
    #  flash[:notice] = "For legal reasons, we need you to indicate that you've actually read this login message."
    #  render :action => 'motd'
    #end
  end
  
  def signup
  end

  def login
    if is_demo_host
{'fraction_non_alphanumeric': 0.10687397708674304, 'fraction_numerical': 0.0019639934533551553, 'mean_word_length': 3.7891849529780566, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 39, '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': '6944839', 'n_tokens_mistral': 2077, 'n_tokens_neox': 2007, 'n_words': 570}