Newer
Older
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
Arzumy MD
a validé
class UsersController < ApplicationController
before_filter :authenticate_user!, :except => [:new, :create, :public, :user_photo]
respond_to :html
danielvincent
a validé
@aspect = :user_edit
@user = current_user
Raphael Sofaer
a validé
@email_prefs = Hash.new(true)
@user.user_preferences.each do |pref|
@email_prefs[pref.email_type] = false
end
def privacy_settings
@blocks = current_user.blocks.includes(:person)
end
password_changed = false
danielvincent
a validé
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
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
danielvincent
a validé
end
respond_to do |format|
Arzumy MD
a validé
format.js { render :nothing => true, :status => 204 }
format.all { redirect_to password_changed ? new_user_session_path : edit_user_path }
if params[:user] && params[:user][:current_password] && current_user.valid_password?(params[:user][:current_password])
Ilya Zhitomirskiy
a validé
current_user.close_account!
redirect_to(stream_path, :notice => I18n.t('users.destroy.success'))
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
danielvincent
a validé
def public
if @user = User.find_by_username(params[:username])
respond_to do |format|
Arzumy MD
a validé
format.atom do
@posts = Post.where(:author_id => @user.person_id, :public => true).order('created_at DESC').limit(25)
Arzumy MD
a validé
end
format.any { redirect_to person_path(@user.person) }
Arzumy MD
a validé
end
redirect_to stream_path, :error => I18n.t('users.public.does_not_exist', :username => params[:username])
danielvincent
a validé
end
@user = current_user
@person = @user.person
@profile = @user.profile
@css_framework = :bootstrap
@include_application_css = true #Hack for multiple CSS frameworks and having two main styles
movilla
a validé
respond_to do |format|
format.mobile { render "users/getting_started" }
format.all { render "users/getting_started", layout: "with_header_with_footer" }
end
def getting_started_completed
user = current_user
redirect_to stream_path
def export
exporter = Diaspora::Exporter.new(Diaspora::Exporters::XML)
send_data exporter.execute(current_user), :filename => "#{current_user.username}_diaspora_data.xml", :type => :xml
def export_photos
tar_path = PhotoMover::move_photos(current_user)
send_data( File.open(tar_path).read, :filename => "#{current_user.id}.tar" )
end
def user_photo
username = params[:username].split('@')[0]
user = User.find_by_username(username)
else
render :nothing => true, :status => 404
end
end
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
params.fetch(:user).permit(
:email,
:current_password,
:password,
:password_confirmation,
:language,
:disable_mail,
:invitation_service,
:invitation_identifier,
:show_community_spotlight_in_stream,
:auto_follow_back,
:auto_follow_back_aspect_id,
:remember_me,
:getting_started,
email_preferences: [
:also_commented,
:mentioned,
:comment_on_post,
:private_message,
:started_sharing,
:liked,
:reshared
]
)