1 class UserController < ApplicationController
4 before_filter :authorize, :only => [:preferences, :api_details, :api_gpx_files]
5 before_filter :authorize_web, :only => [:account, :go_public, :view, :diary, :make_friend]
6 before_filter :require_user, :only => [: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 if params[:user][:pass_crypt].length > 0 or params[:user][:pass_crypt_confirmation].length > 0
28 @user.pass_crypt = params[:user][:pass_crypt]
29 @user.pass_crypt_confirmation = params[:user][:pass_crypt_confirmation]
31 @user.description = params[:user][:description]
32 @user.home_lat = home_lat.to_f
33 @user.home_lon = home_lon.to_f
35 flash[:notice] = "User information updated successfully."
43 if params[:user][:home_lat] and params[:user][:home_lon]
44 @user.home_lat = params[:user][:home_lat].to_f
45 @user.home_lon = params[:user][:home_lon].to_f
47 flash[:notice] = "Home location saved successfully."
48 redirect_to :controller => 'user', :action => 'account'
54 @user.data_public = true
56 flash[:notice] = 'All your edits are now public.'
57 redirect_to :controller => 'user', :action => 'account', :display_name => @user.display_name
61 if params[:user] and params[:user][:email]
62 user = User.find_by_email(params['user']['email'])
64 user.token = User.make_token
66 Notifier::deliver_lost_password(user)
67 flash[:notice] = "Sorry you lost it :-( but an email is on its way so you can reset it soon."
69 flash[:notice] = "Couldn't find that email address, sorry."
72 render :action => 'lost_password'
78 user = User.find_by_token(params['token'])
80 pass = User.make_token(8)
81 user.pass_crypt = pass
82 user.pass_crypt_confirmation = pass
85 Notifier::deliver_reset_password(user, pass)
86 flash[:notice] = "Your password has been changed and is on its way to your mailbox :-)"
88 flash[:notice] = "Didn't find that token, check the URL maybe?"
91 redirect_to :action => 'login'
99 email = params[:user][:email]
100 pass = params[:user][:password]
101 u = User.authenticate(email, pass)
103 u.token = User.make_token
104 u.timeout = 1.day.from_now
106 session[:token] = u.token
108 redirect_to params[:referer]
110 redirect_to :controller => 'site', :action => 'index'
114 flash[:notice] = "Sorry, couldn't log in with those details."
121 u = User.find_by_token(session[:token])
123 u.token = User.make_token
128 session[:token] = nil
130 redirect_to params[:referer]
132 redirect_to :controller => 'site', :action => 'index'
137 @user = User.find_by_token(params[:confirm_string])
138 if @user && @user.active == 0
141 flash[:notice] = 'Confirmed your account, thanks for signing up!'
143 #FIXME: login the person magically
145 redirect_to :action => 'login'
147 flash[:notice] = 'Something went wrong confirming that user.'
153 render_text @user.preferences
154 elsif request.post? or request.put?
155 @user.preferences = request.raw_post
157 render :nothing => true
159 render :status => 400, :nothing => true
164 render :text => @user.to_xml.to_s
168 doc = OSM::API.new.get_xml_doc
169 @user.traces.each do |trace|
170 doc.root << trace.to_xml_node() if trace.public? or trace.user == @user
172 render :text => doc.to_s
176 @this_user = User.find_by_display_name(params[:display_name])
180 @this_user = User.find_by_display_name(params[:display_name])
185 if params[:display_name]
186 name = params[:display_name]
188 friend.user_id = @user.id
189 friend.friend_user_id = User.find_by_display_name(name).id
190 unless @user.is_friends_with?(friend)
192 flash[:notice] = "#{name} is now your friend."
194 friend.add_error("Sorry, failed to add #{name} as a friend.")
197 flash[:notice] = "You are already friends with #{name}."
199 redirect_to :controller => 'user', :action => 'view'