Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Make_Tables/mysqlconnect.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import mysql.connector
import os
from dotenv import load_dotenv
from mysql.connector import Error as sqlerror

directory = os.getcwd()
envindex = directory.find('Make_Tables')
Expand All @@ -18,8 +19,9 @@
mycursor = mydb.cursor()
try:
mycursor.execute("use sac_data;")
except:
print("sac_data does not exists")
except sqlerror as err:
print("Database sac_data does not exists")
print()


def create_insert_statement(data): #pass the data in the JSON Format
Expand Down Expand Up @@ -51,3 +53,4 @@ def create_insert_statement(data): #pass the data in the JSON Format

stmt = "INSERT INTO "+clst+" VALUES"+vlst+";"
return stmt

28 changes: 26 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask import url_for,render_template,redirect,Flask,flash
from flask import url_for,render_template,redirect,Flask,flash, request, jsonify
from forms import LoginForm
from Make_Tables.mysqlconnect import mydb, mycursor, create_insert_statement #Imported the mysqlconnect.py file from Make_tables folder
from Make_Tables.mysqlconnect import mydb, mycursor, create_insert_statement, sqlerror #Imported the mysqlconnect.py file from Make_tables folder
#use sqlerror to track errors in mysql databases

app=Flask(__name__,static_url_path='/public')
app.config['SECRET_KEY']='c828b6ff21f45063fd7860e5c1b1d233'
Expand All @@ -20,5 +21,28 @@ def Login():
flash('Login Unsuccessful. Invalid Email/Password')
return render_template('login.html',title='Login | SAC Portal, IIT Mandi',form=form)

#Example https://host/leaveclub?userID='B19188'&clubID='C10001'
@app.route('/leaveclub', methods = ['POST'])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this comment. @vsvipul @Milind712000 what do you think about this?
Guard this function to check whether the user is logged in. If the user is logged in we don't need to store the userid.
If you are thinking about admin functionalities, we can have a different function for that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done, understood.
I will do this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will only take the clubID in the body, and take the userID from the session.

def leave_club():
data = {
"tablename" : "ClubMembers",
"userID" : request.args.get('userID'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use request body to transfer data, instead of query parameters,
this'll allow for direct HTML form calls

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, userstood for sure, will take care from next time in PRs
However, changing it and doing it as vipul suggested, to not take any parameter, isnted use the session value.

"clubID" : request.args.get('clubID')
}
stmt = "DELETE FROM ClubMembers WHERE userID='"+data["userID"]+"' and clubID='"+data["clubID"]+"';"
#print(stmt)
success = 0;msg=''
try:
mycursor.execute(stmt)
mydb.commit()
success=1
msg = "Deleted"
except sqlerror as err:
success=0
msg = str(err)

return(jsonify(success=success,msg=msg))


if __name__=="__main__":
app.run(debug=True)