self.cursor.execute("SELECT COUNT(*) AS `count` FROM auth_profile WHERE email = %s ; ",(email,))
result_profile=self.cursor.fetchone()
self.cursor.execute("SELECT COUNT(*) AS `count` FROM auth_profile WHERE username = %s ; ",(username,))
result_username=self.cursor.fetchone()
self.cursor.execute(f"SELECT COUNT(*) AS `count` FROM auth_profile_verification INNER JOIN auth_profile ON auth_profile.id = auth_profile_verification.auth_profile WHERE auth_profile.email = %s AND auth_profile_verification.type = 'email' AND auth_profile_verification.verified = 0 ; ",(email,))
result_unverified=self.cursor.fetchone()
self.cursor.execute(f"SELECT id, name FROM `auth_roles` WHERE auth_roles.name = %s ; ",(roles,))
result_roles=self.cursor.fetchone()
loggorilla.prcss(APIADDR,"Validation")
ifscore<0.2:
response["status"]="failed"
response["desc"]="you are sus as a bot"
response["data"]={
"recaptcha":captcha_r
}
elifglobalvar.su_mode==Falseandroles=='su':
response["status"]="failed"
response["desc"]="Forbidden to become super user"
response["data"]={
"recaptcha":captcha_r
}
elifnotre.match(r'^\w+$',username):
response["status"]="failed"
response["desc"]="username can only use letters, numbers, and the underscore symbol"
response["data"]={
"recaptcha":captcha_r
}
eliflen(username)>35:
response["status"]="failed"
response["desc"]="username can not longer than 35 character"
response["data"]={
"recaptcha":captcha_r
}
eliflen(username)<3:
response["status"]="failed"
response["desc"]="username too short"
response["data"]={
"recaptcha":captcha_r
}
eliflen(password)<6:
response["status"]="failed"
response["desc"]="password too short"
response["data"]={
"recaptcha":captcha_r
}
elifresult_unverified["count"]>=1:
response["status"]="failed"
response["desc"]="check email for verification"
response["data"]={
"message":"Check email for verification. Please contact us if you still had a problem",
"resend":globalvar.resend_url(email),
"recaptcha":captcha_r
}
elifresult_profile["count"]>=1:
response["status"]="failed"
response["desc"]="email already taken"
response["data"]={
"recaptcha":captcha_r
}
elifresult_username["count"]>=1:
response["status"]="failed"
response["desc"]="username already taken"
response["data"]={
"recaptcha":captcha_r
}
elifcaptchaandusernameandemailandpassword:
loggorilla.prcss(APIADDR,"Insering")
self.cursor.execute("INSERT INTO `auth` VALUES (%s, %s, NOW(), NULL);",(token,hashed))
self.smtpconfig['text']=f"Please visit this link to complete the registration: {verification_url}. You are not registering this? report on this: {notme_url}."
response["desc"]="Register success. Check email for verification."
response["data"]={
"recaptcha":captcha_r
}
else:
response["status"]="failed"
response["desc"]="Form not complete."
response["data"]={
"recaptcha":captcha_r
}
exceptExceptionase:
self.cursor.execute("ROLLBACK;")
loggorilla.error(APIADDR,str(e))
response["status"]="failed"
response["desc"]="Internal Server Error. Please contact us if you still have an error."
finally:
self.cursor.execute("COMMIT;")
self.cursor.close()
self.db_main.close()
returnresponse
defresend(self,params):
APIADDR="/api/auth/registration/resend"
loggorilla.prcss(APIADDR,"Define parameters")
response={}
email=params["email"].lower()
try:
loggorilla.prcss(APIADDR,"Get dependency data")
self.cursor.execute(f"SELECT COUNT(*) AS `count`, auth_profile.token, auth_profile.email FROM auth_profile_verification INNER JOIN auth_profile ON auth_profile.id = auth_profile_verification.auth_profile WHERE auth_profile.email = %s AND auth_profile_verification.type = 'email' AND auth_profile_verification.verified = 0 ; ",(email,))
result_unverified=self.cursor.fetchone()
token=result_unverified["token"].decode()
ifresult_unverified["count"]>=1:
loggorilla.prcss(APIADDR,"Generate URL")
expired=datetime.datetime.now()+datetime.timedelta(minutes=30)# Can be hours or minutes
self.smtpconfig['text']=f"Please visit this link to complete the registration: {verification_url}. You are not registering this? report on this: {notme_url}."
self.cursor.execute(f"SELECT COUNT(*) AS `count`, auth_profile_verification.verified FROM auth_profile_verification INNER JOIN auth_profile ON auth_profile.id = auth_profile_verification.auth_profile WHERE auth_profile.token = %s AND auth_profile_verification.type = 'email' ; ",(token,))
result_verification=self.cursor.fetchone()
self.cursor.execute("SELECT COUNT(*) AS `count`, token, id, email FROM auth_profile WHERE token = %s ; ",(token,))
result_profile=self.cursor.fetchone()
loggorilla.prcss(APIADDR,"Validation")
ifresult_verification['verified']==1:
response["status"]="failed"
response["desc"]="Your account already verified"
else:
loggorilla.prcss(APIADDR,"Deleting")
self.cursor.execute("DELETE FROM auth_profile_roles WHERE auth_profile = %s ; ",(result_profile['id'],))
self.cursor.execute("DELETE FROM auth_profile_verification WHERE auth_profile = %s ; ",(result_profile['id'],))
self.cursor.execute("DELETE FROM auth_profile WHERE id = %s ; ",(result_profile['id'],))
self.cursor.execute("DELETE FROM auth_session WHERE token = %s ; ",(result_profile['token'],))
self.cursor.execute("DELETE FROM auth WHERE token = %s ; ",(result_profile['token'],))
loggorilla.prcss(APIADDR,"Sending email")
self.smtpconfig['subject']=f"{globalvar.title} - Thanks for the reporting"
self.smtpconfig['to']=result_profile['email']
self.smtpconfig['text']="Thanks for your report. Now your data will be deleted from our system."
self.cursor.execute(f"SELECT COUNT(*) AS `count`, auth_profile_verification.verified FROM auth_profile_verification INNER JOIN auth_profile ON auth_profile.id = auth_profile_verification.auth_profile WHERE auth_profile.token = %s AND auth_profile_verification.type = 'email' ; ",(token,))
result_verification=self.cursor.fetchone()
self.cursor.execute("SELECT COUNT(*) AS `count`, token, id, email FROM auth_profile WHERE token = %s ; ",(token,))
result_profile=self.cursor.fetchone()
loggorilla.prcss(APIADDR,"Validation")
ifresult_verification['verified']==1:
loggorilla.prcss(APIADDR,"Giving response")
response["status"]="failed"
response["desc"]="Your account already verified"
elifdatetime.datetime.now()>expired:
loggorilla.prcss(APIADDR,"Deleting")
self.cursor.execute("DELETE FROM auth_profile_roles WHERE auth_profile = %s ; ",(result_profile['id'],))
self.cursor.execute("DELETE FROM auth_profile_verification WHERE auth_profile = %s ; ",(result_profile['id'],))
self.cursor.execute("DELETE FROM auth_profile WHERE id = %s ; ",(result_profile['id'],))
self.cursor.execute("DELETE FROM auth_session WHERE token = %s ; ",(result_profile['token'],))
self.cursor.execute("DELETE FROM auth WHERE token = %s ; ",(result_profile['token'],))
loggorilla.prcss(APIADDR,"Giving response")
response["status"]="failed"
response["desc"]="Expired. Your data removed."
else:
loggorilla.prcss(APIADDR,"Updating")
self.cursor.execute("UPDATE `auth_profile_verification` SET `verified` = 1 WHERE `type` = 'email' AND `auth_profile` = %s ; ",(result_profile['id'],))
loggorilla.prcss(APIADDR,"Sending email")
loggorilla.fyinf(APIADDR,"1")
self.smtpconfig['subject']=f"Welcome to {globalvar.title}"
self.smtpconfig['to']=result_profile['email']
self.smtpconfig['text']=f"Welcome. Now your account is verified."
self.cursor.execute(f"SELECT COUNT(*) AS `count`, auth_profile.token, auth_profile.email FROM auth_profile_verification INNER JOIN auth_profile ON auth_profile.id = auth_profile_verification.auth_profile WHERE auth_profile.email = %s AND auth_profile_verification.type = 'email' AND auth_profile_verification.verified = 1 ; ",(email,))
result_verified=self.cursor.fetchone()
token=result_verified["token"].decode()
ifresult_verified["count"]>=1:
loggorilla.prcss(APIADDR,"Generate URL")
# TODO: set expired time
expired=datetime.datetime.now()+datetime.timedelta(minutes=30)# Can be hours or minutes
expired_isoformat=expired.isoformat()
payload={
"token":token,
"expired":expired_isoformat
}
# TODO: Config SSH key for tokenguard and set forgot URL
self.cursor.execute(f"SELECT COUNT(*) AS `count`, auth_profile.email FROM auth_profile_verification INNER JOIN auth_profile ON auth_profile.id = auth_profile_verification.auth_profile WHERE auth_profile.token = %s AND auth_profile_verification.type = 'email' AND auth_profile_verification.verified = 1 ; ",(token,))
result_verified=self.cursor.fetchone()
email=result_verified['email']
loggorilla.prcss(APIADDR,"Validation")
ifdatetime.datetime.now()>expired:
response["status"]="failed"
response["desc"]="Expired"
eliflen(password)<6:
response["status"]="failed"
response["desc"]="password too short"
elifresult_verified["count"]==0:
response["status"]="failed"
response["desc"]="Forbidden: No active account for this"
response["data"]={
"message":"Please contact us if you still had a problem"
}
else:
loggorilla.prcss(APIADDR,"Updating")
self.cursor.execute("UPDATE `auth` SET `password` = %s, `when_update` = NOW() WHERE `token` = %s",(hashed,token))
self.cursor.execute(f"SELECT * FROM auth_session WHERE id = %s ; ",(session_id,))
result_session=self.cursor.fetchone()
token=result_session['token']
expired=result_session['end']
self.cursor.execute(f"SELECT COUNT(*) AS `count`, auth_profile.id, auth_profile.email FROM auth_profile_verification INNER JOIN auth_profile ON auth_profile.id = auth_profile_verification.auth_profile WHERE auth_profile.token = %s AND auth_profile_verification.type = 'email' AND auth_profile_verification.verified = 1 ; ",(token,))
result_verified=self.cursor.fetchone()
profile=result_verified['id']
email=result_verified['email']
self.cursor.execute(f"SELECT auth_roles FROM auth_profile_roles WHERE auth_profile = %s ; ",(profile,))
result_roles=self.cursor.fetchall()
roles=[]
forrowinresult_roles:
roles.append(row['auth_roles'])
loggorilla.prcss(APIADDR,"Validation")
ifdatetime.datetime.now()>expired:
loggorilla.prcss(APIADDR,"Deleting")
self.cursor.execute("DELETE FROM auth_session WHERE id = %s ; ",(session_id,))
loggorilla.prcss(APIADDR,"Giving response")
response["status"]="failed"
response["desc"]="Expired. Your session removed."
eliflen(new)<6:
response["status"]="failed"
response["desc"]="password too short"
elifresult_verified["count"]==0:
response["status"]="failed"
response["desc"]="Forbidden: No active account for this"
response["data"]={
"message":"Please contact us if you still had a problem"
}
else:
loggorilla.prcss(APIADDR,"Updating")
self.cursor.execute("UPDATE `auth` SET `password` = %s, `when_update` = NOW() WHERE `token` = %s",(hashed,token))