diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-03-05 22:38:44 -0500 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-03-05 22:38:44 -0500 |
commit | c6471297f0a871ba1062f1285790d39e5471b966 (patch) | |
tree | 8b5cacdb422e67f5b18e481234d5246f65bcd72e | |
parent | a685379aa599bac6a96f657088c8df3cbcec3d22 (diff) |
users_controller: check permissions for doing things
-rw-r--r-- | app/controllers/users_controller.rb | 22 | ||||
-rw-r--r-- | app/views/application/permission_denied.html.erb | 1 | ||||
-rw-r--r-- | app/views/users/already_signed_in.html.erb | 1 |
3 files changed, 23 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) diff --git a/app/views/application/permission_denied.html.erb b/app/views/application/permission_denied.html.erb new file mode 100644 index 0000000..1ef883c --- /dev/null +++ b/app/views/application/permission_denied.html.erb @@ -0,0 +1 @@ +<h1>Permission denied</h1> diff --git a/app/views/users/already_signed_in.html.erb b/app/views/users/already_signed_in.html.erb new file mode 100644 index 0000000..04b4248 --- /dev/null +++ b/app/views/users/already_signed_in.html.erb @@ -0,0 +1 @@ +<h1>You are currently signed in</h1> |