Class: UsersController

Inherits:
ApplicationController show all
Defined in:
vendor/plugins/authentication/test/functional/users_controller_test.rb,
vendor/plugins/authentication/app/controllers/users_controller.rb

Overview

Re-raise errors caught by the controller.

Instance Method Summary collapse

Methods inherited from Refinery::ApplicationController

#admin?, #error_404, #from_dialog?, #home_page?, #just_installed?, #local_request?, #wymiframe

Methods included from Crud

append_features

Instance Method Details

#activateObject



47
48
49
50
51
52
53
54
55
56
# File 'vendor/plugins/authentication/app/controllers/users_controller.rb', line 47

def activate
  self.current_user = params[:activation_code].blank? ? false : User.find_by_activation_code(params[:activation_code])

  if logged_in? && !current_user.active?
    current_user.activate!
    flash[:notice] = "Signup complete!"
  end

  redirect_back_or_default(root_url)
end

#createObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'vendor/plugins/authentication/app/controllers/users_controller.rb', line 14

def create
  unless can_create_public_user
    render :text => "User signup is disabled", :layout => true
  else
    begin
      cookies.delete :auth_token
      # protects against session fixation attacks, wreaks havoc with
      # request forgery protection.
      # uncomment at your own risk
      # reset_session
      @user = User.new(params[:user])
      @selected_plugin_titles = params[:user][:plugins] || []

      @user.register! if @user.valid?
      if @user.errors.empty?
        @user.plugins = @selected_plugin_titles
        self.current_user = @user
        current_user.activate!
        current_user.update_attribute(:superuser, true) if User.count == 1 # this is the superuser if this user is the only user.
        redirect_back_or_default(admin_root_url)
        flash[:notice] = "Welcome to Refinery, #{current_user.}."

        if User.count == 1 or RefinerySetting[:site_name] == "Company Name"
          refinery_setting = RefinerySetting.find_by_name("site_name")
          flash[:notice] << "<br/>First let's give the site a name. <a href='#{edit_admin_refinery_setting_url(refinery_setting)}'>Go here</a> to edit your website's name"
        end
      else
        render :action => 'new'
      end
    end
  end
end

#forgotObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'vendor/plugins/authentication/app/controllers/users_controller.rb', line 58

def forgot
  if request.post?
    if (user = User.find_by_email(params[:user][:email])).present?
      user.create_reset_code

      begin
        flash[:notice] = "An email has been sent to #{user.email} with a link to reset your password."
        UserMailer.deliver_reset_notification(user, request)
      rescue
        logger.info "Error: email could not be sent for user password reset for user #{user.id} with email #{user.email}"
      end
    else
      flash[:notice] = "Sorry, #{params[:user][:email]} isn't associated with any accounts. Are you sure you typed the correct email address?"
    end

    redirect_back_or_default(forgot_url)
  end
end

#newObject



10
11
12
# File 'vendor/plugins/authentication/app/controllers/users_controller.rb', line 10

def new
  render :text => "User signup is disabled", :layout => true unless can_create_public_user
end

#rescue_action(e) ⇒ Object



5
# File 'vendor/plugins/authentication/test/functional/users_controller_test.rb', line 5

def rescue_action(e) raise e end

#resetObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'vendor/plugins/authentication/app/controllers/users_controller.rb', line 77

def reset
  @user = User.find_by_reset_code(params[:reset_code]) unless params[:reset_code].nil?

  if request.post?
    if @user.update_attributes(:password => params[:user][:password], :password_confirmation => params[:user][:password_confirmation])
      self.current_user = @user
      @user.delete_reset_code

      flash[:notice] = "Password reset successfully for #{@user.email}"
      redirect_back_or_default(admin_root_url)
    else
      render :action => :reset
    end
  end
end