1 class UserController < ApplicationController
4 before_filter :authorize, :only => [:preferences, :api_details, :api_gpx_files]
5 before_filter :authorize_web, :only => [:edit, :account, :go_public, :view, :diary, :make_friend]
6 before_filter :require_user, :only => [:edit, :set_home, :account, :go_public, :make_friend]
9 @user = User.new(params[:user])
13 flash[:notice] = 'User was successfully created. Check your email for a confirmation note, and you\'ll be mapping in no time :-)'
14 Notifier::deliver_signup_confirm(@user)
15 redirect_to :action => 'login'
17 render :action => 'new'
22 if params[:user] and params[:user][:display_name] and params[:user][:description]
23 home_lat = params[:user][:home_lat]
24 home_lon = params[:user][:home_lon]
26 @user.display_name = params[:user][:display_name]
27 @user.description = params[:user][:description]
28 @user.home_lat = home_lat.to_f
29 @user.home_lon = home_lon.to_f
31 flash[:notice] = "User information updated successfully."
32 redirect_to :controller => 'user', :action => 'account'
38 if params[:user][:home_lat] and params[:user][:home_lon]
39 @user.home_lat = params[:user][:home_lat].to_f
40 @user.home_lon = params[:user][:home_lon].to_f
42 flash[:notice] = "Home location saved successfully."
43 redirect_to :controller => 'user', :action => 'account'
49 @user.data_public = true
51 flash[:notice] = 'All your edits are now public.'
52 redirect_to :controller => 'user', :action => 'account', :display_name => @user.display_name
56 if params[:user] and params[:user][:email]
57 user = User.find_by_email(params['user']['email'])
59 user.token = User.make_token
61 Notifier::deliver_lost_password(user)
62 flash[:notice] = "Sorry you lost it :-( but an email is on its way so you can reset it soon."
64 flash[:notice] = "Couldn't find that email address, sorry."
67 render :action => 'lost_password'
73 user = User.find_by_token(params['token'])
75 pass = User.make_token(8)
76 user.pass_crypt = pass
77 user.pass_crypt_confirmation = pass
79 Notifier::deliver_reset_password(user, pass)
80 flash[:notice] = "Your password has been changed and is on its way to your mailbox :-)"
82 flash[:notice] = "Didn't find that token, check the URL maybe?"
85 redirect_to :action => 'login'
93 email = params[:user][:email]
94 pass = params[:user][:password]
95 u = User.authenticate(email, pass)
97 u.token = User.make_token
98 u.timeout = 1.day.from_now
100 session[:token] = u.token
101 if params[:next_controller] and params[:next_action]
102 redirect_to :controller => params[:next_controller], :action => params[:next_action]
104 redirect_to :controller => 'site', :action => 'index'
108 flash[:notice] = "Sorry, couldn't log in with those details."
115 u = User.find_by_token(session[:token])
117 u.token = User.make_token
122 session[:token] = nil
123 if params[:next_controller] and params[:next_action]
124 redirect_to :controller => params[:next_controller], :action => params[:next_action]
126 redirect_to :controller => 'site', :action => 'index'
131 @user = User.find_by_token(params[:confirm_string])
132 if @user && @user.active == 0
135 flash[:notice] = 'Confirmed your account, thanks for signing up!'
137 #FIXME: login the person magically
139 redirect_to :action => 'login'
141 flash[:notice] = 'Something went wrong confirming that user.'
147 render_text @user.preferences
148 elsif request.post? or request.put?
149 @user.preferences = request.raw_post
151 render :nothing => true
153 render :status => 400, :nothing => true
158 render :text => @user.to_xml.to_s
162 doc = OSM::API.new.get_xml_doc
163 @user.traces.each do |trace|
164 doc.root << trace.to_xml_node() if trace.public? or trace.user == @user
166 render :text => doc.to_s
170 @this_user = User.find_by_display_name(params[:display_name])
174 @this_user = User.find_by_display_name(params[:display_name])
179 if params[:display_name]
180 name = params[:display_name]
182 friend.user_id = @user.id
183 friend.friend_user_id = User.find_by_display_name(name).id
184 unless @user.is_friends_with?(friend)
186 flash[:notice] = "#{name} is now your friend."
188 friend.add_error("Sorry, failed to add #{name} as a friend.")
191 flash[:notice] = "You are already friends with #{name}."
193 redirect_to :controller => 'user', :action => 'view'