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

1 class UsersController < ApplicationController
2
3 # render new.rhtml
4 def new
5 end
6
7 def show
8 @user = User.find_by_login!(params[:id])
9 @projects = @user.projects.find(:all)
10 @repositories = @user.repositories.find(:all, :conditions => ["mainline = ?", false])
11
12 @commits_last_week = 0
13 # @projects.map{|p| p.repositories.first }.concat(@repositories).each do |repo|
14 # @commits_last_week += repo.count_commits_from_last_week_by_user(@user)
15 # end
16 render :action => 'ac_show'
17 end
18
19 def create
20 @user = User.new
21 @user.login = params[:login]
22 @user.email = params[:email]
23 @user.password = params[:password]
24 @user.password_confirmation = params[:password_confirmation]
25 @user.save!
26 flash[:notice] = "Thanks for signing up! You will receive an account activation email soon"
27 redirect_to root_path
28 rescue ActiveRecord::RecordInvalid
29 render :action => 'new'
30 end
31
32 def activate
33 if user = User.find_by_activation_code(params[:activation_code])
34 self.current_user = user
35 if logged_in? && !current_user.activated?
36 current_user.activate
37 flash[:notice] = "Your account has been activated, welcome!"
38 end
39 else
40 flash[:error] = "Invalid activation code"
41 end
42 redirect_back_or_default('/')
43 end
44
45 def forgot_password
46 end
47
48 def reset_password
49 if params[:user] && user = User.find_by_email(params[:user][:email])
50 # FIXME: should really be a two-step process: receive link, visiting it resets password
51 generated_password = user.reset_password!
52 Mailer.deliver_forgotten_password(user, generated_password)
53 flash[:notice] = "A new password has been sent to your email"
54 redirect_to(root_path)
55 else
56 flash[:error] = "Invalid email"
57 redirect_to forgot_password_users_path
58 end
59 end
60 end