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 :require_user, :only => [:set_home, :account, :go_public, :make_friend, :remove_friend, :upload_image, :delete_image]
7 before_filter :check_database_readable, :except => [:api_details, :api_gpx_files]
8 before_filter :check_database_writable, :only => [:login, :new, :set_home, :account, :go_public, :make_friend, :remove_friend, :upload_image, :delete_image]
9 before_filter :check_api_readable, :only => [:api_details, :api_gpx_files]
11 filter_parameter_logging :password, :pass_crypt, :pass_crypt_confirmation
14 @title = 'create account'
16 if Acl.find_by_address(request.remote_ip, :conditions => {:k => "no_account_creation"})
17 render :action => 'new'
19 @user = User.new(params[:user])
22 @user.data_public = true
23 @user.description = "" if @user.description.nil?
24 @user.creation_ip = request.remote_ip
27 flash[:notice] = "User was successfully created. Check your email for a confirmation note, and you\'ll be mapping in no time :-)<br /><br />Please note that you won't be able to login until you've received and confirmed your email address.<br /><br />If you use an antispam system which sends confirmation requests then please make sure you whitelist webmaster@openstreetmap.org as we are unable to reply to any confirmation requests."
28 Notifier.deliver_signup_confirm(@user, @user.tokens.create)
29 redirect_to :action => 'login'
31 render :action => 'new'
37 @title = 'edit account'
38 if params[:user] and params[:user][:display_name] and params[:user][:description]
39 if params[:user][:email] != @user.email
40 @user.new_email = params[:user][:email]
43 @user.display_name = params[:user][:display_name]
45 if params[:user][:pass_crypt].length > 0 or params[:user][:pass_crypt_confirmation].length > 0
46 @user.pass_crypt = params[:user][:pass_crypt]
47 @user.pass_crypt_confirmation = params[:user][:pass_crypt_confirmation]
50 @user.description = params[:user][:description]
51 @user.home_lat = params[:user][:home_lat]
52 @user.home_lon = params[:user][:home_lon]
55 if params[:user][:email] == @user.new_email
56 @notice = "User information updated successfully. Check your email for a note to confirm your new email address."
57 Notifier.deliver_email_confirm(@user, @user.tokens.create)
59 @notice = "User information updated successfully."
66 if params[:user][:home_lat] and params[:user][:home_lon]
67 @user.home_lat = params[:user][:home_lat].to_f
68 @user.home_lon = params[:user][:home_lon].to_f
70 flash[:notice] = "Home location saved successfully."
71 redirect_to :controller => 'user', :action => 'account'
77 @user.data_public = true
79 flash[:notice] = 'All your edits are now public.'
80 redirect_to :controller => 'user', :action => 'account', :display_name => @user.display_name
84 @title = 'lost password'
85 if params[:user] and params[:user][:email]
86 user = User.find_by_email(params[:user][:email], :conditions => {:visible => true})
89 token = user.tokens.create
90 Notifier.deliver_lost_password(user, token)
91 @notice = "Sorry you lost it :-( but an email is on its way so you can reset it soon."
93 @notice = "Couldn't find that email address, sorry."
99 @title = 'reset password'
101 token = UserToken.find_by_token(params[:token])
103 pass = OSM::make_token(8)
105 user.pass_crypt = pass
106 user.pass_crypt_confirmation = pass
108 user.email_valid = true
111 Notifier.deliver_reset_password(user, pass)
112 flash[:notice] = "Your password has been changed and is on its way to your mailbox :-)"
114 flash[:notice] = "Didn't find that token, check the URL maybe?"
118 redirect_to :action => 'login'
122 @title = 'create account'
123 # The user is logged in already, so don't show them the signup page, instead
124 # send them to the home page
125 redirect_to :controller => 'site', :action => 'index' if session[:user]
130 # The user is logged in already, if the referer param exists, redirect them to that
132 redirect_to params[:referer]
134 redirect_to :controller => 'site', :action => 'index'
140 email_or_display_name = params[:user][:email]
141 pass = params[:user][:password]
142 user = User.authenticate(:username => email_or_display_name, :password => pass)
144 session[:user] = user.id
146 redirect_to params[:referer]
148 redirect_to :controller => 'site', :action => 'index'
151 elsif User.authenticate(:username => email_or_display_name, :password => pass, :inactive => true)
152 @notice = "Sorry, your account is not active yet.<br>Please click on the link in the account confirmation email to activate your account."
154 @notice = "Sorry, couldn't log in with those details."
161 token = UserToken.find_by_token(session[:token])
165 session[:token] = nil
169 redirect_to params[:referer]
171 redirect_to :controller => 'site', :action => 'index'
176 if params[:confirm_action]
177 token = UserToken.find_by_token(params[:confirm_string])
178 if token and !token.user.active?
181 @user.email_valid = true
184 flash[:notice] = 'Confirmed your account, thanks for signing up!'
185 session[:user] = @user.id
186 redirect_to :action => 'account', :display_name => @user.display_name
188 @notice = 'Something went wrong confirming that user.'
194 if params[:confirm_action]
195 token = UserToken.find_by_token(params[:confirm_string])
196 if token and token.user.new_email?
198 @user.email = @user.new_email
199 @user.new_email = nil
201 @user.email_valid = true
204 flash[:notice] = 'Confirmed your email address, thanks for signing up!'
205 session[:user] = @user.id
206 redirect_to :action => 'account', :display_name => @user.display_name
208 @notice = 'Something went wrong confirming that email address.'
214 @user.image = params[:user][:image]
216 redirect_to :controller => 'user', :action => 'view', :display_name => @user.display_name
222 redirect_to :controller => 'user', :action => 'view', :display_name => @user.display_name
226 render :text => @user.to_xml.to_s, :content_type => "text/xml"
230 doc = OSM::API.new.get_xml_doc
231 @user.traces.each do |trace|
232 doc.root << trace.to_xml_node() if trace.public? or trace.user == @user
234 render :text => doc.to_s, :content_type => "text/xml"
238 @this_user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
241 @title = @this_user.display_name
243 @not_found_user = params[:display_name]
244 render :action => 'no_such_user', :status => :not_found
249 if params[:display_name]
250 name = params[:display_name]
251 new_friend = User.find_by_display_name(name, :conditions => {:visible => true})
253 friend.user_id = @user.id
254 friend.friend_user_id = new_friend.id
255 unless @user.is_friends_with?(new_friend)
257 flash[:notice] = "#{name} is now your friend."
258 Notifier.deliver_friend_notification(friend)
260 friend.add_error("Sorry, failed to add #{name} as a friend.")
263 flash[:notice] = "You are already friends with #{name}."
266 redirect_to :controller => 'user', :action => 'view'
271 if params[:display_name]
272 name = params[:display_name]
273 friend = User.find_by_display_name(name, :conditions => {:visible => true})
274 if @user.is_friends_with?(friend)
275 Friend.delete_all "user_id = #{@user.id} AND friend_user_id = #{friend.id}"
276 flash[:notice] = "#{friend.display_name} was removed from your friends."
278 flash[:notice] = "#{friend.display_name} is not one of your friends."
281 redirect_to :controller => 'user', :action => 'view'