Class: Masq::AccountsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/masq/accounts_controller.rb

Instance Method Summary collapse

Instance Method Details

#activateObject



68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/masq/accounts_controller.rb', line 68

def activate
  return render_404 unless Masq::Engine.config.masq["send_activation_mail"]

  begin
    .find_and_activate!(params[:activation_code])
    redirect_to(, notice: t(:account_activated_login_now))
  rescue ArgumentError, ::ActivationCodeNotFound
    redirect_to(, alert: t(:couldnt_find_account_with_code_create_new_one))
  rescue ::AlreadyActivated
    redirect_to(, alert: t(:account_already_activated_please_login))
  end
end

#change_passwordObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/controllers/masq/accounts_controller.rb', line 81

def change_password
  return render_404 unless Masq::Engine.config.masq["can_change_password"]

  if .authenticate(., params[:old_password])
    if (params[:password] == params[:password_confirmation]) && !params[:password_confirmation].blank?
      .password_confirmation = params[:password_confirmation]
      .password = params[:password]
      if .save
        redirect_to((account: ), notice: t(:password_has_been_changed))
      else
        redirect_to(, alert: t(:sorry_password_couldnt_be_changed))
      end
    else
      @old_password = params[:old_password]
      redirect_to(, alert: t(:confirmation_of_new_password_invalid))
    end
  else
    redirect_to(, alert: t(:old_password_incorrect))
  end
end

#createObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/masq/accounts_controller.rb', line 29

def create
  cookies.delete(:auth_token)
  [:login] = [:email] if email_as_login?
   = .create_account!()
  if .succeeded?
    redirect_to(, notice: .send_activation_email? ?
      t(:thanks_for_signing_up_activation_link) :
      t(:thanks_for_signing_up))
  else
    @account = .
    render(action: "new")
  end
end

#destroyObject



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/masq/accounts_controller.rb', line 54

def destroy
  return render_404 unless Masq::Engine.config.masq["can_disable_account"]

  if .authenticated?(params[:confirmation_password])
    .disable!
    .forget_me
    cookies.delete(:auth_token)
    reset_session
    redirect_to(root_path, notice: t(:account_disabled))
  else
    redirect_to(, alert: t(:entered_password_is_wrong))
  end
end

#newObject



25
26
27
# File 'app/controllers/masq/accounts_controller.rb', line 25

def new
  @account = .new
end

#resend_activation_emailObject



102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/controllers/masq/accounts_controller.rb', line 102

def resend_activation_email
   = .find_by(login: params[:account])

  if  && !.active?
    AccountMailer.().deliver_now
    flash[:notice] = t(:activation_link_resent)
  else
    flash[:alert] = t(:account_already_activated_or_missing)
  end

  redirect_to()
end

#showObject

Raises:

  • (ActiveRecord::RecordNotFound)


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

def show
  @account =
    if params[:account].to_i.to_s == params[:account].to_s
      .find_by(id: params[:account], enabled: true)
    else
      .find_by(login: params[:account], enabled: true)
    end

  raise ActiveRecord::RecordNotFound if @account.nil?

  respond_to do |format|
    format.html do
      response.headers["X-XRDS-Location"] = identity_url(account: @account, format: :xrds, protocol: scheme)
    end
    format.xrds
  end
end

#updateObject



43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/masq/accounts_controller.rb', line 43

def update
  .delete(:email) if email_as_login?
  .delete(:login)

  if .update()
    redirect_to((account: ), notice: t(:profile_updated))
  else
    render(action: "edit")
  end
end