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
19 token = @user.tokens.create
20 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."
21 Notifier::deliver_signup_confirm(@user, token)
22 redirect_to :action => 'login'
24 render :action => 'new'
29 @title = 'edit account'
30 if params[:user] and params[:user][:display_name] and params[:user][:description]
31 home_lat = params[:user][:home_lat]
32 home_lon = params[:user][:home_lon]
34 @user.display_name = params[:user][:display_name]
35 if params[:user][:pass_crypt].length > 0 or params[:user][:pass_crypt_confirmation].length > 0
36 @user.pass_crypt = params[:user][:pass_crypt]
37 @user.pass_crypt_confirmation = params[:user][:pass_crypt_confirmation]
39 @user.description = params[:user][:description]
40 @user.home_lat = home_lat
41 @user.home_lon = home_lon
43 flash[:notice] = "User information updated successfully."
51 if params[:user][:home_lat] and params[:user][:home_lon]
52 @user.home_lat = params[:user][:home_lat].to_f
53 @user.home_lon = params[:user][:home_lon].to_f
55 flash[:notice] = "Home location saved successfully."
56 redirect_to :controller => 'user', :action => 'account'
62 @user.data_public = true
64 flash[:notice] = 'All your edits are now public.'
65 redirect_to :controller => 'user', :action => 'account', :display_name => @user.display_name
69 @title = 'lost password'
70 if params[:user] and params[:user][:email]
71 user = User.find_by_email(params[:user][:email])
73 token = user.tokens.create
74 Notifier::deliver_lost_password(user, token)
75 flash[:notice] = "Sorry you lost it :-( but an email is on its way so you can reset it soon."
77 flash[:notice] = "Couldn't find that email address, sorry."
80 render :action => 'lost_password'
85 @title = 'reset password'
87 token = UserToken.find_by_token(params[:token])
89 pass = OSM::make_token(8)
91 user.pass_crypt = pass
92 user.pass_crypt_confirmation = pass
96 Notifier::deliver_reset_password(user, pass)
97 flash[:notice] = "Your password has been changed and is on its way to your mailbox :-)"
99 flash[:notice] = "Didn't find that token, check the URL maybe?"
102 redirect_to :action => 'login'
106 @title = 'create account'
112 email_or_display_name = params[:user][:email]
113 pass = params[:user][:password]
114 user = User.authenticate(:username => email_or_display_name, :password => pass)
116 session[:user] = user.id
118 redirect_to params[:referer]
120 redirect_to :controller => 'site', :action => 'index'
123 elsif User.authenticate(:username => email_or_display_name, :password => pass, :inactive => true)
124 flash[:notice] = "Sorry, your account is not active yet.<br>Please click on the link in the account confirmation email to activate your account."
126 flash[:notice] = "Sorry, couldn't log in with those details."
133 token = UserToken.find_by_token(session[:token])
137 session[:token] = nil
141 redirect_to params[:referer]
143 redirect_to :controller => 'site', :action => 'index'
148 if params[:confirm_action]
149 token = UserToken.find_by_token(params[:confirm_string])
150 if token and !token.user.active?
155 flash[:notice] = 'Confirmed your account, thanks for signing up!'
156 session[:user] = @user.id
157 redirect_to :action => 'account', :display_name => @user.display_name
159 flash[:notice] = 'Something went wrong confirming that user.'
165 @user.image = params[:user][:image]
167 redirect_to :controller => 'user', :action => 'view', :display_name => @user.display_name
173 redirect_to :controller => 'user', :action => 'view', :display_name => @user.display_name
177 render :text => @user.to_xml.to_s, :content_type => "text/xml"
181 doc = OSM::API.new.get_xml_doc
182 @user.traces.each do |trace|
183 doc.root << trace.to_xml_node() if trace.public? or trace.user == @user
185 render :text => doc.to_s, :content_type => "text/xml"
189 @this_user = User.find_by_display_name(params[:display_name])
192 @title = @this_user.display_name
194 @not_found_user = params[:display_name]
195 render :action => 'no_such_user', :status => :not_found
200 if params[:display_name]
201 name = params[:display_name]
202 new_friend = User.find_by_display_name(name)
204 friend.user_id = @user.id
205 friend.friend_user_id = new_friend.id
206 unless @user.is_friends_with?(new_friend)
208 flash[:notice] = "#{name} is now your friend."
209 Notifier::deliver_friend_notification(friend)
211 friend.add_error("Sorry, failed to add #{name} as a friend.")
214 flash[:notice] = "You are already friends with #{name}."
216 redirect_to :controller => 'user', :action => 'view'
221 if params[:display_name]
222 name = params[:display_name]
223 friend = User.find_by_display_name(name)
224 if @user.is_friends_with?(friend)
225 Friend.delete_all "user_id = #{@user.id} AND friend_user_id = #{friend.id}"
226 flash[:notice] = "#{friend.display_name} was removed from your friends."
228 flash[:notice] = "#{friend.display_name} was not already one of your friends."
230 redirect_to :controller => 'user', :action => 'view'