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
|
require 'sinatra/base'
require 'pony'
class ExampleSinatraApp < Sinatra::Base
get '/' do
<<-EOHTML
<form method="post" action="/signup">
<label for="Name">Name</label>
<input type="text" id="Name" name="user[name]">
<label for="Email">Email</label>
<input type="text" id="Email" name="user[email]">
<input type="submit" value="Sign up">
</form>
EOHTML
end
post '/signup' do
user = params[:user]
body = <<-EOTEXT
Hello #{user['name']}!
Copy and paste this URL into your browser to confirm your account!
http://www.example.com/confirm
This is the text part.
EOTEXT
html_body = <<-EOHTML
Hello #{user['name']}!
<a href="http://www.example.com/confirm">Click here to confirm your account!</a>
This is the HTML part.
EOHTML
Pony.mail(:from => 'admin@example.com',
:to => user['email'],
:subject => 'Account confirmation',
:body => body,
:html_body => html_body
)
'Thanks! Go check your email!'
end
get '/confirm' do
'Confirm your new account!'
end
end
|