-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rb
110 lines (91 loc) · 1.82 KB
/
main.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
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
require 'sinatra'
require 'rubygems'
require 'pony'
require "sinatra/activerecord"
require_relative './helpers/validate'
helpers Valid
set :database, "sqlite3:///user.db"
class User < ActiveRecord::Base
end
configure do
enable :sessions
set :session_secret, 'secret'
end
post '/login' do
session[:foo] = params[:username], params[:password], params[:email]
@user = User.new(:name => params[:username], :password => params[:password], :email => params[:email])
if @user.save
redirect "/"
else
redirect '/hobby'
end
end
post '/sign' do
if params[:nameuser] == User.find(:all)
session[:foo]=params[:name], params[:password]
redirect "/"
else
redirect "/notaunt"
end
end
get '/notaunt' do
erb :error
end
post '/logout' do
session.clear
redirect '/'
end
get "/" do
@title='Main'
erb :main
end
get "/biography" do
@title='Bio'
erb :biography
end
get "/hobby" do
@title='hobby'
erb :hobby
end
get "/about" do
@title='about'
erb :about
end
before '/contact' do
@errors = []
end
get "/contact" do
@title='contact'
erb :contact
end
get "/success" do
erb :success
end
get "/reg" do
@title='Sign up'
erb :register
end
post '/contact' do
validate #method from Helpers with module Valid
unless @errors.any?
options = {
:to => params[:email],
:subject => "Message by #{params[:name]}",
:html_body => params[:message],
:via => :smtp,
:via_options => {
:address => 'smtp.gmail.com',
:port => 587,
:enable_starttls_auto => true,
:user_name => 'puts your email',
:password => 'password',
:authentication => :plain,
:domain => 'localhost'
}
}
Pony.mail(options)
redirect '/success'
else
erb :contact
end
end