Class: ErpTechSvcs::UserController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/erp_tech_svcs/user_controller.rb

Instance Method Summary collapse

Instance Method Details

#activateObject



3
4
5
6
7
8
9
10
11
# File 'app/controllers/erp_tech_svcs/user_controller.rb', line 3

def activate
   = params[:login_url].blank? ? ErpTechSvcs::Config. : params[:login_url]
  if @user = User.load_from_activation_token(params[:activation_token])
    @user.activate!
    redirect_to , :notice => 'User was successfully activated.'
  else
    redirect_to , :notice => "Invalid activation token."
  end
end

#reset_passwordObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/erp_tech_svcs/user_controller.rb', line 31

def reset_password
  begin
     = params[:login].strip
    if user = (User.where('username = ? or email = ?', , )).first

      website = Website.find_by_host(request.host_with_port)
      if website
        user.add_instance_attribute(:website_id, website.id)
      end

      user.add_instance_attribute(:reset_password_url, (params[:reset_password_url] || '/erp_app/reset_password'))
      user.add_instance_attribute(:domain, params[:domain])
      user.deliver_reset_password_instructions!

      message = "Password has been reset. An email has been sent with further instructions to #{user.email}."
      success = true

    else
      message = "Invalid user name or email address."
      success = false
    end
    render :json => {:success => success, :message => message}
  rescue => ex
    Rails.logger.error ex.message
    Rails.logger.error ex.backtrace.join("\n")

    ExceptionNotifier.notify_exception(ex) if defined? ExceptionNotifier

    render :json => {:success => false, :message => 'Error sending email.'}
  end
end

#update_passwordObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/erp_tech_svcs/user_controller.rb', line 13

def update_password
  if user = User.authenticate(current_user.username, params[:old_password])
    user.password_confirmation = params[:password_confirmation]
    if user.change_password!(params[:password])
      success = true
    else
      #### validation failed ####
      message = user.errors.full_messages
      success = false
    end
  else
    message = "Invalid current password."
    success = false
  end

  request.xhr? ? (render :json => {:success => success, :message => message}) : (render :text => message)
end