try exact match when substring search failed due to too many results
[opensuse:software-o-o.git] / app / controllers / order_controller.rb
1 class OrderController < ApplicationController
2
3   before_filter :require_auth, :except => [:new, :save, :thanks]
4
5   def new
6     @order = Order.new params[:order]
7     render :template => 'order/pause'
8   end
9
10   def save
11     @order = Order.new params[:order]
12     if @order.save
13       Promomailer.deliver_promo_order @order
14       redirect_to "/order/thanks"
15     else
16       flash[:save_errors] = @order.errors.full_messages
17       redirect_to :action => "new", :order => @order
18     end
19   end
20
21   def thanks
22   end
23
24   # admin stuff
25   def require_auth
26     auth = request.env['HTTP_AUTHORIZATION'].to_s.split
27
28     if auth and auth[0] == "Basic"
29       login, pw = Base64.decode64(auth[1]).split(':')[0..1]
30       pw ||= ""
31       # TODO: fix this when we enable the online ordering again
32       if login == "admin" and pw == "secret" and false
33         @user = session[:admin_user]
34         return true
35       end
36     end
37
38     response.headers["WWW-Authenticate"] = 'basic realm="software.opensuse.org admin login"'
39     render :text => "authentication required", :status => 401
40     return false
41   end
42   private :require_auth
43
44   def admin_index
45     @orders = Order.find :all, :conditions => "isnull(processed_by)"
46   end
47
48   def change_name
49     session[:admin_user] = params[:name]
50     redirect_to :action => :admin_index
51   end
52
53   def logout
54     session[:admin_user] = nil
55     redirect_to :action => :admin_index
56   end
57
58   def process_order
59     @order = Order.find params[:id]
60     @order.processed_at = Time.now
61     @order.processed_by = session[:admin_user]
62
63     @order.save
64     
65     render :partial => 'order', :object => @order
66   end
67 end