1 class UserController < ApplicationController
4 before_filter :authorize, :only => [:api_details, :api_gpx_files]
5 before_filter :set_locale, :except => [:api_details, :api_gpx_files]
6 before_filter :authorize_web, :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
28 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."
29 Notifier.deliver_signup_confirm(@user, @user.tokens.create)
30 redirect_to :action => 'login'
32 render :action => 'new'
38 @title = 'edit account'
39 if params[:user] and params[:user][:display_name] and params[:user][:description]
40 if params[:user][:email] != @user.email
41 @user.new_email = params[:user][:email]
44 @user.display_name = params[:user][:display_name]
46 if params[:user][:pass_crypt].length > 0 or params[:user][:pass_crypt_confirmation].length > 0
47 @user.pass_crypt = params[:user][:pass_crypt]
48 @user.pass_crypt_confirmation = params[:user][:pass_crypt_confirmation]
51 @user.description = params[:user][:description]
52 @user.home_lat = params[:user][:home_lat]
53 @user.home_lon = params[:user][:home_lon]
56 if params[:user][:email] == @user.new_email
57 @notice = "User information updated successfully. Check your email for a note to confirm your new email address."
58 Notifier.deliver_email_confirm(@user, @user.tokens.create)
60 @notice = "User information updated successfully."
67 if params[:user][:home_lat] and params[:user][:home_lon]
68 @user.home_lat = params[:user][:home_lat].to_f
69 @user.home_lon = params[:user][:home_lon].to_f
71 flash[:notice] = "Home location saved successfully."
72 redirect_to :controller => 'user', :action => 'account'
78 @user.data_public = true
80 flash[:notice] = 'All your edits are now public.'
81 redirect_to :controller => 'user', :action => 'account', :display_name => @user.display_name
85 @title = 'lost password'
86 if params[:user] and params[:user][:email]
87 user = User.find_by_email(params[:user][:email], :conditions => {:visible => true})
90 token = user.tokens.create
91 Notifier.deliver_lost_password(user, token)
92 @notice = "Sorry you lost it :-( but an email is on its way so you can reset it soon."
94 @notice = "Couldn't find that email address, sorry."
100 @title = 'reset password'
102 token = UserToken.find_by_token(params[:token])
104 pass = OSM::make_token(8)
106 user.pass_crypt = pass
107 user.pass_crypt_confirmation = pass
109 user.email_valid = true
112 Notifier.deliver_reset_password(user, pass)
113 flash[:notice] = "Your password has been changed and is on its way to your mailbox :-)"
115 flash[:notice] = "Didn't find that token, check the URL maybe?"
119 redirect_to :action => 'login'
123 @title = 'create account'
124 # The user is logged in already, so don't show them the signup page, instead
125 # send them to the home page
126 redirect_to :controller => 'site', :action => 'index' if session[:user]
131 # The user is logged in already, if the referer param exists, redirect them to that
133 redirect_to params[:referer]
135 redirect_to :controller => 'site', :action => 'index'
141 email_or_display_name = params[:user][:email]
142 pass = params[:user][:password]
143 user = User.authenticate(:username => email_or_display_name, :password => pass)
145 session[:user] = user.id
147 redirect_to params[:referer]
149 redirect_to :controller => 'site', :action => 'index'
152 elsif User.authenticate(:username => email_or_display_name, :password => pass, :inactive => true)
153 @notice = "Sorry, your account is not active yet.<br>Please click on the link in the account confirmation email to activate your account."
155 @notice = "Sorry, couldn't log in with those details."
162 token = UserToken.find_by_token(session[:token])
166 session[:token] = nil
170 redirect_to params[:referer]
172 redirect_to :controller => 'site', :action => 'index'
177 if params[:confirm_action]
178 token = UserToken.find_by_token(params[:confirm_string])
179 if token and !token.user.active?
182 @user.email_valid = true
185 flash[:notice] = 'Confirmed your account, thanks for signing up!'
186 session[:user] = @user.id
187 redirect_to :action => 'account', :display_name => @user.display_name
189 @notice = 'Something went wrong confirming that user.'
195 if params[:confirm_action]
196 token = UserToken.find_by_token(params[:confirm_string])
197 if token and token.user.new_email?
199 @user.email = @user.new_email
200 @user.new_email = nil
202 @user.email_valid = true
205 flash[:notice] = 'Confirmed your email address, thanks for signing up!'
206 session[:user] = @user.id
207 redirect_to :action => 'account', :display_name => @user.display_name
209 @notice = 'Something went wrong confirming that email address.'
215 @user.image = params[:user][:image]
217 redirect_to :controller => 'user', :action => 'view', :display_name => @user.display_name
223 redirect_to :controller => 'user', :action => 'view', :display_name => @user.display_name
227 render :text => @user.to_xml.to_s, :content_type => "text/xml"
231 doc = OSM::API.new.get_xml_doc
232 @user.traces.each do |trace|
233 doc.root << trace.to_xml_node() if trace.public? or trace.user == @user
235 render :text => doc.to_s, :content_type => "text/xml"
239 @this_user = User.find_by_display_name(params[:display_name], :conditions => {:visible => true})
242 @title = @this_user.display_name
244 @not_found_user = params[:display_name]
245 render :action => 'no_such_user', :status => :not_found
250 if params[:display_name]
251 name = params[:display_name]
252 new_friend = User.find_by_display_name(name, :conditions => {:visible => true})
254 friend.user_id = @user.id
255 friend.friend_user_id = new_friend.id
256 unless @user.is_friends_with?(new_friend)
258 flash[:notice] = "#{name} is now your friend."
259 Notifier.deliver_friend_notification(friend)
261 friend.add_error("Sorry, failed to add #{name} as a friend.")
264 flash[:notice] = "You are already friends with #{name}."
267 redirect_to :controller => 'user', :action => 'view'
272 if params[:display_name]
273 name = params[:display_name]
274 friend = User.find_by_display_name(name, :conditions => {:visible => true})
275 if @user.is_friends_with?(friend)
276 Friend.delete_all "user_id = #{@user.id} AND friend_user_id = #{friend.id}"
277 flash[:notice] = "#{friend.display_name} was removed from your friends."
279 flash[:notice] = "#{friend.display_name} is not one of your friends."
282 redirect_to :controller => 'user', :action => 'view'