-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwelcome.rb
54 lines (49 loc) · 1.57 KB
/
welcome.rb
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
require 'sinatra'
require 'sinatra/activerecord'
require 'sinatra/base'
require 'active_record'
require 'haml'
require 'pony'
dbconfig = YAML.load(File.read('config/database.yml'))
ENV['RACK_ENV'] ||= 'development'
ActiveRecord::Base.establish_connection dbconfig[ENV['RACK_ENV']]
class Contact < ActiveRecord::Base
validates_presence_of :nombre, :email, :message => "no puede estar vacio/ "
validates_uniqueness_of :email, :twitter, :message => "ya registrado/ "
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/ , :message => "no valido/ "
end
get '/' do
haml :index
end
get '/contact' do
haml :index
end
get '/registered_users' do
@user = Contact.all
haml :registered
end
post '/contact' do
mail_body = File.read("views/mail.html")
@info = Contact.create(:nombre => params[:nombre], :email => params[:email], :twitter => params[:twitter])
if @info.valid?
Pony.mail(
:to => @info.email,
:via => :smtp,
:via_options => {
:address => 'smtp.gmail.com',
:port => '587',
:enable_starttls_auto => true,
:user_name => ENV['MAIL_USER'],
:password => ENV['MAIL_PASSWORD'],
:authentication => :plain,
:domain => "crowdint.com"
},
:subject => "Reforestanding Colima!! Welcome #{@info.nombre}",
:html_body => mail_body,
:body => "Gracias por registrarte. Pronto te informaremos sobre los eventos. Saludos.")
haml :thank_you
else
@errors = true
haml :index
end
end