-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
123 lines (99 loc) · 2.53 KB
/
app.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
111
112
113
114
115
116
117
118
119
120
121
122
123
require 'rubygems'
require 'sinatra'
require 'dm-core'
require 'dm-migrations'
require 'dm-postgres-adapter'
require 'dm-validations'
require 'dm-timestamps'
require 'digest/sha2'
DataMapper.setup(:default, ENV['DATABASE_URL'])
# DataMapper.setup(:default, 'sqlite://local.db')
class User
include DataMapper::Resource
property :id, Serial # An auto-increment integer key
property :username, String, :required => true #, :format => /[a-zA-Z0-9]*/, :length => 6..20
property :firstname, String, :default => "", :format => /[a-zA-Z]*/, :length => 0..20
property :lastname, String, :default => "", :format => /[a-zA-Z]*/, :length => 0..20
property :link, String, :default => "", :format => :url , :length => 0..512
property :about, Text, :default => ""
property :email, String, :required => true, :format => :email_address, :length => 0..256
property :password, String, :required => true, :length => 6..20
property :confirmed, Boolean, :default => false
property :role, String, :default => 'member'
property :created_at, DateTime
property :created_on, Date
property :updated_at, DateTime
property :updated_on, Date
# thanks solnic!
validates_uniqueness_of :username, :email
end
DataMapper.finalize
DataMapper.auto_upgrade!
configure do
set :sessions, true
end
helpers do
def hashit(pass)
salt = "some amazingly long and salty bit of stringage"
Digest::SHA256.digest(pass+salt)
end
end
# display the index page
get '/' do
erb :index
end
get '/members' do
erb :members
end
get '/members/:name' do
@name = params[:name]
erb :member
end
get '/events' do
erb :events
end
get '/sponsor' do
erb :sponsor
end
get '/contact' do
erb :contact
end
get '/signup' do
erb :signup
end
post '/signup' do
# create user
user = User.new(:username => params[:username],
:email => params[:email],
:password => hashit(params[:password]),
:created_at => Time.now)
if user.save
# my_account is valid and has been saved
redirect '/signup#thanks'
else
user.errors.each do |e|
puts e
end
# session[:regErr] = user.errors
redirect '/signup#fail'
end
end
# used for monitoring unicorn status
# ( monitor1 is for nginx...)
get '/monitor2.html' do
erb :monitor2
end
# trap those nasty errors
not_found do
'This is nowhere to be found'
end
error 403 do
'Access forbidden'
end
error 500 do
'Boom'
session[:regErr]
end
error do
'wtf'
end