-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd_burns_app.rb
143 lines (122 loc) · 2.95 KB
/
d_burns_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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
require 'sinatra'
require 'tilt'
require 'erubis'
require_relative 'db_tools'
helpers do
def interpert_depression(score)
score = score.to_i
case score
when (0..4) then 'No Depression'
when (5..10) then 'Boderline Depression'
when (11..20) then 'Mild Depression'
when (21..30) then 'Moderate Depression'
when (31..45) then 'Severe Depression'
else 'Something went wrong.'
end
end
def interpert_anxiety(score)
score = score.to_i
case score
when (0..4) then 'No Anxiety'
when (5..10) then 'Boderline Anxiety'
when (11..20) then 'Mild Anxiety'
when (21..30) then 'Moderate Anxiety'
when (31..50) then 'Severe Anxiety'
when (51..99) then 'Extreme Anxiety'
else 'Something went wrong.'
end
end
end
configure do
enable :sessions
set :session_secret, "e5a44ff4292412d123b548648b"
end
before do
@connect = PgInterface.new
@message = session.delete('msg')
@user_id_num = session['user_id_num']
@username = session['username']
end
get '/signup' do
erb :sign_up
end
get '/signin' do
erb :sign_in
end
get '/delete/account' do
erb :confirm_delete
end
post '/delete/account' do
@connect.delete_user(@user_id_num)
session.delete('user_id_num')
session.delete('username')
redirect '/home'
end
post '/signin' do
@connect.sign_in(params['email'], params['password'])
if !!@connect.user_id_num
session['user_id_num'] = @connect.user_id_num
session['username'] = params['email']
redirect '/home'
else
session['msg'] = 'Invalid Email or Password'
redirect '/signin'
end
end
get '/signout' do
session.delete('user_id_num')
session.delete('username')
redirect '/home'
end
post '/signup' do
@user_mail = params['email']
@password = params['password']
@connect.add_user(@user_mail, @password)
if @connect.message
session['msg'] = @connect.message.dup
@connect.message = nil
redirect '/signup'
else
redirect '/home'
end
end
get '/' do
redirect '/home'
erb :home
end
get '/home' do
erb :home
end
get '/depression/new' do
erb :depression
end
get '/anxiety/new' do
erb :anxiety
end
post '/anxiety/new' do
@score = params.values.map(&:to_i).sum
@connect.add_anxiety_score(@user_id_num, @score)
redirect '/home'
end
post '/depression/new' do
@score = params.values.map(&:to_i).sum
if params['Do you have a plan for harming yoursel'] != '0' ||
params['Would you like to end your life?'] != '0' ||
params['Do you have any suicidal thoughts?'] != '0'
session['msg'] =
'Contact <a href="https://suicidepreventionlifeline.org/" target="_blank"> the suicide prevention lifeline for help! </a>'
end
@connect.add_depression_score(@user_id_num, @score)
redirect '/home'
end
get '/depression/reports' do
@scores = @connect.depression_scores(@user_id_num)
erb :depression_report
end
get '/anxiety/reports' do
@scores = @connect.anxieties_scores(@user_id_num)
erb :anxiety_report
end
after do
@connect.close
end