📄 customer_controller.rb
字号:
class CustomerController < ApplicationController helper :edition, :work, :composer before_filter :authorize, :except => ["signup","login"] before_filter :new_customer, :only => ["signup"] def authorize return true if @c report_error("Unauthorized access; password required") end def new_customer if Customer.find_by_nick(params[:customer][:nick]) report_error("That name is already in use. Please choose another.") end end def signup c = Customer.new(params[:customer]) c.password = Digest::SHA1.hexdigest(c.password) c.save @session['customer'] = c.id redirect_to :controller => "main", :action => "welcome" end def login pw,nick = params[:customer].values_at(*%w{password nick}) c = Customer.find_by_nick(nick) if c && Digest::SHA1.hexdigest(pw) == c.password @session['customer'] = c.id redirect_to :controller => "main", :action => "welcome" else report_error("Invalid login") end end def logout @session['customer'] = nil redirect_to :controller => "main", :action => "welcome" end def add_to_cart e = Edition.find(params[:id]) order = Order.create(:customer => @c, :edition => e) redirect_to :action => "view_cart" end def view_cart end def check_out @c.check_out endend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -