summaryrefslogtreecommitdiff
path: root/app/controllers/v1
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-03-31 11:40:44 +0200
committerAzul <azul@riseup.net>2016-03-31 11:40:44 +0200
commitbe5efb57dc9b282a31cf29c9eac27cb5a7e7ac2f (patch)
treece8bee7d2fa4007a1db9815e1af001fe44e329c1 /app/controllers/v1
parent14c9f2ab7cbf410bcd7fdd75b4a1c11417b30bd7 (diff)
parent48acca107b9bd7a59bacb1449b042eb753e63917 (diff)
Merge remote-tracking branch 'github/211' into develop
Diffstat (limited to 'app/controllers/v1')
-rw-r--r--app/controllers/v1/identities_controller.rb16
-rw-r--r--app/controllers/v1/users_controller.rb51
2 files changed, 59 insertions, 8 deletions
diff --git a/app/controllers/v1/identities_controller.rb b/app/controllers/v1/identities_controller.rb
new file mode 100644
index 0000000..4efd1f5
--- /dev/null
+++ b/app/controllers/v1/identities_controller.rb
@@ -0,0 +1,16 @@
+module V1
+ class IdentitiesController < ApiController
+ before_filter :token_authenticate
+ before_filter :require_monitor
+
+ def show
+ @identity = Identity.find_by_address(params[:id])
+ if @identity
+ respond_with @identity
+ else
+ render_not_found
+ end
+ end
+
+ end
+end
diff --git a/app/controllers/v1/users_controller.rb b/app/controllers/v1/users_controller.rb
index 2e840d9..8296eb0 100644
--- a/app/controllers/v1/users_controller.rb
+++ b/app/controllers/v1/users_controller.rb
@@ -2,10 +2,12 @@ module V1
class UsersController < ApiController
include ControllerExtension::FetchUser
+ # allow optional access to this controller using API auth tokens:
+ before_filter :token_authenticate
+
before_filter :fetch_user, :only => [:update, :destroy]
- before_filter :require_admin, :only => [:index]
+ before_filter :require_monitor, :only => [:index, :show]
before_filter :require_login, :only => [:index, :update, :destroy]
- before_filter :require_registration_allowed, only: :create
respond_to :json
@@ -19,9 +21,27 @@ module V1
end
end
+ def show
+ if params[:login]
+ @user = User.find_by_login(params[:login])
+ elsif params[:id]
+ @user = User.find(params[:id])
+ end
+ if @user
+ respond_with @user
+ else
+ not_found
+ end
+ end
+
def create
- @user = Account.create(params[:user])
- respond_with @user # return ID instead?
+ if current_user.is_monitor?
+ create_test_account
+ elsif APP_CONFIG[:allow_registration]
+ create_account
+ else
+ head :forbidden
+ end
end
def update
@@ -30,19 +50,34 @@ module V1
end
def destroy
- @user.account.destroy(params[:identities] == "destroy")
+ destroy_identity = current_user.is_monitor? || params[:identities] == "destroy"
+ @user.account.destroy(destroy_identity)
if @user == current_user
logout
end
render :json => {'success' => 'user deleted'}
end
- protected
+ private
+
+ # tester auth can only create test users.
+ def create_test_account
+ if User::is_test?(params[:user][:login])
+ @user = Account.create(params[:user])
+ respond_with @user
+ else
+ head :forbidden
+ end
+ end
- def require_registration_allowed
- unless APP_CONFIG[:allow_registration]
+ def create_account
+ if APP_CONFIG[:allow_registration]
+ @user = Account.create(params[:user])
+ respond_with @user # return ID instead?
+ else
head :forbidden
end
end
+
end
end