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 = 'create account'
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] = I18n.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 = 'edit account'
40 if params[:user] and params[:user][:display_name] and params[:user][:description]
41 if params[:user][:email] != @user.email
42 @user.new_email = params[:user][:email]
45 @user.display_name = params[:user][:display_name]
47 if params[:user][:pass_crypt].length > 0 or params[:user][:pass_crypt_confirmation].length > 0
48 @user.pass_crypt = params[:user][:pass_crypt]
49 @user.pass_crypt_confirmation = params[:user][:pass_crypt_confirmation]
52 @user.description = params[:user][:description]
53 @user.languages = params[:user][:languages].split(",")
54 @user.home_lat = params[:user][:home_lat]
55 @user.home_lon = params[:user][:home_lon]
60 if params[:user][:email] == @user.new_email
61 flash[:notice] = I18n.t('user.account.flash update success confirm needed')
62 Notifier.deliver_email_confirm(@user, @user.tokens.create)
64 flash[:notice] = I18n.t('user.account.flash update success')
71 if params[:user][:home_lat] and params[:user][:home_lon]
72 @user.home_lat = params[:user][:home_lat].to_f
73 @user.home_lon = params[:user][:home_lon].to_f
75 flash[:notice] = I18n.t('user.set_home.flash success')
76 redirect_to :controller => 'user', :action => 'account'
82 @user.data_public = true
84 flash[:notice] = I18n.t('user.go_public.flash success')
85 redirect_to :controller => 'user', :action => 'account', :display_name => @user.display_name
89 @title = I18n.t('user.lost_password.title')
90 if params[:user] and params[:user][:email]
91 user = User.find_by_email(params[:user][:email], :conditions => {:visible => true})
94 token = user.tokens.create
95 Notifier.deliver_lost_password(user, token)
96 flash[:notice] = I18n.t('user.lost_password.notice.email on way')
98 flash[:notice] = I18n.t('user.lost_password.notice email cannot find')
104 @title = I18n.t('user.reset_password.title')
106 token = UserToken.find_by_token(params[:token])
108 pass = OSM::make_token(8)
110 user.pass_crypt = pass
111 user.pass_crypt_confirmation = pass
113 user.email_valid = true
116 Notifier.deliver_reset_password(user, pass)
117 flash[:notice] = I18n.t('user.reset_password.flash changed check mail')
119 flash[:notice] = I18n.t('user.reset_password.flash token bad')
123 redirect_to :action => 'login'
127 @title = 'create account'
128 # The user is logged in already, so don't show them the signup page, instead
129 # send them to the home page
130 redirect_to :controller => 'site', :action => 'index' if session[:user]
135 # The user is logged in already, if the referer param exists, redirect them to that
137 redirect_to params[:referer]
139 redirect_to :controller => 'site', :action => 'index'
145 email_or_display_name = params[:user][:email]
146 pass = params[:user][:password]
147 user = User.authenticate(:username => email_or_display_name, :password => pass)
149 session[:user] = user.id
151 redirect_to params[:referer]
153 redirect_to :controller => 'site', :action => 'index'
156 elsif User.authenticate(:username => email_or_display_name, :password => pass, :inactive => true)
157 @notice = "Sorry, your account is not active yet.<br>Please click on the link in the account confirmation email to activate your account."
159 @notice = "Sorry, couldn't log in with those details."
166 token = UserToken.find_by_token(session[:token])
170 session[:token] = nil
174 redirect_to params[:referer]
176 redirect_to :controller => 'site', :action => 'index'
181 if params[:confirm_action]
182 token = UserToken.find_by_token(params[:confirm_string])
183 if token and !token.user.active?
186 @user.email_valid = true
189 flash[:notice] = 'Confirmed your account, thanks for signing up!'
190 session[:user] = @user.id
191 redirect_to :action => 'account', :display_name => @user.display_name
193 @notice = 'Something went wrong confirming that user.'
199 if params[:confirm_action]
200 token = UserToken.find_by_token(params[:confirm_string])
201 if token and token.user.new_email?
203 @user.email = @user.new_email
204 @user.new_email = nil
206 @user.email_valid = true
209 flash[:notice] = 'Confirmed your email address, thanks for signing up!'
210 session[:user] = @user.id
211 redirect_to :action => 'account', :display_name => @user.display_name
213 @notice = 'Something went wrong confirming that email address.'
219 @user.image = params[:user][:image]
221 redirect_to :controller => 'user', :action => 'view', :display_name => @user.display_name
227 redirect_to :controller => 'user', :action => 'view', :display_name => @user.display_name
231 render :text => @user.to_xml.to_s, :content_type => "text/xml"
235 doc = OSM::API.new.get_xml_doc
236 @user.traces.each do |trace|
237 doc.root << trace.to_xml_node() if trace.public? or trace.user == @user
239 render :text => doc.to_s, :content_type => "text/xml"
243 @this_user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
246 @title = @this_user.display_name
248 @not_found_user = params[:display_name]
249 render :action => 'no_such_user', :status => :not_found
254 if params[:display_name]
255 name = params[:display_name]
256 new_friend = User.find_by_display_name(name, :conditions => {:visible => true})
258 friend.user_id = @user.id
259 friend.friend_user_id = new_friend.id
260 unless @user.is_friends_with?(new_friend)
262 flash[:notice] = "#{name} is now your friend."
263 Notifier.deliver_friend_notification(friend)
265 friend.add_error("Sorry, failed to add #{name} as a friend.")
268 flash[:notice] = "You are already friends with #{name}."
271 redirect_to :controller => 'user', :action => 'view'
276 if params[:display_name]
277 name = params[:display_name]
278 friend = User.find_by_display_name(name, :conditions => {:visible => true})
279 if @user.is_friends_with?(friend)
280 Friend.delete_all "user_id = #{@user.id} AND friend_user_id = #{friend.id}"
281 flash[:notice] = "#{friend.display_name} was removed from your friends."
283 flash[:notice] = "#{friend.display_name} is not one of your friends."
286 redirect_to :controller => 'user', :action => 'view'