This repository has been archived by the owner on Dec 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomer.rb
103 lines (75 loc) · 3.56 KB
/
customer.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
before do
@db = SQLite3::Database.new './curry_house.sqlite'
end
get '/customer_info' do
redirect '/' if !session[:admin]
@submitted=false
erb :customer_info
end
get '/search_customer' do
redirect '/' if !session[:admin]
@submitted=true
@input = params[:input].strip
session[:current_customer] = @input
@name = @db.get_first_value('SELECT firstname FROM customer WHERE twitterAcc = ?',@input)
@customer_found_twitter [email protected]?
@[email protected]_first_value('SELECT surname FROM customer WHERE email = ?',@input)
@customer_found_email [email protected]?
@customer_found=@customer_found_twitter|| @customer_found_email
if @customer_found
if @customer_found_twitter
@twitter=@input
@[email protected]_first_value('SELECT email FROM customer WHERE twitterAcc = ?',@input)
@[email protected]_first_value('SELECT surname FROM customer WHERE twitterAcc = ?',@input)
@[email protected]_first_value('SELECT address FROM customer WHERE twitterAcc = ?',@input)
@[email protected]_first_value('SELECT city FROM customer WHERE twitterAcc = ?',@input)
@[email protected]_first_value('SELECT balance FROM customer WHERE twitterAcc = ?',@input)
[email protected]_first_value('SELECT cc FROM customer WHERE twitterAcc = ?',@input)
else
@[email protected]_first_value('SELECT twitterAcc FROM customer WHERE email = ?',@input)
@email=@input
@[email protected]_first_value('SELECT firstname FROM customer WHERE email = ?',@input)
@[email protected]_first_value('SELECT address FROM customer WHERE email = ?',@input)
@[email protected]_first_value('SELECT city FROM customer WHERE email = ?',@input)
@[email protected]_first_value('SELECT balance FROM customer WHERE email = ?',@input)
[email protected]_first_value('SELECT cc FROM customer WHERE email = ?',@input)
end
if !cc.nil? then
@cCard="YES"
else
@cCard="NO"
end
session[:current_customer]=@twitter
blacklisted = @db.get_first_value('SELECT blacklisted FROM customer WHERE twitterAcc = ?',session[:current_customer]) == 1
@button_text = blacklisted ? 'Unblacklist' : 'Blacklist'
admin_ok = [email protected]_first_value('SELECT email FROM administrators WHERE email = ?',@email).nil?
@button2 = admin_ok ? 'Unmake administrator' : 'Make administrator'
end
erb :customer_info
end
get '/adminButton' do
redirect '/' if !session[:admin]
# count = db.execute('SELECT Count(*) FROM administrators')
twitter_acc = session[:current_customer]
[email protected]_first_value('SELECT email FROM customer WHERE twitterAcc = ?',twitter_acc)
admin_ok = [email protected]_first_value('SELECT email FROM administrators WHERE email = ?',email).nil?
if admin_ok
@db.execute('DELETE FROM administrators where email = ?',email)
else
@db.execute('INSERT INTO administrators(email) VALUES(?)',[email])
end
redirect "/search_customer?input=#{twitter_acc}"
end
get '/blacklistButton' do
redirect '/' if !session[:admin]
twitter_acc = session[:current_customer]
blacklisted = @db.get_first_value('SELECT blacklisted FROM customer WHERE twitterAcc = ?',twitter_acc) == 1
if blacklisted
@db.execute('UPDATE customer SET blacklisted = 0 WHERE twitterAcc = ?', twitter_acc)
ch_twitter.update("@#{twitter_acc} You have been unbanned from our website! Sorry for any inconvenience caused.")
else
@db.execute('UPDATE customer SET blacklisted = 1 WHERE twitterAcc = ?', twitter_acc)
ch_twitter.update("@#{twitter_acc} We are sorry to inform you that your account has been banned from our website.")
end
redirect "/search_customer?input=#{twitter_acc}"
end