Skip to content

Use identity check for comparison to a singleton #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions services/Auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def sign_in_with_oauth(self, provider_key, provider_name, firstname, lastname, e

user = cursor.fetchone()

if user != None:
if user is not None:
conn.close()
return json.dumps({
"uid": user["uid"],
Expand Down Expand Up @@ -244,7 +244,7 @@ def sign_up(self, firstname, lastname, email, password, confirmpassword, platfor
hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())

#Insert into the database
if platform == None:
if platform is None:
cursor.execute("INSERT INTO users(uid, firstname, lastname, email, password, profileimage, streak, bio) VALUES('" + str(uid) + "', '" + firstname + "', '" + lastname + "', '" + email + "', '" + hashed_password.decode('utf-8') + "', 'user/" + str(uid) + "/profile/profile.png', 0, '');")
else:
cursor.execute("INSERT INTO users(uid, firstname, lastname, email, password, profileimage, streak, bio, platform) VALUES('" + str(uid) + "', '" + firstname + "', '" + lastname + "', '" + email + "', '" + hashed_password.decode('utf-8') + "', 'user/" + str(uid) + "/profile/profile.png', 0, '', " + str(platform) + ");")
Expand Down Expand Up @@ -289,10 +289,10 @@ def sign_in(self, email, password):
existingUser = cursor.fetchone()


if existingUser != None:
if existingUser is not None:

#If the password is correct...
if existingUser["banned"] != True and bcrypt.checkpw(password.encode('utf-8'), existingUser["password"].encode('utf-8')):
if existingUser["banned"] is not True and bcrypt.checkpw(password.encode('utf-8'), existingUser["password"].encode('utf-8')):

#The user is authenticated; create and return a token
access_token = self.create_token( existingUser["uid"] )
Expand Down Expand Up @@ -332,7 +332,7 @@ def admin_sign_in(self, username, password):
existingUser = cursor.fetchone()


if existingUser != None:
if existingUser is not None:

#If the password is correct...
if bcrypt.checkpw(password.encode('utf-8'), existingUser["password"].encode('utf-8')):
Expand Down Expand Up @@ -601,7 +601,7 @@ def refresh_access(self, refresh_token):

conn.commit()
conn.close()
if user != None and user["banned"]:
if user is not None and user["banned"]:
return "ERROR-INVALID-REFRESH-TOKEN"

#Create a new token and return it
Expand Down
6 changes: 3 additions & 3 deletions services/EventLogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ def query(self, _type=None, min_time=None, max_time=None, conditions=[], admin_p
#Time constraint
time_constraint_str = ""

if min_time != None:
if min_time is not None:
time_constraint_str += " AND _timestamp >= TIMESTAMP('{}') ".format(min_time)

if max_time != None:
if max_time is not None:
time_constraint_str += " AND _timestamp <= TIMESTAMP('{}') ".format(max_time)


#Type constraint
type_str = ""

if _type != None:
if _type is not None:
type_str += " AND type='{}'".format(_type)

#Password check
Expand Down
50 changes: 25 additions & 25 deletions services/HighLow.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, host, username, password, database, high_low_id=None):
self.database = database
self.high_low_id = ""

if high_low_id != None:
if high_low_id is not None:
self.high_low_id = pymysql.escape_string( bleach.clean(high_low_id) )

conn = pymysql.connect(self.host, self.username, self.password, self.database, cursorclass=pymysql.cursors.DictCursor, charset='utf8mb4')
Expand Down Expand Up @@ -104,17 +104,17 @@ def create(self, uid, _date, high=None, low=None, high_image=None, low_image=Non
#Create a High/Low ID
self.high_low_id = str( uuid.uuid1() )

if high != None:
if high is not None:
self.high = pymysql.escape_string( self.sanitize_html(high) )


self.high = "{}".format(self.high)

if low != None:
if low is not None:
self.low = pymysql.escape_string( self.sanitize_html(low) )
self.low = "{}".format(self.low)

if high_image != None:
if high_image is not None:
fileStorage = FileStorage()

upload_result = json.loads( fileStorage.upload_to_high_images(high_image) )
Expand All @@ -126,7 +126,7 @@ def create(self, uid, _date, high=None, low=None, high_image=None, low_image=Non

self.high_image = "{}".format(upload_result["file"])

if low_image != None:
if low_image is not None:
fileStorage = FileStorage()

upload_result = json.loads( fileStorage.upload_to_low_images(low_image) )
Expand Down Expand Up @@ -231,12 +231,12 @@ def get_json(self, uid=None, supports_html=False):
conn = pymysql.connect(self.host, self.username, self.password, self.database, cursorclass=pymysql.cursors.DictCursor, charset='utf8mb4')
cursor = conn.cursor()

if uid != None:
if uid is not None:
cursor.execute( "SELECT * FROM likes WHERE uid='{}' AND highlowid='{}'".format(uid, self.high_low_id) )
if cursor.fetchone() != None:
if cursor.fetchone() is not None:
json_object["liked"] = True
cursor.execute("SELECT * FROM flags WHERE uid='{}' AND highlowid='{}'".format(uid, self.high_low_id))
if cursor.fetchone() != None:
if cursor.fetchone() is not None:
json_object["flagged"] = True

cursor.execute( """
Expand Down Expand Up @@ -317,7 +317,7 @@ def update_high(self, uid, text=None, image=None, isPrivate=False, supports_html
conn = pymysql.connect(self.host, self.username, self.password, self.database, cursorclass=pymysql.cursors.DictCursor, charset='utf8mb4')
cursor = conn.cursor()

if text != None:
if text is not None:
text = pymysql.escape_string( self.sanitize_html(text) )
self.high = text
text = "'{}'".format(text)
Expand All @@ -326,7 +326,7 @@ def update_high(self, uid, text=None, image=None, isPrivate=False, supports_html

filename = ""

if image != None:
if image is not None:

fileStorage = FileStorage()

Expand Down Expand Up @@ -361,7 +361,7 @@ def update_low(self, uid, text=None, image=None, isPrivate=False, supports_html=
conn = pymysql.connect(self.host, self.username, self.password, self.database, cursorclass=pymysql.cursors.DictCursor, charset='utf8mb4')
cursor = conn.cursor()

if text != None:
if text is not None:
text = pymysql.escape_string( self.sanitize_html(text) )
self.low = text
text = "'{}'".format(text)
Expand All @@ -370,7 +370,7 @@ def update_low(self, uid, text=None, image=None, isPrivate=False, supports_html=

filename = ""

if image != None:
if image is not None:

fileStorage = FileStorage()

Expand Down Expand Up @@ -437,15 +437,15 @@ def like(self, uid):
#Make sure this user hasn't "liked" before
cursor.execute("SELECT * FROM likes WHERE highlowid='{}' AND uid='{}';".format(self.high_low_id, uid))

if cursor.fetchone() != None:
if cursor.fetchone() is not None:
conn.commit()
conn.close()
return { 'error': 'already-liked' }

#Make sure the highlow does not belong to the user
cursor.execute("SELECT uid FROM highlows WHERE highlowid='{}' AND uid='{}';".format(self.high_low_id, uid))

if cursor.fetchone() != None:
if cursor.fetchone() is not None:
conn.commit()
conn.close()
return { 'error': 'not-allowed' }
Expand Down Expand Up @@ -487,7 +487,7 @@ def unlike(self, uid):

#Update the High/Low's total likes
cursor.execute( "SELECT * FROM likes WHERE highlowid='{}' AND uid='{}';".format(self.high_low_id, uid) )
if cursor.fetchone() != None:
if cursor.fetchone() is not None:
cursor.execute( "UPDATE highlows SET total_likes = total_likes - 1 WHERE highlowid='{}'".format(self.high_low_id) )

#Delete the entry, if it exists
Expand Down Expand Up @@ -674,7 +674,7 @@ def unflag(self, uid, supports_html=False):

cursor.execute("SELECT id FROM flags WHERE highlowid='{}' AND flagger='{}';".format(self.high_low_id, uid))

if cursor.fetchone() != None:
if cursor.fetchone() is not None:
cursor.execute( """
UPDATE users
SET times_flagged = IF(times_flagged > 0, times_flagged - 1, 0)
Expand Down Expand Up @@ -740,7 +740,7 @@ def get_highlows_for_user(self, uid, current_user, limit, page, sortby=None, sup

highlows = cursor.fetchall()

if sortby != None:
if sortby is not None:

options = {

Expand All @@ -750,7 +750,7 @@ def get_highlows_for_user(self, uid, current_user, limit, page, sortby=None, sup

}

if options[sortby][0] == None:
if options[sortby][0] is None:
highlows = sorted(highlows, reverse=options[sortby][1])
else:
highlows = sorted(highlows, key=lambda a: a[ options[sortby][0] ], reverse=options[sortby][1])
Expand Down Expand Up @@ -814,7 +814,7 @@ def get_today_for_user(self, uid, supports_html=False):

highlow = cursor.fetchone()

if highlow == None:
if highlow is None:
conn.commit()
conn.close()

Expand All @@ -839,10 +839,10 @@ def get_today_for_user(self, uid, supports_html=False):
highlow['low'] = self.html_to_plain_text(highlow['low'])

cursor.execute( "SELECT * FROM likes WHERE uid='{}' AND _date='{}';".format(uid, datestr) )
if cursor.fetchone() != None:
if cursor.fetchone() is not None:
highlow["liked"] = True
cursor.execute("SELECT * FROM flags WHERE uid='{}' AND _date='{}';".format(uid, datestr))
if cursor.fetchone() != None:
if cursor.fetchone() is not None:
highlow["flagged"] = True


Expand Down Expand Up @@ -889,7 +889,7 @@ def get_day_for_user(self, uid, date, viewer, supports_html=False):
highlow = cursor.fetchone()


if highlow == None:
if highlow is None:
conn.commit()
conn.close()

Expand All @@ -911,10 +911,10 @@ def get_day_for_user(self, uid, date, viewer, supports_html=False):
highlow['low'] = self.html_to_plain_text(highlow['low'])

cursor.execute( "SELECT * FROM likes WHERE uid='{}' AND highlowid='{}'".format(viewer, highlow["highlowid"]) )
if cursor.fetchone() != None:
if cursor.fetchone() is not None:
highlow["liked"] = True
cursor.execute("SELECT * FROM flags WHERE uid='{}' AND highlowid='{}'".format(viewer, highlow["highlowid"]))
if cursor.fetchone() != None:
if cursor.fetchone() is not None:
highlow["flagged"] = True


Expand Down Expand Up @@ -972,7 +972,7 @@ def delete_comment(self, uid, commentid):
conn.close()

def update_comment(self, uid, commentid, message):
if message == None or message == "":
if message is None or message == "":
return '{ "error": "no-message" }'


Expand Down
4 changes: 2 additions & 2 deletions services/User.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, uid, host, username, password, database):
conn.close()

#Make sure the user existed in the first place
if user == None:
if user is None:
raise ValueError("user-no-exist")

#Otherwise, get all the data and store it
Expand Down Expand Up @@ -412,7 +412,7 @@ def is_friend_with(self, uid):
conn.close()


if row == None:
if row is None:
return '{"isFriend": false}'

return '{"isFriend": true}'
Expand Down