<commit_before>#   Copyright (c) 2010, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

class UsersController < ApplicationController
  require File.join(Rails.root, 'lib/diaspora/ostatus_builder')
  require File.join(Rails.root, 'lib/diaspora/exporter')
  require File.join(Rails.root, 'lib/collect_user_photos')

  before_filter :authenticate_user!, :except => [:new, :create, :public]

  respond_to :html

  def edit
    @aspect = :user_edit
    @user   = current_user
    @email_prefs = Hash.new(true)
    @user.user_preferences.each do |pref|
      @email_prefs[pref.email_type] = false
    end
  end

  def update
    password_changed = false
    if u = params[:user]
      @user = current_user

      u.delete(:password) if u[:password].blank?
      u.delete(:password_confirmation) if u[:password].blank? and u[:password_confirmation].blank?
      u.delete(:language) if u[:language].blank?

      # change email notifications
      if u[:email_preferences]
        @user.update_user_preferences(u[:email_preferences])
        flash[:notice] = I18n.t 'users.update.email_notifications_changed'
      # change password
      elsif u[:current_password] && u[:password] && u[:password_confirmation]
        if @user.update_with_password(u)
          password_changed = true
          flash[:notice] = I18n.t 'users.update.password_changed'
        else
          flash[:error] = I18n.t 'users.update.password_not_changed'
        end
      elsif u[:language]
        if @user.update_attributes(:language => u[:language])
          I18n.locale = @user.language
          flash[:notice] = I18n.t 'users.update.language_changed'
        else
          flash[:error] = I18n.t 'users.update.language_not_changed'
        end
      end
    end

    respond_to do |format|
      format.js   { render :nothing => true, :status => 204 }
      format.all  { redirect_to password_changed ? new_user_session_path : edit_user_path }
    end
  end

  def destroy
    Resque.enqueue(Job::DeleteAccount, current_user.id)
    current_user.lock_access!
    sign_out current_user
    flash[:notice] = I18n.t 'users.destroy'
    redirect_to root_path
  end

  def public
    if user = User.find_by_username(params[:username])
      respond_to do |format|
        format.atom do
          posts = StatusMessage.where(:author_id => user.person.id, :public => true).order('created_at DESC')
          director = Diaspora::Director.new
          ostatus_builder = Diaspora::OstatusBuilder.new(user, posts)
          render :xml => director.build(ostatus_builder), :content_type => 'application/atom+xml'
        end

        format.html { redirect_to person_path(user.person.id) }
      end
    else
      redirect_to root_url, :error => I18n.t('users.public.does_not_exist', :username => params[:username])
    end
  end

  def getting_started
    @aspect   = :getting_started
    @user     = current_user
    @person   = @user.person
    @profile  = @user.profile
    @services = @user.services
    service = current_user.services.where(:type => "Services::Facebook").first

    @step = ((params[:step].to_i>0)&&(params[:step].to_i<4)) ? params[:step].to_i : 1
    @step ||= 1

    if @step == 2 && SERVICES['facebook']['app_id'] == ""
      @step = 3
    end

    if @step == 3
      @friends = service ? service.finder(:local => true) : []<commit_msg>Limit posts in the RSS feed, wecan come back to this and not limit it, and instead cache the static feed, when we have a little more time.<commit_after>#   Copyright (c) 2010, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

class UsersController < ApplicationController
  require File.join(Rails.root, 'lib/diaspora/ostatus_builder')
  require File.join(Rails.root, 'lib/diaspora/exporter')
  require File.join(Rails.root, 'lib/collect_user_photos')

  before_filter :authenticate_user!, :except => [:new, :create, :public]

  respond_to :html

  def edit
    @aspect = :user_edit
    @user   = current_user
    @email_prefs = Hash.new(true)
    @user.user_preferences.each do |pref|
      @email_prefs[pref.email_type] = false
    end
  end

  def update
    password_changed = false
    if u = params[:user]
      @user = current_user

      u.delete(:password) if u[:password].blank?
      u.delete(:password_confirmation) if u[:password].blank? and u[:password_confirmation].blank?
      u.delete(:language) if u[:language].blank?

      # change email notifications
      if u[:email_preferences]
        @user.update_user_preferences(u[:email_preferences])
        flash[:notice] = I18n.t 'users.update.email_notifications_changed'
      # change password
      elsif u[:current_password] && u[:password] && u[:password_confirmation]
        if @user.update_with_password(u)
          password_changed = true
          flash[:notice] = I18n.t 'users.update.password_changed'
        else
          flash[:error] = I18n.t 'users.update.password_not_changed'
        end
      elsif u[:language]
        if @user.update_attributes(:language => u[:language])
          I18n.locale = @user.language
          flash[:notice] = I18n.t 'users.update.language_changed'
        else
          flash[:error] = I18n.t 'users.update.language_not_changed'
        end
      end
    end

    respond_to do |format|
      format.js   { render :nothing => true, :status => 204 }
      format.all  { redirect_to password_changed ? new_user_session_path : edit_user_path }
    end
  end

  def destroy
    Resque.enqueue(Job::DeleteAccount, current_user.id)
    current_user.lock_access!
    sign_out current_user
    flash[:notice] = I18n.t 'users.destroy'
    redirect_to root_path
  end

  def public
    if user = User.find_by_username(params[:username])
      respond_to do |format|
        format.atom do
          posts = StatusMessage.where(:author_id => user.person.id, :public => true).order('created_at DESC').limit(25)
          director = Diaspora::Director.new
          ostatus_builder = Diaspora::OstatusBuilder.new(user, posts)
          render :xml => director.build(ostatus_builder), :content_type => 'application/atom+xml'
        end

        format.html { redirect_to person_path(user.person.id) }
      end
    else
      redirect_to root_url, :error => I18n.t('users.public.does_not_exist', :username => params[:username])
    end
  end

  def getting_started
    @aspect   = :getting_started
    @user     = current_user
    @person   = @user.person
    @profile  = @user.profile
    @services = @user.services
    service = current_user.services.where(:type => "Services::Facebook").first

    @step = ((params[:step].to_i>0)&&(params[:step].to_i<4)) ? params[:step].to_i : 1
    @step ||= 1

    if @step == 2 && SERVICES['facebook']['app_id'] == ""
      @step = 3
    end

    if @step == 3
      @friends = service ? service.finder(:local => true) : []
{'fraction_non_alphanumeric': 0.11863434227513986, 'fraction_numerical': 0.009180892267967294, 'mean_word_length': 3.0440835266821344, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3204738', 'n_tokens_mistral': 2272, 'n_tokens_neox': 2165, 'n_words': 481}