Class: UsersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/users_controller.rb

Overview

Copyright © 2010-2011, Diaspora Inc. This file is

licensed under the Affero General Public License version 3 or later.  See
the COPYRIGHT file.

Instance Method Summary collapse

Instance Method Details

#confirm_emailObject



158
159
160
161
162
163
164
165
# File 'app/controllers/users_controller.rb', line 158

def confirm_email
  if current_user.confirm_email(params[:token])
    flash[:notice] = I18n.t('users.confirm_email.email_confirmed', :email => current_user.email)
  elsif current_user.unconfirmed_email.present?
    flash[:error] = I18n.t('users.confirm_email.email_not_confirmed')
  end
  redirect_to edit_user_path
end

#destroyObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/controllers/users_controller.rb', line 87

def destroy
  if params[:user] && params[:user][:current_password] && current_user.valid_password?(params[:user][:current_password])
    current_user.close_account!
    sign_out current_user
    redirect_to(stream_path, :notice => I18n.t('users.destroy.success'))
  else
    if params[:user].present? && params[:user][:current_password].present?
      flash[:error] = t 'users.destroy.wrong_password'
    else
      flash[:error] = t 'users.destroy.no_password'
    end
    redirect_to :back
  end
end

#editObject



15
16
17
18
19
20
21
22
# File 'app/controllers/users_controller.rb', line 15

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

#exportObject



138
139
140
141
# File 'app/controllers/users_controller.rb', line 138

def export
  exporter = Diaspora::Exporter.new(Diaspora::Exporters::XML)
  send_data exporter.execute(current_user), :filename => "#{current_user.username}_diaspora_data.xml", :type => :xml
end

#export_photosObject



143
144
145
146
# File 'app/controllers/users_controller.rb', line 143

def export_photos
  tar_path = PhotoMover::move_photos(current_user)
  send_data( File.open(tar_path).read, :filename => "#{current_user.id}.tar" )
end

#getting_startedObject



120
121
122
123
124
125
126
127
128
129
# File 'app/controllers/users_controller.rb', line 120

def getting_started
  @user     = current_user
  @person   = @user.person
  @profile  = @user.profile

  respond_to do |format|
  format.mobile { render "users/getting_started" }
  format.all { render "users/getting_started", layout: "with_header_with_footer" }
  end
end

#getting_started_completedObject



131
132
133
134
135
136
# File 'app/controllers/users_controller.rb', line 131

def getting_started_completed
  user = current_user
  user.getting_started = false
  user.save
  redirect_to stream_path
end

#privacy_settingsObject



24
25
26
# File 'app/controllers/users_controller.rb', line 24

def privacy_settings
  @blocks = current_user.blocks.includes(:person)
end

#publicObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/controllers/users_controller.rb', line 102

def public
  if @user = User.find_by_username(params[:username])
    respond_to do |format|
      format.atom do
        @posts = Post.where(author_id: @user.person_id, public: true)
                  .order('created_at DESC')
                  .limit(25)
                  .map {|post| post.is_a?(Reshare) ? post.absolute_root : post }
                  .compact
      end

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

#updateObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/users_controller.rb', line 28

def update
  password_changed = false
  @user = current_user

  if u = user_params
    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[:show_community_spotlight_in_stream] || u[:getting_started]
      if @user.update_attributes(u)
        flash[:notice] = I18n.t 'users.update.settings_updated'
      else
        flash[:notice] = I18n.t 'users.update.settings_not_updated'
      end
    elsif u[:language]
      if @user.update_attributes(u)
        I18n.locale = @user.language
        flash[:notice] = I18n.t 'users.update.language_changed'
      else
        flash[:error] = I18n.t 'users.update.language_not_changed'
      end
    elsif u[:email]
      @user.unconfirmed_email = u[:email]
      if @user.save
        @user.mail_confirm_email == @user.email
        if @user.unconfirmed_email
          flash[:notice] = I18n.t 'users.update.unconfirmed_email_changed'
        end
      else
        flash[:error] = I18n.t 'users.update.unconfirmed_email_not_changed'
      end
    elsif u[:auto_follow_back]
      if  @user.update_attributes(u)
        flash[:notice] = I18n.t 'users.update.follow_settings_changed'
      else
        flash[:error] = I18n.t 'users.update.follow_settings_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

#user_photoObject



148
149
150
151
152
153
154
155
156
# File 'app/controllers/users_controller.rb', line 148

def user_photo
  username = params[:username].split('@')[0]
  user = User.find_by_username(username)
  if user.present?
    redirect_to user.image_url
  else
    render :nothing => true, :status => 404
  end
end