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, :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 @user.display_name = params[:user][:display_name]
24 @user.description = params[:user][:description]
26 flash[:notice] = "User edited OK."
27 redirect_to :controller => 'user', :action => 'account'
33 if params[:user][:home_lat] and params[:user][:home_lon]
34 lat = params[:user][:home_lat]
35 lon = params[:user][:home_lon]
37 #check the lat and lon
39 #make an api request to insert a new node
45 @user.data_public = true
47 flash[:notice] = 'All your edits are now public'
48 redirect_to :controller => 'user', :action => 'account'
52 if params['user']['email']
53 user = User.find_by_email(params['user']['email'])
55 user.token = User.make_token
57 Notifier::deliver_lost_password(user)
58 flash[:notice] = "Sorry you lost it :-( but an email is on it's way so you can reset it soon."
60 flash[:notice] = "Couldn't find that email address, sorry."
67 user = User.find_by_token(params['token'])
69 pass = User.make_token(8)
70 user.pass_crypt = pass
72 Notifier::deliver_reset_password(user, pass)
73 flash[:notice] = "You're password has been changed and is on the way to your mailbox :-)"
75 flash[:notice] = "Didn't find that token, check the URL maybe?"
78 redirect_to :action => 'login'
86 email = params[:user][:email]
87 pass = params[:user][:password]
88 u = User.authenticate(email, pass)
90 u.token = User.make_token
91 u.timeout = 1.day.from_now
93 session[:token] = u.token
94 redirect_to :controller => 'site', :action => 'index'
97 flash[:notice] = "Couldn't log in with those details"
104 u = User.find_by_token(session[:token])
106 u.token = User.make_token
111 session[:token] = nil
112 redirect_to :controller => 'site', :action => 'index'
116 @user = User.find_by_token(params[:confirm_string])
117 if @user && @user.active == 0
120 flash[:notice] = 'Confirmed your account, thanks for signing up!'
122 #FIXME: login the person magically
124 redirect_to :action => 'login'
126 flash[:notice] = 'Something went wrong confirming that user'
132 render_text @user.preferences
133 elsif request.post? or request.put?
134 @user.preferences = request.raw_post
136 render :nothing => true
138 render :status => 400, :nothing => true
143 render :text => @user.to_xml.to_s
147 doc = OSM::API.new.get_xml_doc
148 @user.traces.each do |trace|
149 doc.root << trace.to_xml_node() if trace.public? or trace.user == @user
151 render :text => doc.to_s
155 @this_user = User.find_by_display_name(params[:display_name])
159 @this_user = User.find_by_display_name(params[:display_name])