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, :api_details]
9 @title = 'create account'
10 @user = User.new(params[:user])
14 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."
15 Notifier::deliver_signup_confirm(@user)
16 redirect_to :action => 'login'
18 render :action => 'new'
23 @title = 'edit account'
24 if params[:user] and params[:user][:display_name] and params[:user][:description]
25 home_lat = params[:user][:home_lat]
26 home_lon = params[:user][:home_lon]
28 @user.display_name = params[:user][:display_name]
29 if params[:user][:pass_crypt].length > 0 or params[:user][:pass_crypt_confirmation].length > 0
30 @user.pass_crypt = params[:user][:pass_crypt]
31 @user.pass_crypt_confirmation = params[:user][:pass_crypt_confirmation]
33 @user.description = params[:user][:description]
34 @user.home_lat = home_lat.to_f
35 @user.home_lon = home_lon.to_f
37 flash[:notice] = "User information updated successfully."
45 if params[:user][:home_lat] and params[:user][:home_lon]
46 @user.home_lat = params[:user][:home_lat].to_f
47 @user.home_lon = params[:user][:home_lon].to_f
49 flash[:notice] = "Home location saved successfully."
50 redirect_to :controller => 'user', :action => 'account'
56 @user.data_public = true
58 flash[:notice] = 'All your edits are now public.'
59 redirect_to :controller => 'user', :action => 'account', :display_name => @user.display_name
63 @title = 'lost password'
64 if params[:user] and params[:user][:email]
65 user = User.find_by_email(params['user']['email'])
67 user.token = User.make_token
69 Notifier::deliver_lost_password(user)
70 flash[:notice] = "Sorry you lost it :-( but an email is on its way so you can reset it soon."
72 flash[:notice] = "Couldn't find that email address, sorry."
75 render :action => 'lost_password'
80 @title = 'reset password'
82 user = User.find_by_token(params['token'])
84 pass = User.make_token(8)
85 user.pass_crypt = pass
86 user.pass_crypt_confirmation = pass
89 Notifier::deliver_reset_password(user, pass)
90 flash[:notice] = "Your password has been changed and is on its way to your mailbox :-)"
92 flash[:notice] = "Didn't find that token, check the URL maybe?"
95 redirect_to :action => 'login'
99 @title = 'create account'
105 email = params[:user][:email]
106 pass = params[:user][:password]
107 u = User.authenticate(email, pass)
109 u.token = User.make_token
110 u.timeout = 1.day.from_now
112 session[:token] = u.token
114 redirect_to params[:referer]
116 redirect_to :controller => 'site', :action => 'index'
119 elsif User.authenticate(email, pass, false)
120 flash[:notice] = "Sorry, your account is not active yet.<br>Please click on the link in the account confirmation email to activate your account."
122 flash[:notice] = "Sorry, couldn't log in with those details."
129 u = User.find_by_token(session[:token])
131 u.token = User.make_token
136 session[:token] = nil
138 redirect_to params[:referer]
140 redirect_to :controller => 'site', :action => 'index'
145 @user = User.find_by_token(params[:confirm_string])
146 if @user && @user.active == 0
148 @user.token = User.make_token
149 @user.timeout = 1.day.from_now
151 flash[:notice] = 'Confirmed your account, thanks for signing up!'
152 session[:token] = @user.token
153 redirect_to :action => 'account', :display_name => @user.display_name
155 flash[:notice] = 'Something went wrong confirming that user.'
160 @title = 'preferences'
162 render_text @user.preferences
163 elsif request.post? or request.put?
164 @user.preferences = request.raw_post
166 render :nothing => true
168 render :nothing => true, :status => :method_not_allowed
173 render :text => @user.to_xml.to_s
177 doc = OSM::API.new.get_xml_doc
178 @user.traces.each do |trace|
179 doc.root << trace.to_xml_node() if trace.public? or trace.user == @user
181 render :text => doc.to_s
185 @this_user = User.find_by_display_name(params[:display_name])
186 @title = @this_user.display_name
191 if params[:display_name]
192 name = params[:display_name]
194 friend.user_id = @user.id
195 friend.friend_user_id = User.find_by_display_name(name).id
196 unless @user.is_friends_with?(friend)
198 flash[:notice] = "#{name} is now your friend."
200 friend.add_error("Sorry, failed to add #{name} as a friend.")
203 flash[:notice] = "You are already friends with #{name}."
205 redirect_to :controller => 'user', :action => 'view'