2016-03-08 15:53:50 +01:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: users
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
# remember_created_at :datetime
|
|
|
|
# admin :boolean default(FALSE)
|
|
|
|
# dagschotel_id :integer
|
|
|
|
# avatar_file_name :string
|
|
|
|
# avatar_content_type :string
|
|
|
|
# avatar_file_size :integer
|
|
|
|
# avatar_updated_at :datetime
|
|
|
|
# orders_count :integer default(0)
|
|
|
|
# koelkast :boolean default(FALSE)
|
|
|
|
# name :string
|
|
|
|
# private :boolean default(FALSE)
|
|
|
|
# frecency :integer default(0), not null
|
|
|
|
# quickpay_hidden :boolean
|
|
|
|
#
|
|
|
|
|
2014-11-06 16:25:27 +01:00
|
|
|
class UsersController < ApplicationController
|
2019-04-20 13:56:04 +02:00
|
|
|
load_and_authorize_resource except: :show
|
2015-09-14 20:26:16 +02:00
|
|
|
before_action :init, only: :show
|
2015-02-12 14:39:58 +01:00
|
|
|
|
2014-11-06 16:25:27 +01:00
|
|
|
def show
|
2019-04-08 16:41:19 +02:00
|
|
|
respond_to do |format|
|
|
|
|
format.json { render json: @user }
|
|
|
|
format.html {}
|
|
|
|
end
|
2014-11-06 16:25:27 +01:00
|
|
|
end
|
2014-11-06 18:30:53 +01:00
|
|
|
|
2015-03-20 02:21:56 +01:00
|
|
|
def update
|
2016-02-05 09:16:02 +01:00
|
|
|
if user_params.empty?
|
|
|
|
flash[:notice] = "Nothing happened."
|
|
|
|
redirect_to @user
|
2015-03-20 02:21:56 +01:00
|
|
|
else
|
2016-02-09 00:12:54 +01: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 02:21:56 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-19 14:59:37 +01:00
|
|
|
def edit_dagschotel
|
|
|
|
@dagschotel = @user.dagschotel
|
2015-03-19 16:22:55 +01:00
|
|
|
|
2015-08-25 15:53:27 +02:00
|
|
|
@products = Product.for_sale
|
2015-03-19 16:22:55 +01:00
|
|
|
@categories = Product.categories
|
2015-03-19 14:59:37 +01:00
|
|
|
end
|
|
|
|
|
2015-09-14 20:26:16 +02:00
|
|
|
def quickpay
|
2016-03-04 14:14:56 +01:00
|
|
|
authorize! :create, @user.orders.build
|
2015-09-14 20:26:16 +02:00
|
|
|
order = @user.orders.build
|
2015-09-18 15:53:45 +02:00
|
|
|
order.order_items.build(count: 1, product: @user.dagschotel)
|
2015-09-14 20:26:16 +02:00
|
|
|
if order.save
|
2016-03-03 22:20:56 +01:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to(@user) }
|
|
|
|
format.json { render json: { message: "Quick pay succeeded for #{@user.name}." }, status: :ok }
|
|
|
|
end
|
2015-09-14 20:26:16 +02:00
|
|
|
else
|
2015-10-29 11:54:02 +01:00
|
|
|
head :unprocessable_entity
|
2015-09-14 20:26:16 +02:00
|
|
|
end
|
2014-12-10 14:18:56 +01:00
|
|
|
end
|
2015-03-19 14:59:37 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-03-03 22:20:56 +01:00
|
|
|
def user_params
|
2016-03-04 22:45:36 +01:00
|
|
|
params.fetch(:user, {}).permit(:avatar, :private, :dagschotel_id, :quickpay_hidden)
|
2016-03-03 22:20:56 +01:00
|
|
|
end
|
2015-09-01 17:40:18 +02:00
|
|
|
|
2016-03-03 22:20:56 +01:00
|
|
|
def init
|
2019-04-08 16:41:19 +02:00
|
|
|
@user ||= current_user || user_token || User.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_token
|
|
|
|
@user_token ||= authenticate_with_http_token do |token, options|
|
|
|
|
User.find_by userkey: token
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset_key
|
|
|
|
@user.generate_key!
|
|
|
|
redirect_to @user
|
2016-03-03 22:20:56 +01:00
|
|
|
end
|
2014-11-06 16:25:27 +01:00
|
|
|
end
|