def add_security_question(question): from constants import load_security_questions SECURITY_QUESTIONS = load_security_questions() SECURITY_QUESTIONS.append(question) if type(SECURITY_QUESTIONS) != list: raise ValueError('SECURITY_QUESTIONS is null') with open('database/security_questions.json','w') as file: file.write(json.dumps({"list":SECURITY_QUESTIONS}))
def security_questions(): from app import get_admin_auth if not get_admin_auth(): flash('please sign in here and then return to siteadmin') return redirect('/admin') from constants import load_security_questions SECURITY_QUESTIONS = load_security_questions() return render_template('siteadmin/questions/securityq.html',SECURITY_QUESTIONS=SECURITY_QUESTIONS)
def security_question_add(): from app import get_admin_auth if not get_admin_auth(): flash('please sign in here and then return to siteadmin') return redirect('/admin') from constants import load_security_questions SECURITY_QUESTIONS = load_security_questions() if request.method == 'POST': q = request.form.get('question') if limit_input_size(name=q, max_size=100, item="security question"): return redirect('/siteadmin/securityq/add') add_security_question(q) return redirect('/siteadmin/securityq') return render_template('siteadmin/questions/add.html',SECURITY_QUESTIONS=SECURITY_QUESTIONS, add=True)
def security_question_remove(): from app import get_admin_auth if not get_admin_auth(): flash('please sign in here and then return to siteadmin') return redirect('/admin') from constants import load_security_questions SECURITY_QUESTIONS = load_security_questions() if request.method == 'POST': q = request.form.get('question') status = remove_security_question(q) if status == False: flash('You cannot delete that security question because it is already in use by somebody') return redirect('/siteadmin/securityq') return render_template('siteadmin/questions/remove.html',SECURITY_QUESTIONS=SECURITY_QUESTIONS, remove=True)
def remove_security_question(question): from constants import load_security_questions SECURITY_QUESTIONS = load_security_questions() from app import User SECURITY_QUESTIONS.remove(question) if type(SECURITY_QUESTIONS) != list: raise ValueError('SECURITY_QUESTIONS is null') users = User.query.all() for user in users: user_q = user.security_question_id # called id but actually a string of the question itself if user_q == question: print(f'{user.username} has already used the security question "{question}". Overriding deleting that record.') return False with open('database/security_questions.json','w') as file: file.write(json.dumps({"list":SECURITY_QUESTIONS})) return True