2014-11-06 15:25:27 +00:00
|
|
|
class UsersController < ApplicationController
|
2015-02-12 13:39:58 +00:00
|
|
|
load_and_authorize_resource
|
2015-09-14 18:26:16 +00:00
|
|
|
before_action :init, only: :show
|
2015-02-12 13:39:58 +00:00
|
|
|
|
2014-11-06 15:25:27 +00:00
|
|
|
def show
|
|
|
|
end
|
2014-11-06 17:30:53 +00:00
|
|
|
|
2015-03-20 01:21:56 +00:00
|
|
|
def update
|
2016-02-05 08:16:02 +00:00
|
|
|
if user_params.empty?
|
|
|
|
flash[:notice] = "Nothing happened."
|
|
|
|
redirect_to @user
|
2015-03-20 01:21:56 +00:00
|
|
|
else
|
2016-02-08 23:12:54 +00:00
|
|
|
if @user.update_attributes(user_params)
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
flash[:success] = "Successfully updated!"
|
|
|
|
redirect_to @user
|
|
|
|
end
|
|
|
|
format.js { head :ok }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
flash[:error] = "Update failed!"
|
|
|
|
@user.reload
|
|
|
|
render 'show'
|
|
|
|
end
|
|
|
|
format.js { head :bad_request }
|
|
|
|
end
|
|
|
|
end
|
2015-03-20 01:21:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-19 13:59:37 +00:00
|
|
|
def edit_dagschotel
|
|
|
|
@dagschotel = @user.dagschotel
|
2015-03-19 15:22:55 +00:00
|
|
|
|
2015-08-25 13:53:27 +00:00
|
|
|
@products = Product.for_sale
|
2015-03-19 15:22:55 +00:00
|
|
|
@categories = Product.categories
|
2015-03-19 13:59:37 +00:00
|
|
|
end
|
|
|
|
|
2015-09-14 18:26:16 +00:00
|
|
|
def quickpay
|
|
|
|
order = @user.orders.build
|
2015-09-18 13:53:45 +00:00
|
|
|
order.order_items.build(count: 1, product: @user.dagschotel)
|
2015-09-14 18:26:16 +00:00
|
|
|
if order.save
|
2015-10-29 10:54:02 +00:00
|
|
|
render json: { message: "Quick pay succeeded for #{@user.name}." }, status: :ok
|
2015-09-14 18:26:16 +00:00
|
|
|
else
|
2015-10-29 10:54:02 +00:00
|
|
|
head :unprocessable_entity
|
2015-09-14 18:26:16 +00:00
|
|
|
end
|
2014-12-10 13:18:56 +00:00
|
|
|
end
|
2015-03-19 13:59:37 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2015-03-20 01:21:56 +00:00
|
|
|
def user_params
|
2016-02-04 22:47:34 +00:00
|
|
|
params.fetch(:user, {}).permit(:avatar, :private, :dagschotel_id)
|
2015-03-20 01:21:56 +00:00
|
|
|
end
|
2015-09-01 15:40:18 +00:00
|
|
|
|
|
|
|
def init
|
2016-02-04 20:03:03 +00:00
|
|
|
@user ||= current_user
|
2015-09-01 15:40:18 +00:00
|
|
|
end
|
2014-11-06 15:25:27 +00:00
|
|
|
end
|