From 12b30b7e861c510593c6a8bd4bae68c2126106db Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 26 Jun 2012 18:56:43 +0200 Subject: moved user and log class to models, verify prints logs --- example/http-srp.rb | 42 ++++++++++++++---------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) (limited to 'example/http-srp.rb') diff --git a/example/http-srp.rb b/example/http-srp.rb index c0c9360..4faa149 100644 --- a/example/http-srp.rb +++ b/example/http-srp.rb @@ -1,36 +1,11 @@ require 'sinatra' require 'pp' -class User - - def self.current - # p "getting #{@current ? @current.login : 'nil'}" - @current ||= User.new - end - - attr_accessor :login - attr_accessor :password - attr_accessor :active - - def signup!(params) - self.login = params.delete('login') - p "signing up as #{login}" - self.password = params.delete('password') - self.active = false - end - - def login!(params) - self.active = valid_login?(params[:login], params[:password]) - end - - def valid_login?(login, password) - (self.login == login) and (self.password == password) - end -end +require 'models/user' +require 'models/log' get '/' do @user = User.current - p "visiting / as #{@user.login}" erb :index end @@ -39,6 +14,8 @@ get '/signup' do end post '/signup' do + Log.clear + Log.log(:signup, params) @user = User.current @user.signup!(params) redirect '/' @@ -49,11 +26,20 @@ get '/login' do end post '/login' do + Log.log(:login, params) @user = User.current - @user.login!(params) + if @user.login!(params) + Log.log(:response, "Login succeeded") + else + Log.log(:response, "Login failed") + end redirect '/' end +get '/verify' do + erb :verify +end + helpers do def button_link(action, options = {}) action = action.to_s -- cgit v1.2.3