1 class UserController < ApplicationController
4 before_filter :authorize, :only => [:api_details, :api_gpx_files]
5 before_filter :authorize_web, :only => [:account, :go_public, :view, :diary, :make_friend, :remove_friend, :upload_image, :delete_image]
6 before_filter :require_user, :only => [:set_home, :account, :go_public, :make_friend, :remove_friend, :upload_image, :delete_image]
7 before_filter :check_database_availability, :except => [:api_details, :api_gpx_files]
8 before_filter :check_read_availability, :only => [:api_details, :api_gpx_files]
10 filter_parameter_logging :password, :pass_crypt, :pass_crypt_confirmation
13 @title = 'create account'
14 @user = User.new(params[:user])
16 @user.data_public = true
17 @user.description = "" if @user.description.nil?
20 token = @user.tokens.create
21 flash[:notice] = "User was successfully created. Check your email for a confirmation note, and you\'ll be mapping in no time :-)<br>Please note that you won't be able to login until you've received and confirmed your email address."
22 Notifier::deliver_signup_confirm(@user, token)
23 redirect_to :action => 'login'
25 render :action => 'new'
30 @title = 'edit account'
31 if params[:user] and params[:user][:display_name] and params[:user][:description]
32 home_lat = params[:user][:home_lat]
33 home_lon = params[:user][:home_lon]
35 @user.display_name = params[:user][:display_name]
36 if params[:user][:pass_crypt].length > 0 or params[:user][:pass_crypt_confirmation].length > 0
37 @user.pass_crypt = params[:user][:pass_crypt]
38 @user.pass_crypt_confirmation = params[:user][:pass_crypt_confirmation]
40 @user.description = params[:user][:description]
41 @user.home_lat = home_lat
42 @user.home_lon = home_lon
44 flash[:notice] = "User information updated successfully."
52 if params[:user][:home_lat] and params[:user][:home_lon]
53 @user.home_lat = params[:user][:home_lat].to_f
54 @user.home_lon = params[:user][:home_lon].to_f
56 flash[:notice] = "Home location saved successfully."
57 redirect_to :controller => 'user', :action => 'account'
63 @user.data_public = true
65 flash[:notice] = 'All your edits are now public.'
66 redirect_to :controller => 'user', :action => 'account', :display_name => @user.display_name
70 @title = 'lost password'
71 if params[:user] and params[:user][:email]
72 user = User.find_by_email(params[:user][:email])
74 token = user.tokens.create
75 Notifier::deliver_lost_password(user, token)
76 flash[:notice] = "Sorry you lost it :-( but an email is on its way so you can reset it soon."
78 flash[:notice] = "Couldn't find that email address, sorry."
81 render :action => 'lost_password'
86 @title = 'reset password'
88 token = UserToken.find_by_token(params[:token])
90 pass = OSM::make_token(8)
92 user.pass_crypt = pass
93 user.pass_crypt_confirmation = pass
97 Notifier::deliver_reset_password(user, pass)
98 flash[:notice] = "Your password has been changed and is on its way to your mailbox :-)"
100 flash[:notice] = "Didn't find that token, check the URL maybe?"
103 redirect_to :action => 'login'
107 @title = 'create account'
113 email_or_display_name = params[:user][:email]
114 pass = params[:user][:password]
115 user = User.authenticate(:username => email_or_display_name, :password => pass)
117 session[:user] = user.id
119 redirect_to params[:referer]
121 redirect_to :controller => 'site', :action => 'index'
124 elsif User.authenticate(:username => email_or_display_name, :password => pass, :inactive => true)
125 flash[:notice] = "Sorry, your account is not active yet.<br>Please click on the link in the account confirmation email to activate your account."
127 flash[:notice] = "Sorry, couldn't log in with those details."
134 token = UserToken.find_by_token(session[:token])
138 session[:token] = nil
142 redirect_to params[:referer]
144 redirect_to :controller => 'site', :action => 'index'
149 if params[:confirm_action]
150 token = UserToken.find_by_token(params[:confirm_string])
151 if token and !token.user.active?
156 flash[:notice] = 'Confirmed your account, thanks for signing up!'
157 session[:user] = @user.id
158 redirect_to :action => 'account', :display_name => @user.display_name
160 flash[:notice] = 'Something went wrong confirming that user.'
166 @user.image = params[:user][:image]
168 redirect_to :controller => 'user', :action => 'view', :display_name => @user.display_name
174 redirect_to :controller => 'user', :action => 'view', :display_name => @user.display_name
178 render :text => @user.to_xml.to_s, :content_type => "text/xml"
182 doc = OSM::API.new.get_xml_doc
183 @user.traces.each do |trace|
184 doc.root << trace.to_xml_node() if trace.public? or trace.user == @user
186 render :text => doc.to_s, :content_type => "text/xml"
190 @this_user = User.find_by_display_name(params[:display_name])
193 @title = @this_user.display_name
195 @not_found_user = params[:display_name]
196 render :action => 'no_such_user', :status => :not_found
201 if params[:display_name]
202 name = params[:display_name]
203 new_friend = User.find_by_display_name(name)
205 friend.user_id = @user.id
206 friend.friend_user_id = new_friend.id
207 unless @user.is_friends_with?(new_friend)
209 flash[:notice] = "#{name} is now your friend."
210 Notifier::deliver_friend_notification(friend)
212 friend.add_error("Sorry, failed to add #{name} as a friend.")
215 flash[:notice] = "You are already friends with #{name}."
217 redirect_to :controller => 'user', :action => 'view'
222 if params[:display_name]
223 name = params[:display_name]
224 friend = User.find_by_display_name(name)
225 if @user.is_friends_with?(friend)
226 Friend.delete_all "user_id = #{@user.id} AND friend_user_id = #{friend.id}"
227 flash[:notice] = "#{friend.display_name} was removed from your friends."
229 flash[:notice] = "#{friend.display_name} was not already one of your friends."
231 redirect_to :controller => 'user', :action => 'view'