This repository was archived by the owner on Apr 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcubeba.rb
More file actions
121 lines (96 loc) · 2.6 KB
/
Copy pathcubeba.rb
File metadata and controls
121 lines (96 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
require "rubygems"
require "bundler/setup"
# require your gems as usual
require 'sinatra'
require 'haml'
require 'rack'
require 'pony'
#set :environment, :production
#set :port, 80
helpers do
def protected!
unless authorized?
response['WWW-Authenticate'] = %(Basic realm="Restricted Area")
throw(:halt, [401, "Not authorized\n"])
end
end
def authorized?
@auth ||= Rack::Auth::Basic::Request.new(request.env)
@auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ['admin', 'sergiopaolo']
end
end
get '/' do
haml :index
end
get '/food' do
haml :food
end
get '/drink' do
haml :drink
end
get '/dance' do
haml :dance
end
get '/news' do
haml :news
end
get '/contatti' do
haml :contatti
end
get '/chi_siamo' do
haml :chi_siamo
end
get '/galleria' do
haml :galleria
end
get '/newsletter' do
haml :newsletter
end
get '/privacy' do
haml :privacy
end
post '/newsletter' do
name = params[:firstname]
surname = params[:surname]
town = params[:town]
email = params[:email]
age = params[:age]
pr = params[:privacy]
if pr == 'on'
@privacy = 'Dati inviati con successo'
Pony.mail(:to => 'info@cubeba.it', :subject => '[cubeba] Nuova iscrizione utente',
:body => "Nome: #{name}\n Cognome: #{surname}\n Eta': #{age}\n Paese: #{town}\n Email: #{email}\n", :via => :smtp, :via_options => {
:address => 'smtp.gmail.com',
:port => '587',
:enable_starttls_auto => true,
:user_name => 'cubebapress',
:password => 'cubita83',
:authentication => :plain, # :plain, :login, :cram_md5, no auth by default
:domain => "localhost.localdomain" # the HELO domain provided by the client to the server
})
else
@privacy = 'Dati non inviati, consenso al trattamento dei dati non selezionato'
end
haml :newsletter
end
get '/admin' do
protected!
@title = params[:title]
haml :admin
end
post '/admin' do
protected!
c = params[:content]
t = params[:title]
if t.empty?
"Non hai inserito il titolo (o data) della news! <br> <a href='/admin'>Torna alle news</a>"
else
body c
Dir.mkdir(File.join("public", "news", t)) if !File.directory?(File.join("public", "news", t))
File.open(File.join("public", "news", t, "text.html"), "w") { |f| f.write c }
"Testo news creato. Ricordati di caricare il flyer (nome file: flyer.jpg, dimensione: 150 x 210 px) via ftp nella cartella 'news/" + t + "' <br> <a href='/admin'>Torna alle news</a>"
end
end
post '/*.html' do |filename|
send_file 'public/galleria/' + filename + '/_ajax.html'
end