summaryrefslogtreecommitdiff
path: root/users/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'users/app/controllers')
-rw-r--r--users/app/controllers/email_aliases_controller.rb25
-rw-r--r--users/app/controllers/users_controller.rb16
2 files changed, 16 insertions, 25 deletions
diff --git a/users/app/controllers/email_aliases_controller.rb b/users/app/controllers/email_aliases_controller.rb
index 751df85..3b0d5ac 100644
--- a/users/app/controllers/email_aliases_controller.rb
+++ b/users/app/controllers/email_aliases_controller.rb
@@ -4,29 +4,10 @@ class EmailAliasesController < ApplicationController
respond_to :html
- # get a list of email aliases for the given user?
- def index
- @aliases = @user.email_aliases
- respond_with @aliases
- end
-
- def create
- @alias = @user.add_email_alias(params[:email_alias])
- flash[:notice] = t(:email_alias_created_successfully) unless @alias.errors
- respond_with @alias, :location => edit_user_path(@user, :anchor => :email)
- end
-
- def update
- @alias = @user.get_email_alias(params[:id])
- @alias.set_email(params[:email_alias])
- flash[:notice] = t(:email_alias_updated_successfully) unless @alias.errors
- respond_with @alias, :location => edit_user_path(@user, :anchor => :email)
- end
-
def destroy
- @alias = @user.get_email_alias(params[:id])
- flash[:notice] = t(:email_alias_destroyed_successfully)
- @alias.destroy
+ @alias = @user.email_aliases.delete(params[:id])
+ @user.save
+ flash[:notice] = t(:email_alias_destroyed_successfully, :alias => @alias)
redirect_to edit_user_path(@user, :anchor => :email)
end
diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb
index 811e8e5..3d71c1a 100644
--- a/users/app/controllers/users_controller.rb
+++ b/users/app/controllers/users_controller.rb
@@ -3,6 +3,7 @@ class UsersController < ApplicationController
skip_before_filter :verify_authenticity_token, :only => [:create]
before_filter :fetch_user, :only => [:edit, :update, :destroy]
+ before_filter :set_anchor, :only => [:edit, :update]
before_filter :authorize_admin, :only => [:index]
respond_to :json, :html
@@ -27,16 +28,16 @@ class UsersController < ApplicationController
end
def edit
+ @email_alias = LocalEmail.new
end
def update
@user.attributes = params[:user]
+ @email_alias = @user.email_aliases.last
if @user.changed? and @user.save
flash[:notice] = t(:user_updated_successfully)
- else
- flash[:error] = @user.errors.full_messages
end
- respond_with @user, :location => edit_user_path(@user)
+ respond_with @user, :location => edit_user_path(@user, :anchor => :email)
end
def destroy
@@ -50,4 +51,13 @@ class UsersController < ApplicationController
@user = User.find_by_param(params[:id])
access_denied unless admin? or (@user == current_user)
end
+
+ def set_anchor
+ @anchor = email_settings? ? :email : :account
+ end
+
+ def email_settings?
+ params[:user] &&
+ params[:user].keys.detect{|key| key.index('email')}
+ end
end