Class: Iugu::ProfileController

Inherits:
SettingsController
  • Object
show all
Defined in:
app/controllers/iugu/profile_controller.rb

Instance Method Summary collapse

Instance Method Details

#become_userObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/iugu/profile_controller.rb', line 58

def become_user
  if current_user.guest
    @user = current_user
    if current_user.become_user(params[:user])
       @user
      
      redirect_to root_path, :notice => I18n.t("iugu.notices.congrats_for_becoming_user")
    else
      render 'iugu/settings/profile'
    end 
  else
    raise ActionController::RoutingError.new("Not found")
  end 
end

#cancel_destructionObject



36
37
38
39
40
41
# File 'app/controllers/iugu/profile_controller.rb', line 36

def cancel_destruction
  flash[:group] = :remove_user
  flash[:error] = I18n.t("iugu.user_destruction_undone")
  current_user.cancel_destruction
  redirect_to(profile_settings_path)
end

#destroyObject



25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/iugu/profile_controller.rb', line 25

def destroy
  if IuguSDK::enable_user_cancel
    (user = current_user).destroy
    flash[:group] = :remove_user
    flash[:error] = I18n.t("iugu.user_destruction_in") + user.destruction_job.run_at.to_s
    redirect_to(profile_settings_path)
  else
    raise ActionController::RoutingError.new("Not found")
  end
end

#destroy_socialObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/iugu/profile_controller.rb', line 43

def destroy_social
  begin
    if  = current_user.social_accounts.where(:id => params[:id]).first.unlink
      notice = I18n.t("iugu.social_unlinked")
    else
      notice = I18n.t("errors.messages.only_social_and_no_email")
    end
  rescue
    notice = I18n.t("errors.messages.not_found")
  end
  flash[:notice] = notice
  flash[:group] = :social
  redirect_to profile_settings_path
end

#indexObject



3
4
5
6
7
# File 'app/controllers/iugu/profile_controller.rb', line 3

def index
  @user = current_user
  @social_accounts = @user.social_accounts
  render 'iugu/settings/profile'
end

#renew_tokenObject



73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/iugu/profile_controller.rb', line 73

def renew_token
  if IuguSDK::enable_user_api
    current_user.token.refresh
    flash[:group] = :api
    flash[:notice] = I18n.t("iugu.notices.new_token_generated")
    redirect_to profile_settings_path
  else
    raise ActionController::RoutingError.new("Not found")
  end
end

#updateObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/iugu/profile_controller.rb', line 9

def update
  @user = current_user
  @social_accounts = @user.social_accounts
  if params[:form_group] == "password"
    flash.now[:group] = :password
  else
    flash.now[:group] = :profile_update
  end
  if @user.update_attributes(params[:user])
    I18n.locale = @user.locale 
     @user, :bypass => true if !params[:user][:password].blank?
    flash.now[:notice] = I18n.t('iugu.notices.user_update')
  end
  render 'iugu/settings/profile'
end