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]
6 before_filter :require_user, :only => [:edit, :set_home, :account, :go_public]
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 edited OK."
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] = "User home saved."
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'
56 if 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 it's way so you can reset it soon."
64 flash[:notice] = "Couldn't find that email address, sorry."
71 user = User.find_by_token(params['token'])
73 pass = User.make_token(8)
74 user.pass_crypt = pass
76 Notifier::deliver_reset_password(user, pass)
77 flash[:notice] = "You're password has been changed and is on the way to your mailbox :-)"
79 flash[:notice] = "Didn't find that token, check the URL maybe?"
82 redirect_to :action => 'login'
90 email = params[:user][:email]
91 pass = params[:user][:password]
92 u = User.authenticate(email, pass)
94 u.token = User.make_token
95 u.timeout = 1.day.from_now
97 session[:token] = u.token
98 redirect_to :controller => 'site', :action => 'index'
101 flash[:notice] = "Couldn't log in with those details"
108 u = User.find_by_token(session[:token])
110 u.token = User.make_token
115 session[:token] = nil
116 redirect_to :controller => 'site', :action => 'index'
120 @user = User.find_by_token(params[:confirm_string])
121 if @user && @user.active == 0
124 flash[:notice] = 'Confirmed your account, thanks for signing up!'
126 #FIXME: login the person magically
128 redirect_to :action => 'login'
130 flash[:notice] = 'Something went wrong confirming that user'
136 render_text @user.preferences
137 elsif request.post? or request.put?
138 @user.preferences = request.raw_post
140 render :nothing => true
142 render :status => 400, :nothing => true
147 render :text => @user.to_xml.to_s
151 doc = OSM::API.new.get_xml_doc
152 @user.traces.each do |trace|
153 doc.root << trace.to_xml_node() if trace.public? or trace.user == @user
155 render :text => doc.to_s
159 @this_user = User.find_by_display_name(params[:display_name])
163 @this_user = User.find_by_display_name(params[:display_name])
166 def contact_others(user_id, message_body)
167 @to = User.find_by_id(user_id)
168 @to.messages.new = body
170 flash[:notice] = Message sent
173 #Send a message to other users - maybe there's a rails messaging plugin