Blob of app/controllers/users_controller.rb (raw blob data)

1 class UsersController < ApplicationController
2 # render new.rhtml
3 def new
4 end
5
6 def show
7 @user = User.find_by_login!(params[:id])
8 @projects = @user.projects.find(:all, :include => [:tags, { :repositories => :project }])
9 @repositories = @user.repositories.find(:all, :conditions => ["mainline = ?", false])
10 @events = @user.events.paginate(:all,
11 :page => params[:page],
12 :order => "events.created_at desc",
13 :include => [:user, :project])
14
15 @commits_last_week = @user.events.count(:all,
16 :conditions => ["created_at > ? AND action = ?", 7.days.ago, Action::COMMIT])
17 @atom_auto_discovery_url = formatted_feed_user_path(@user, :atom)
18
19 respond_to do |format|
20 format.html { }
21 format.atom { redirect_to formatted_feed_user_path(@user, :atom) }
22 end
23 end
24
25 def feed
26 @user = User.find_by_login!(params[:id])
27 @events = @user.events.find(:all, :order => "events.created_at desc",
28 :include => [:user, :project], :limit => 30)
29 respond_to do |format|
30 format.html { redirect_to user_path(@user) }
31 format.atom { }
32 end
33 end
34
35 def create
36 @user = User.new(params[:user])
37 @user.login = params[:user][:login]
38 @user.save!
39 flash[:notice] = "Thanks for signing up! You will receive an account activation email soon"
40 redirect_to root_path
41 rescue ActiveRecord::RecordInvalid
42 render :action => 'new'
43 end
44
45 def activate
46 if user = User.find_by_activation_code(params[:activation_code])
47 self.current_user = user
48 if logged_in? && !current_user.activated?
49 current_user.activate
50 flash[:notice] = "Your account has been activated, welcome!"
51 end
52 else
53 flash[:error] = "Invalid activation code"
54 end
55 redirect_back_or_default('/')
56 end
57
58 def forgot_password
59 end
60
61 def reset_password
62 if params[:user] && user = User.find_by_email(params[:user][:email])
63 # FIXME: should really be a two-step process: receive link, visiting it resets password
64 generated_password = user.reset_password!
65 Mailer.deliver_forgotten_password(user, generated_password)
66 flash[:notice] = "A new password has been sent to your email"
67 redirect_to(root_path)
68 else
69 flash[:error] = "Invalid email"
70 redirect_to forgot_password_users_path
71 end
72 end
73 end