Class: UserController
- Inherits:
-
ApplicationController
- Object
- ActionController::API
- ApplicationController
- UserController
- Defined in:
- app/controllers/user_controller.rb
Overview
this controller is used when registering a user
Instance Attribute Summary
Attributes inherited from ApplicationController
Instance Method Summary (collapse)
-
- (Object) create
this is the registration endpoint maybe too much logic here.
- - (Object) destroy
-
- (Object) index
TODO: make less sloppy (joins etc).
- - (Object) show
- - (Object) update
Instance Method Details
- (Object) create
this is the registration endpoint maybe too much logic here
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/user_controller.rb', line 20 def create Rails.logger.info(params) if params.has_key?(:password) && params.has_key?(:email) && params.has_key?(:first_name) && params.has_key?(:last_name) unless User.exists?(email: params[:email]) @user = User.new_user(params[:password], params[:email], params[:first_name], params[:last_name]) if @user != nil && @user.save render json: @user.as_json, status: :created return end else render json: {error: 'user exists'}, status: :bad_request end end render json: {error: 'insufficient params'}, status: :bad_request end |
- (Object) destroy
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/user_controller.rb', line 44 def destroy if params.has_key?(:id) if User.exists?('id' => params[:id]) User.find(params[:id]).destroy render json: {user_destroyed: params[:id]}, status: 200 return end render json: {user_not_exist: params[:id]}, status: 200 else render json: {error: 'insufficient params'}, status: :bad_request end end |
- (Object) index
TODO: make less sloppy (joins etc)
7 8 9 10 11 12 13 14 15 16 |
# File 'app/controllers/user_controller.rb', line 7 def index @admins = Admin.where('approved' => true) @user_ids = Array.new @admins.each do |a| @user_ids.push(a.user_id) end @users = User.where('approved' => true) .where.not('id' => @user_ids) render json: @users, status: 200 end |
- (Object) show
36 37 38 |
# File 'app/controllers/user_controller.rb', line 36 def show render json: {warning: 'not implemented'}, status: 200 end |
- (Object) update
40 41 42 |
# File 'app/controllers/user_controller.rb', line 40 def update render json: {warning: 'not implemented'}, status: 200 end |