1 class UserController < ApplicationController
4 before_filter :authorize, :only => [:api_details, :api_gpx_files]
5 before_filter :authorize_web, :except => [:api_details, :api_gpx_files]
6 before_filter :set_locale, :except => [:api_details, :api_gpx_files]
7 before_filter :require_user, :only => [:set_home, :account, :go_public, :make_friend, :remove_friend, :upload_image, :delete_image]
8 before_filter :check_database_readable, :except => [:api_details, :api_gpx_files]
9 before_filter :check_database_writable, :only => [:login, :new, :set_home, :account, :go_public, :make_friend, :remove_friend, :upload_image, :delete_image]
10 before_filter :check_api_readable, :only => [:api_details, :api_gpx_files]
12 filter_parameter_logging :password, :pass_crypt, :pass_crypt_confirmation
15 @title = t 'user.new.title'
17 if Acl.find_by_address(request.remote_ip, :conditions => {:k => "no_account_creation"})
18 render :action => 'new'
20 @user = User.new(params[:user])
23 @user.data_public = true
24 @user.description = "" if @user.description.nil?
25 @user.creation_ip = request.remote_ip
26 @user.languages = request.user_preferred_languages
29 flash[:notice] = t 'user.new.flash create success message'
30 Notifier.deliver_signup_confirm(@user, @user.tokens.create)
31 redirect_to :action => 'login'
33 render :action => 'new'
39 @title = t 'user.account.title'
41 if params[:user] and params[:user][:display_name] and params[:user][:description]
42 if params[:user][:email] != @user.email
43 @user.new_email = params[:user][:email]
46 @user.display_name = params[:user][:display_name]
48 if params[:user][:pass_crypt].length > 0 or params[:user][:pass_crypt_confirmation].length > 0
49 @user.pass_crypt = params[:user][:pass_crypt]
50 @user.pass_crypt_confirmation = params[:user][:pass_crypt_confirmation]
53 @user.description = params[:user][:description]
54 @user.languages = params[:user][:languages].split(",")
55 @user.home_lat = params[:user][:home_lat]
56 @user.home_lon = params[:user][:home_lon]
61 if params[:user][:email] == @user.new_email
62 flash[:notice] = t 'user.account.flash update success confirm needed'
63 Notifier.deliver_email_confirm(@user, @user.tokens.create)
65 flash[:notice] = t 'user.account.flash update success'
72 if params[:user][:home_lat] and params[:user][:home_lon]
73 @user.home_lat = params[:user][:home_lat].to_f
74 @user.home_lon = params[:user][:home_lon].to_f
76 flash[:notice] = t 'user.set_home.flash success'
77 redirect_to :controller => 'user', :action => 'account'
83 @user.data_public = true
85 flash[:notice] = t 'user.go_public.flash success'
86 redirect_to :controller => 'user', :action => 'account', :display_name => @user.display_name
90 @title = t 'user.lost_password.title'
92 if params[:user] and params[:user][:email]
93 user = User.find_by_email(params[:user][:email], :conditions => {:visible => true})
96 token = user.tokens.create
97 Notifier.deliver_lost_password(user, token)
98 flash[:notice] = t 'user.lost_password.notice email on way'
100 flash[:notice] = t 'user.lost_password.notice email cannot find'
106 @title = t 'user.reset_password.title'
109 token = UserToken.find_by_token(params[:token])
111 pass = OSM::make_token(8)
113 user.pass_crypt = pass
114 user.pass_crypt_confirmation = pass
116 user.email_valid = true
119 Notifier.deliver_reset_password(user, pass)
120 flash[:notice] = t 'user.reset_password.flash changed check mail'
122 flash[:notice] = t 'user.reset_password.flash token bad'
126 redirect_to :action => 'login'
130 @title = t 'user.new.title'
132 # The user is logged in already, so don't show them the signup page, instead
133 # send them to the home page
134 redirect_to :controller => 'site', :action => 'index' if session[:user]
139 # The user is logged in already, if the referer param exists, redirect them to that
141 redirect_to params[:referer]
143 redirect_to :controller => 'site', :action => 'index'
148 @title = t 'user.login.title'
151 email_or_display_name = params[:user][:email]
152 pass = params[:user][:password]
153 user = User.authenticate(:username => email_or_display_name, :password => pass)
155 session[:user] = user.id
157 redirect_to params[:referer]
159 redirect_to :controller => 'site', :action => 'index'
162 elsif User.authenticate(:username => email_or_display_name, :password => pass, :inactive => true)
163 @notice = t 'user.login.account not active'
165 @notice = t 'user.login.auth failure'
172 token = UserToken.find_by_token(session[:token])
176 session[:token] = nil
180 redirect_to params[:referer]
182 redirect_to :controller => 'site', :action => 'index'
187 if params[:confirm_action]
188 token = UserToken.find_by_token(params[:confirm_string])
189 if token and !token.user.active?
192 @user.email_valid = true
195 flash[:notice] = t 'user.confirm.success'
196 session[:user] = @user.id
197 redirect_to :action => 'account', :display_name => @user.display_name
199 @notice = t 'user.confirm.failure'
205 if params[:confirm_action]
206 token = UserToken.find_by_token(params[:confirm_string])
207 if token and token.user.new_email?
209 @user.email = @user.new_email
210 @user.new_email = nil
212 @user.email_valid = true
215 flash[:notice] = t 'user.confirm_email.success'
216 session[:user] = @user.id
217 redirect_to :action => 'account', :display_name => @user.display_name
219 @notice = t 'user.confirm_email.failure'
225 @user.image = params[:user][:image]
227 redirect_to :controller => 'user', :action => 'view', :display_name => @user.display_name
233 redirect_to :controller => 'user', :action => 'view', :display_name => @user.display_name
237 render :text => @user.to_xml.to_s, :content_type => "text/xml"
241 doc = OSM::API.new.get_xml_doc
242 @user.traces.each do |trace|
243 doc.root << trace.to_xml_node() if trace.public? or trace.user == @user
245 render :text => doc.to_s, :content_type => "text/xml"
249 @this_user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
252 @title = @this_user.display_name
254 @title = t 'user.no_such_user.title'
255 @not_found_user = params[:display_name]
256 render :action => 'no_such_user', :status => :not_found
261 if params[:display_name]
262 name = params[:display_name]
263 new_friend = User.find_by_display_name(name, :conditions => {:visible => true})
265 friend.user_id = @user.id
266 friend.friend_user_id = new_friend.id
267 unless @user.is_friends_with?(new_friend)
269 flash[:notice] = t 'user.make_friend.success', :name => name
270 Notifier.deliver_friend_notification(friend)
272 friend.add_error(t('user.make_friend.failed', :name => name))
275 flash[:notice] = t 'user.make_friend.already_a_friend', :name => name
278 redirect_to :controller => 'user', :action => 'view'
283 if params[:display_name]
284 name = params[:display_name]
285 friend = User.find_by_display_name(name, :conditions => {:visible => true})
286 if @user.is_friends_with?(friend)
287 Friend.delete_all "user_id = #{@user.id} AND friend_user_id = #{friend.id}"
288 flash[:notice] = t 'user.remove_friend.success', :name => friend.display_name
290 flash[:notice] = t 'user.remove_friend.not_a_friend', :name => friend.display_name
293 redirect_to :controller => 'user', :action => 'view'