forked from marshluca/slience
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
80 lines (67 loc) · 1.43 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
require "rubygems"
require "sinatra"
require "sinatra/base"
require "mongoid"
require "logger"
class App < Sinatra::Base
require './init'
require './models'
require './helpers'
error do
e = request.env['sinatra.error']
Kernel.puts e.backtrace.join("\n")
'Application error ... '
end
before do
p '-' * 100
p request.params.inspect
unless request.path =~ /sign/i
login_required
end
end
get '/' do
redirect '/feeds'
end
get '/signin' do
haml :signin
end
post '/signin' do
if @user = User.auth_emrms(params[:email], params[:password])
session[:user] = @user.id.to_s
redirect_to_stored
else
redirect '/signin'
end
end
get '/signup' do
haml :signup
end
post '/signup' do
@user = User.build_emrms(params[:user])
if @user && @user.valid?
session[:user] = @user.id.to_s
redirect '/'
else
redirect '/signup'
end
end
get '/signout' do
logout_user
redirect '/signin'
end
get '/feeds' do
@feeds = Feed.page(params[:page])
@title = 'All Syncronize List'
haml :feeds
end
get '/feeds/:kind' do
@feeds = Feed.kind(params[:kind]).page(params[:page])
@title = "Syncronize List on #{params[:kind]}"
haml :feeds
end
get '/:user/feeds' do
@feeds = Feed.from_user(params[:user]).page(params[:page])
@title = "Syncronize List from #{params[:user]}"
haml :feeds
end
end