]> git.openstreetmap.org Git - rails.git/blob - app/controllers/user_controller.rb
trace stuff in rails port
[rails.git] / app / controllers / user_controller.rb
1 class UserController < ApplicationController
2   layout 'site'
3   
4   def save
5     @user = User.new(params[:user])
6     @user.set_defaults
7
8     if @user.save
9       flash[:notice] = 'User was successfully created. Check your email for a confirmation note, and you\'ll be mapping in no time :-)'
10       Notifier::deliver_signup_confirm(@user)
11       redirect_to :action => 'login'
12     else
13       render :action => 'new'
14     end
15   end
16
17   def lost_password
18     if params['user']['email']
19       user = User.find_by_email(params['user']['email'])
20       if user
21         user.token = User.make_token
22         user.save
23         Notifier::deliver_lost_password(user)
24         flash[:notice] = "Sorry you lost it :-( but an email is on it's way so you can reset it soon."
25       else
26         flash[:notice] = "Couldn't find that email address, sorry."
27       end
28     end
29   end
30
31   def reset_password
32     if params['token']
33       user = User.find_by_token(params['token'])
34       if user
35         pass = User.make_token(8)
36         user.pass_crypt = pass
37         user.save
38         Notifier::deliver_reset_password(user, pass)
39         flash[:notice] = "You're password has been changed and is on the way to your mailbox :-)"
40       else
41         flash[:notice] = "Didn't find that token, check the URL maybe?"
42       end
43     end
44     redirect_to :action => 'login'
45   end
46
47   def new
48   end
49
50   def login
51     if params[:user]
52       email = params[:user][:email]
53       pass = params[:user][:password]
54       u = User.authenticate(email, pass)
55       if u
56         u.token = User.make_token
57         u.timeout = 1.day.from_now
58         u.save
59         session[:token] = u.token
60         redirect_to :controller => 'site', :action => 'index'
61         return
62       else
63         flash[:notice] = "Couldn't log in with those details"
64       end
65     end
66   end
67
68   def logout
69     if session[:token]
70       u = User.find_by_token(session[:token])
71       if u
72         u.token = User.make_token
73         u.timeout = Time.now
74         u.save
75       end
76     end
77     session[:token] = nil
78     redirect_to :controller => 'site', :action => 'index'
79   end
80
81   def confirm
82     @user = User.find_by_token(params[:confirm_string])
83     if @user && @user.active == 0
84       @user.active = true
85       @user.save
86       flash[:notice] = 'Confirmed your account, thanks for signing up!'
87
88       #FIXME: login the person magically
89
90       redirect_to :action => 'login'
91     else
92       flash[:notice] = 'Something went wrong confirming that user'
93     end
94   end
95
96 end