Class: Muck::UsersController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/muck/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#activation_instructionsObject



27
28
29
30
31
32
33
# File 'app/controllers/muck/users_controller.rb', line 27

def activation_instructions
  @page_title = t('muck.users.welcome')
  @user = User.find(params[:id])
  respond_to do |format|
    format.html { render :template => 'users/activation_instructions' }
  end
end

#createObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/muck/users_controller.rb', line 47

def create
  @page_title = t('muck.users.register_account', :application_name => MuckEngine.configuration.application_name)
  cookies.delete :auth_token
  @user = User.new(params[:user])
  setup_tos
  check_access_code
  check_recaptcha
  if before_create_user
    success, path = setup_user
    after_create_user(success)
    after_create_response(success, path)
  else
    after_create_response(false)
  end
rescue MuckUsers::Exceptions::InvalidAccessCode, ActiveRecord::RecordInvalid => ex
  after_create_response(false)
end

#destroyObject



83
84
85
86
87
88
89
90
# File 'app/controllers/muck/users_controller.rb', line 83

def destroy
  return unless admin? || MuckUsers.configuration.
  @user = admin? ? User.find(params[:id]) : User.find(current_user)
  if @user.destroy
    flash[:notice] = t("muck.users.user_account_deleted")
  end
  after_destroy_response
end

#editObject



41
42
43
44
45
# File 'app/controllers/muck/users_controller.rb', line 41

def edit
  @page_title = t('muck.users.update_profile')
  @user = admin? ? User.find(params[:id]) : current_user
  standard_response('edit', true)
end

#is_email_availableObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'app/controllers/muck/users_controller.rb', line 131

def is_email_available
  @available = 'unavailable'
  @output_element = 'email'
  if params[:user_email].nil?
    result = ''
  elsif params[:user_email].empty?
    result = t('muck.users.email_empty')
  elsif !User.email_exists?(params[:user_email])
    valid, errors = valid_email?(params[:user_email])
    if valid
      result = t('muck.users.email_available')
    else
      result = t('muck.users.email_invalid')
    end
  else
    recover_password_prompt = render_to_string :partial => 'users/recover_password_via_email_link', :locals => { :email => params[:user_email] }
    result = t('muck.users.email_not_available', :reset_password_help => recover_password_prompt.html_safe).html_safe
    respond_to do |format|
      format.html { render :partial => 'users/availability', :locals => { :message => result } }
      format.js { render :partial => 'users/availability', :locals => { :message => result } }
    end
    return
  end  
  if errors.blank? && ! result.nil?
    @available = 'available'
  end
  respond_to do |format|
    format.html { render :partial => 'users/availability', :locals => { :message => result } }
    format.js { render :partial => 'users/availability', :locals => { :message => result } }
  end
end

#is_login_availableObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'app/controllers/muck/users_controller.rb', line 104

def 
  @available = 'unavailable'
  @output_element = 'username'    
  recover_password_prompt = render_to_string :partial => 'users/recover_password_via_email_link', :locals => { :email => params[:user_email] }
  result = t('muck.users.username_not_available', :reset_password_help => recover_password_prompt.html_safe).html_safe
  if params[:user_login].nil?
    result = ''
  elsif params[:user_login].empty?
    result = t('muck.users.login_empty')
  elsif !User.(params[:user_login])
    @user = User.new(:login => params[:user_login])
    @user.valid? # we aren't interested in the output of this.
    if !@user.errors[:login].blank?
      result = "#{t('muck.users.invalid_username')} <br /> #{t('muck.users.username')} #{@user.errors[:login]}"
    else
      result = t('muck.users.username_available')
    end
  end
  if !@user.blank? && @user.errors[:login].blank? && !result.blank?
    @available = 'available'
  end
  respond_to do |format|
    format.html { render :partial => 'users/availability', :locals => { :message => result } }
    format.js { render :partial => 'users/availability', :locals => { :message => result } }
  end
end

#login_searchObject



92
93
94
95
96
97
98
99
100
101
102
# File 'app/controllers/muck/users_controller.rb', line 92

def 
  if params[:q]
    @users = User..(params[:q], :limit => params[:limit] || 100)
  else
    @users = User.(:limit => params[:limit] || 100)
  end
  respond_to do |format|
    format.js { render :text => @users.collect{|user| user. }.join("\n") }
    format.json { render :json => @users.collect{|user| { :login => user. } }.to_json }
  end
end

#newObject



35
36
37
38
39
# File 'app/controllers/muck/users_controller.rb', line 35

def new
  @page_title = t('muck.users.register_account', :application_name => MuckEngine.configuration.application_name)
  @user = User.new(:access_code_code => params[:access_code])
  standard_response('new', true)
end

#showObject



8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/muck/users_controller.rb', line 8

def show
  @user = User.find(params[:id]) if params[:id]
  @user ||= current_user
  if @user == current_user
    @page_title = @user.to_param
    standard_response('show', true)
  else
    standard_response('show', false, public_user_path(@user))
  end
end

#updateObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/muck/users_controller.rb', line 65

def update
  @title = t("users.update_profile")
  @user = admin? ? User.find(params[:id]) : User.find(current_user)
  @user.attributes = params[:user]
  if before_update_user
    success = @user.save
    after_update_user(success)
    if success
      flash[:notice] = t("muck.users.user_update")
      after_update_response(true)
    else
      after_update_response(false)
    end
  else
    after_update_response(false)
  end
end

#welcomeObject



19
20
21
22
23
24
25
# File 'app/controllers/muck/users_controller.rb', line 19

def welcome
  @page_title = t('muck.users.welcome')
  @user = User.find(params[:id])
  respond_to do |format|
    format.html { render :template => 'users/welcome' }
  end
end