summaryrefslogtreecommitdiff
path: root/app/controllers/users_controller.rb
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2014-03-05 22:38:44 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2014-03-05 22:38:44 -0500
commitc6471297f0a871ba1062f1285790d39e5471b966 (patch)
tree8b5cacdb422e67f5b18e481234d5246f65bcd72e /app/controllers/users_controller.rb
parenta685379aa599bac6a96f657088c8df3cbcec3d22 (diff)
users_controller: check permissions for doing things
Diffstat (limited to 'app/controllers/users_controller.rb')
-rw-r--r--app/controllers/users_controller.rb22
1 files changed, 21 insertions, 1 deletions
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 284892b..907958b 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1,5 +1,7 @@
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update, :destroy]
+ before_action :perms_edit, only: [:edit, :update, :destroy]
+ before_action :perms_create, only: [:new, :create]
# GET /users
# GET /users.json
@@ -33,7 +35,7 @@ class UsersController < ApplicationController
format.html { redirect_to root_path, notice: 'User was successfully created.' }
format.json { render action: 'show', status: :created, location: @user }
else
- format.html { render action: 'new' }
+ format.html { render action: 'new', status: :unprocessable_entity }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
@@ -69,6 +71,24 @@ class UsersController < ApplicationController
@user = User.find(params[:id])
end
+ def perms_edit
+ unless (current_user == @user) or (signed_in? and current_user.in_group? :admin)
+ respond_to do |format|
+ format.html { render action: 'permission_denied', status: :forbidden }
+ format.json { render json: "Permission denied", status: :forbidden }
+ end
+ end
+ end
+
+ def perms_create
+ if signed_in?
+ respond_to do |format|
+ format.html { render action: 'already_signed_in', status: :unprocessable_entity }
+ format.json { render json: "Already signed in", status: :unprocessable_entity }
+ end
+ end
+ end
+
# Never trust parameters from the scary internet, only allow the white list through.
def user_params
params.require(:user).permit(:name, :email, :user_name, :password, :password_confirmation)