summaryrefslogtreecommitdiff
path: root/users/app/controllers/email_settings_controller.rb
blob: 0261b47451dfd68046a714b74f5624c63da71598 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class EmailSettingsController < UsersBaseController

  before_filter :authorize
  before_filter :fetch_user

  def edit
    @email_alias = LocalEmail.new
  end

  def update
    @user.attributes = params[:user]
    if @user.changed?
      if @user.save
        flash[:notice] = t(:changes_saved)
        redirect
      else
        if @user.email_aliases.last && !@user.email_aliases.last.valid?
          # display bad alias in text field:
          @email_alias = @user.email_aliases.pop
        end
        render 'email_settings/edit'
      end
    else
      redirect
    end
  end

  private

  def redirect
    redirect_to edit_user_email_settings_url(@user)
  end

end