summaryrefslogtreecommitdiff
path: root/users/app/controllers
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-12-13 17:17:30 +0100
committerAzul <azul@leap.se>2012-12-13 17:17:30 +0100
commita77d5cf5fd2ff6cc335b586477d6d6e58f758591 (patch)
tree32640ef2457ecce3a08f704f5b5b0ac00a37f9d8 /users/app/controllers
parent961fe13b784e7f44e55f9cd0a106728c69354a0f (diff)
parent32db6e2ee3ae449f2fe0f947f9ac4aafde340a9d (diff)
Merge branch 'master' into develop
Conflicts: users/test/unit/user_test.rb
Diffstat (limited to 'users/app/controllers')
-rw-r--r--users/app/controllers/email_aliases_controller.rb39
-rw-r--r--users/app/controllers/users_controller.rb5
2 files changed, 43 insertions, 1 deletions
diff --git a/users/app/controllers/email_aliases_controller.rb b/users/app/controllers/email_aliases_controller.rb
new file mode 100644
index 0000000..751df85
--- /dev/null
+++ b/users/app/controllers/email_aliases_controller.rb
@@ -0,0 +1,39 @@
+class EmailAliasesController < ApplicationController
+
+ before_filter :fetch_user
+
+ 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
+ redirect_to edit_user_path(@user, :anchor => :email)
+ end
+
+ protected
+
+ def fetch_user
+ @user = User.find_by_param(params[:user_id])
+ access_denied unless admin? or (@user == current_user)
+ end
+end
diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb
index 4921a4a..811e8e5 100644
--- a/users/app/controllers/users_controller.rb
+++ b/users/app/controllers/users_controller.rb
@@ -30,8 +30,11 @@ class UsersController < ApplicationController
end
def update
- if @user.update_attributes(params[:user])
+ @user.attributes = params[:user]
+ 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)
end