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 pathSignUp.rb
72 lines (51 loc) · 1.95 KB
/
SignUp.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
require 'erb'
require 'sinatra'
require 'sqlite3'
require 'twitter'
include ERB::Util
before do
@db = SQLite3::Database.new('curry_house.sqlite')
end
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
get '/sign_up' do
if session[:logged_in]
redirect '/'
end
@submitted = false
erb :access
end
post '/form_handler' do
@submitted = true
@firstname = params[:firstname].strip
@surname = params[:surname].strip
@email = params[:email].strip
@city = params[:city].strip
@address = params[:address].strip
@twitter=params[:twitter].strip
@password = params[:password].strip
@confirm_password = params[:confirm_password].strip
@firstname_ok [email protected]? && @firstname != ""
@surname_ok = [email protected]? && @surname != ""
@address_ok = [email protected]? && @address != ""
@email_ok = [email protected]? && @email =~ VALID_EMAIL_REGEX
@[email protected]('SELECT * FROM customer WHERE email = ?LIMIT 1 ',[@email])
@different_emails_ok=@check_emails[0].nil? || @check_emails[0]==""
exists_ok=true
begin
exists= ch_twitter.user(@twitter)
rescue Twitter::Error=> err
exists_ok=false
end
@twitter_ok [email protected]? && exists_ok
@[email protected]('SELECT * FROM customer WHERE twitterAcc = ?LIMIT 1 ',[@twitter])
@different_twitter_ok=@check_twitter[0].nil? || @check_twitter[0]==""
@password_ok = [email protected]? && @password !="" && @password.length>=6
@confirm_password_ok = @confirm_password==@password
@all_ok = @firstname_ok && @surname_ok &&@address_ok && @email_ok&& @password_ok&& @confirm_password_ok &&@different_emails_ok&&@twitter_ok&&@different_twitter_ok
if @submitted && @all_ok
ch_twitter.follow(@twitter)
Stats.increment 'registrations',@city
@db.execute('INSERT INTO customer(firstname, surname, email,twitterAcc, password, city,address) VALUES(?, ?, ?, ?,?,?,?)', [@firstname, @surname, @email,@twitter, @password,@city, @address ])
end
erb :access
end