diff --git a/code/webapp/README.md b/code/webapp/README.md new file mode 100644 index 0000000..93f49c5 --- /dev/null +++ b/code/webapp/README.md @@ -0,0 +1,46 @@ +#Further configuration for mysql database: +##These dependencies must be installed on machine: + +sudo pip install Flask +sudo pip install Flask-Mail + +``` +CREATE DATABASE garbageday; + +CREATE TABLE users ( + id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, + email VARCHAR(100), + zone INT, +confirmed BOOLEAN NOT NULL DEFAULT 0); +``` + +------------------------------------------------------------------------- + +``` +DELIMITER $$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_createUser`( + IN p_email VARCHAR(255), + IN p_zone VARCHAR(255) +) +BEGIN + if ( select exists (select 1 from users where email = p_email) ) THEN + + select 'Email has already been used!'; + + ELSE + + insert into users + ( + email, + zone + ) + values + ( + p_email, + p_zone + ); + + END IF; +END$$ +DELIMITER ; +```` diff --git a/code/webapp/app.py b/code/webapp/app.py new file mode 100644 index 0000000..b70a9d0 --- /dev/null +++ b/code/webapp/app.py @@ -0,0 +1,67 @@ +from flask import Flask, render_template, request, json, redirect +from flask_mail import Message, Mail +from flask.ext.mysql import MySQL + +app = Flask(__name__) +#app.config['DEBUG'] = True + +ADMINS = ['email'] +app.config.update( + #EMAIL SETTINGS + MAIL_SERVER='smtp.gmail.com', + MAIL_PORT=465, + MAIL_USE_SSL=True, + MAIL_USERNAME = ADMINS[0], + MAIL_PASSWORD = 'password' + ) + +mail = Mail(app) +mysql = MySQL() + +# MySQL configurations +app.config['MYSQL_DATABASE_USER'] = 'root' +app.config['MYSQL_DATABASE_PASSWORD'] = 'password' +app.config['MYSQL_DATABASE_DB'] = 'garbageday' +app.config['MYSQL_DATABASE_HOST'] = 'localhost' +mysql.init_app(app) + +@app.route("/") +def main(): + return render_template('index.html') + +@app.route('/showSignUp') +def showSignUp(): + return render_template('signup.html') + +@app.route('/signUp', methods=['POST']) +def signUp(): + try: + # read the posted values from the UI + _address = request.form['inputAddress'] + _email = request.form['inputEmail'] + # validate the received values + if _address and _email: + conn = mysql.connect() + cursor = conn.cursor() + cursor.callproc('sp_createUser',(_email,_address)) + data = cursor.fetchall() + if len(data) is 0: + msg = Message("Garbage Alert Signup", sender=ADMINS[0], recipients=[_email]) + msg.html = 'Email Confirmation Test Complete' + mail.send(msg) + conn.commit() + return render_template('confirmation.html') + elif str(data[0]) == "(u'Email has already been used!',)": + return render_template("alreadyused.html") + else: + return json.dumps({'error1':str(data[0])}) + else: + return json.dumps({'html':'Enter the required fields'}) + except Exception as e: + return json.dumps({'error2':str(e)}) + finally: + cursor.close() + conn.close() + +if __name__ == "__main__": + app.run(host="0.0.0.0") diff --git a/code/webapp/static/images/kamloops.jpg b/code/webapp/static/images/kamloops.jpg new file mode 100644 index 0000000..dab5718 Binary files /dev/null and b/code/webapp/static/images/kamloops.jpg differ diff --git a/code/webapp/static/signup.css b/code/webapp/static/signup.css new file mode 100644 index 0000000..df401bc --- /dev/null +++ b/code/webapp/static/signup.css @@ -0,0 +1,33 @@ +body { + padding-top: 40px; + padding-bottom: 40px; +} +.form-signin { + max-width: 330px; + padding: 15px; + margin: 0 auto; +} +.form-signin .form-signin-heading, +.form-signin .checkbox { + margin-bottom: 10px; +} +.form-signin .checkbox { + font-weight: normal; +} +.form-signin .form-control { + position: relative; + height: auto; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + padding: 10px; + font-size: 16px; +} +.form-signin .form-control:focus { + z-index: 2; +} +.form-signin input[type="email"] { + margin-bottom: -1px; + border-bottom-right-radius: 0; + border-bottom-left-radius: 0; +} diff --git a/code/webapp/templates/alreadyused.html b/code/webapp/templates/alreadyused.html new file mode 100644 index 0000000..08064bd --- /dev/null +++ b/code/webapp/templates/alreadyused.html @@ -0,0 +1,33 @@ + + + + + G-Day + + + + + + + +
+
+

Kamloops G-Day

+
+ +
+

Email Already Registered

+

+

Go Back

+




+
+ +




+ + +
+ + + diff --git a/code/webapp/templates/confirmation.html b/code/webapp/templates/confirmation.html new file mode 100644 index 0000000..2af2df7 --- /dev/null +++ b/code/webapp/templates/confirmation.html @@ -0,0 +1,33 @@ + + + + + G-Day + + + + + + + +
+
+

G-Day Yo

+
+ +
+

Confirmation Email Sent

+

+

Home Page

+





+
+ +




+ + +
+ + + diff --git a/code/webapp/templates/index.html b/code/webapp/templates/index.html new file mode 100644 index 0000000..96b6713 --- /dev/null +++ b/code/webapp/templates/index.html @@ -0,0 +1,46 @@ + + + + + G-Day + + + + + + +
+
+ +

Kamloops G-Day

+
+ +
+

Garbage Day

+

+

Sign up today +





+
+ +
+
+

Welcome to this work in progress

+

Thanks for visiting :-)

+
+
+ + + +
+ + + diff --git a/code/webapp/templates/signup.html b/code/webapp/templates/signup.html new file mode 100644 index 0000000..a456b7c --- /dev/null +++ b/code/webapp/templates/signup.html @@ -0,0 +1,41 @@ + + + + G-Day + + + + + + + + +
+
+ +

Kamloops G-Day

+
+ +
+

Garbage Day

+ +
+ + + +
+ +