summaryrefslogtreecommitdiff
path: root/users/app
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-11-23 12:11:11 +0100
committerAzul <azul@leap.se>2012-11-23 15:09:53 +0100
commitee3c9146e4bbe93ec1f00ee45386a82ec4363c4d (patch)
treeec673f97f22c13c19c1f9034dfe88646525bdeae /users/app
parent716dc248e940be8bd323a9d92f98785737fc99a0 (diff)
identify user by id so rerendering the form does not use new invalid login
Diffstat (limited to 'users/app')
-rw-r--r--users/app/controllers/users_controller.rb15
-rw-r--r--users/app/models/user.rb8
2 files changed, 13 insertions, 10 deletions
diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb
index ecab53b..3913d0d 100644
--- a/users/app/controllers/users_controller.rb
+++ b/users/app/controllers/users_controller.rb
@@ -1,6 +1,8 @@
class UsersController < ApplicationController
- skip_before_filter :verify_authenticity_token
+ skip_before_filter :verify_authenticity_token, :only => [:create]
+
+ before_filter :fetch_user, :only => [:edit, :update]
respond_to :json, :html
@@ -17,12 +19,17 @@ class UsersController < ApplicationController
end
def edit
- @user = current_user
end
def update
- @user = current_user
- @user.update(params[:user])
+ @user.update_attributes(params[:user])
respond_with(@user, :location => edit_user_path(@user))
end
+
+ protected
+
+ def fetch_user
+ @user = User.find_by_param(params[:id])
+ access_denied unless @user == current_user
+ end
end
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index 507eda5..624754b 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -29,9 +29,7 @@ class User < CouchRest::Model::Base
end
class << self
- def find_by_param(login)
- return find_by_login(login) || raise(RECORD_NOT_FOUND)
- end
+ alias_method :find_by_param, :find
# valid set of attributes for testing
def valid_attributes_hash
@@ -42,9 +40,7 @@ class User < CouchRest::Model::Base
end
- def to_param
- self.login
- end
+ alias_method :to_param, :id
def to_json(options={})
{