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

#auth_tokenObject


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

def auth_token
  current_user.ensure_authentication_token!
  render status: 200, json: {token: current_user.authentication_token}
end

#confirm_emailObject


124
125
126
127
128
129
130
131
# File 'app/controllers/users_controller.rb', line 124

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


54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/users_controller.rb', line 54

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(new_user_session_path(format: request[:format]), 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_back fallback_location: edit_user_path
  end
end

#download_photosObject


120
121
122
# File 'app/controllers/users_controller.rb', line 120

def download_photos
  redirect_to current_user.exported_photos_file.url
end

#download_profileObject


110
111
112
# File 'app/controllers/users_controller.rb', line 110

def download_profile
  redirect_to current_user.export.url
end

#editObject


11
12
13
14
# File 'app/controllers/users_controller.rb', line 11

def edit
  @user = current_user
  set_email_preferences
end

#export_photosObject


114
115
116
117
118
# File 'app/controllers/users_controller.rb', line 114

def export_photos
  current_user.queue_export_photos
  flash[:notice] = I18n.t("users.edit.export_photos_in_progress")
  redirect_to edit_user_path
end

#export_profileObject


104
105
106
107
108
# File 'app/controllers/users_controller.rb', line 104

def export_profile
  current_user.queue_export
  flash[:notice] = I18n.t("users.edit.export_in_progress")
  redirect_to edit_user_path
end

#getting_startedObject


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

def getting_started
  @user     = current_user
  @person   = @user.person
  @profile  = @user.profile
  gon.preloads[:inviter] = PersonPresenter.new(current_user.invited_by.try(:person), current_user).as_json
  gon.preloads[:tagsArray] = current_user.followed_tags.map {|tag| {name: "##{tag.name}", value: "##{tag.name}"} }

  render "users/getting_started"
end

#getting_started_completedObject


97
98
99
100
101
102
# File 'app/controllers/users_controller.rb', line 97

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

#privacy_settingsObject


16
17
18
# File 'app/controllers/users_controller.rb', line 16

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

#publicObject


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/users_controller.rb', line 69

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


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/users_controller.rb', line 20

def update
  password_changed = false
  user_data = user_params
  @user = current_user

  if user_data
    # change password
    if params[:change_password]
      password_changed = change_password(user_data)
    else
      update_user(user_data)
    end
  end

  if password_changed
    redirect_to new_user_session_path
  else
    set_email_preferences
    render :edit
  end
end

#update_privacy_settingsObject


42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/users_controller.rb', line 42

def update_privacy_settings
  privacy_params = params.fetch(:user).permit(:strip_exif)

  if current_user.update_attributes(strip_exif: privacy_params[:strip_exif])
    flash[:notice] = t("users.update.settings_updated")
  else
    flash[:error] = t("users.update.settings_not_updated")
  end

  redirect_back fallback_location: privacy_settings_path
end