def admin_export(): try: log.write_to_console(msg="In Administators Export Route") try: cookie_id = request.cookies.get('{0}'.format(config.COOKIE_VALUE)) except Exception as e: cookie_id = None if cookie_id != None: session_details = session['{0}'.format(cookie_id)] log.write_to_console(msg="Account-User-Session: {}".format(session_details)) else: log.write_to_console(msg="Account-User-Session: No session Redirecting") return redirect(url_for("home.home_page")) svc = adminServices(session_details) if request.method == 'GET': print("In GET") print(request.args.to_dict()) data = svc.getAllAdministratorsExport(request.args.to_dict()) print(data) response_data = excel.make_response_from_array(data, "xls") response = make_response(response_data) response.headers['Content-Disposition'] = 'attachment; filename=BulkPay_Admins.xls' response.headers['Content-Type'] = 'application/xls' log.write_to_console(msg="Administrators export don retruning file") return response except TemplateNotFound as e: raise e
def branches_export(): try: log.write_to_console(msg="In Branches Export Route") try: cookie_id = request.cookies.get('{0}'.format(config.COOKIE_VALUE)) except Exception as e: cookie_id = None if cookie_id != None: session_details = session['{0}'.format(cookie_id)] print("Session Data") print(session_details) else: return redirect(url_for("home.home_page")) svc = adminServices(session_details) if request.method == 'GET': print("In GET") data = svc.getAllBranchesExport() print(data) response_data = excel.make_response_from_array(data, "csv") response = make_response(response_data) response.headers['Content-Disposition'] = 'attachment; filename=SSNIT_Branches_list.csv' response.headers['Content-Type'] = 'application/csv' log.write_to_console(msg="Administrators export done returning file") return response except TemplateNotFound as e: raise e
def branches_remove(): try: print("In Branches Remove") # access session data (session['k']=v) try: cookie_id = request.cookies.get('{0}'.format(config.COOKIE_VALUE)) except Exception as e: cookie_id = None if cookie_id != None: session_details = session['{0}'.format(cookie_id)] print("Session Data") print(session_details) else: return redirect(url_for("home.home_page")) print(session_details) request_data = request.form.to_dict() svc = adminServices(session_details) result = svc.removeBranch(request_data) return jsonify(result) except TemplateNotFound as e: raise e
def admins_change_password(): try: print("In Admin Add") # access session data (session['k']=v) try: cookie_id = request.cookies.get('{0}'.format(config.COOKIE_VALUE)) except Exception as e: cookie_id = None if cookie_id != None: session_details = session['{0}'.format(cookie_id)] print("Session Data") print(session_details) else: return redirect(url_for("home.home_page")) print(session_details) request_data = request.form.to_dict() svc = adminServices(session_details) result = svc.changeAdminPassword(request_data) if result['code'] == '00': session['{0}'.format(cookie_id)] = dict(result['data']) return jsonify(**result) except TemplateNotFound as e: raise e
def admins_reset_password(): try: print("In Admin forgot Password") # access session data (session['k']=v) try: cookie_id = request.cookies.get('{0}'.format(config.COOKIE_VALUE)) except Exception as e: cookie_id = None if cookie_id != None: session_details = session['{0}'.format(cookie_id)] print("Session Data") print(session_details) else: session_details = {} print(session_details) request_data = request.form.to_dict() svc = adminServices(session_details) result = svc.resetAdminPassword(request_data) return jsonify(**result) except TemplateNotFound as e: raise e
def admins_signout(): print("In Admin logout") try: cookie_id = request.cookies.get('{0}'.format(config.COOKIE_VALUE)) if cookie_id != None: session_details = session['{0}'.format(cookie_id)] svc = adminServices(session_details) result = svc.adminLogout() log.write_log("USER_ACCESS", "Logout request | "+ session_details['username'] + " | Successful | Logout Successful") else: # return redirect(url_for("home.home_page")) pass # cookie_id = request.cookies.get('{0}'.format(config.COOKIE_VALUE)) # GET previous cookies # session_details = session['{0}'.format(cookie_id)] response = make_response(redirect(url_for("home.home_page"))) if cookie_id != None: session.pop(cookie_id, None) # Clear existing session data response.set_cookie('{0}'.format(config.COOKIE_VALUE), '', expires=0) # Expire existing cookie data return response except Exception as e: response = make_response(redirect(url_for("home.home_page"))) response.set_cookie('{0}'.format(config.COOKIE_VALUE), '', expires=0) # Expire existing cookie data # cookie_id = None return response
def admins_login(): try: print("In Admin Login") # access session data (session['k']=v) # try: # cookie_id = request.cookies.get('{0}'.format(config.COOKIE_VALUE)) # except Exception as e: # cookie_id = None # # if cookie_id != None: # session_details = session['{0}'.format(cookie_id)] # print("Session Data") # print(session_details) # else: session_details = {} try_var = None # print(session_details) request_data = request.form.to_dict() if 'trying_{0}'.format(request_data['username']) in session: try_var = session['trying_{0}'.format(request_data['username'])] svc = adminServices(session_details) result = svc.adminlogin(request_data, try_var) print(result) if result['code'] == '00': cookie_value = str(uuid.uuid4()).replace('-','')[:15] # Generate a session token value session['{0}'.format(cookie_value)] = dict(result['data']) session['trying_{0}'.format(result['username'])] = None # Render Response and browser cookie value expire_date = datetime.datetime.now() expire_date = expire_date + datetime.timedelta(days=1) response = make_response(jsonify(**result)) response.set_cookie('{0}'.format(config.COOKIE_VALUE), cookie_value, expires=expire_date) # Return response for successful login return response elif result['code'] == '01' and result['data'] == 1: if 'trying_{0}'.format(result['username']) in session and session['trying_{0}'.format(result['username'])] is not None: session['trying_{0}'.format(result['username'])] = session['trying_{0}'.format(result['username'])] + 1 else: session['trying_{0}'.format(result['username'])] = 1 elif result['code'] == '01' and result['data'] == 2: session['trying_{0}'.format(result['username'])] = None return jsonify(**result) except TemplateNotFound as e: raise e
def branches_page(): try: log.write_to_console(msg="In Branches Route") # svc = adminServices(session_details) # log.write_to_console(msg="Calling service: getAllBranches()") try: cookie_id = request.cookies.get('{0}'.format(config.COOKIE_VALUE)) except Exception as e: cookie_id = None if cookie_id != None: session_details = session['{0}'.format(cookie_id)] print("Session Data") print(session_details) else: return redirect(url_for("home.home_page")) svc = adminServices(session_details) if request.method == 'POST': data = svc.getAllBranches(request.form.to_dict()) log.write_to_console(msg="Returning POST Response: getBranches()") print(data) return jsonify(data) data = svc.getAllBranches({ 'page': 0}) user_lang = lang if "lang" in session_details: user_lang = getattr(language, session_details['lang']) log.write_to_console(msg="Returning GET Response: getAllAdministrators -> Rendering Page: admins/admins.html") return render_template("admins/admins.html", lang=user_lang, mStyle=language.STYLE['admins_style'], userdata=session_details, data=data) except TemplateNotFound as e: log.write_log("ERROR", msg="Account: {}".format(e)) return render_template('404.html'), 404 except Exception as ee: log.write_log("ERROR", msg="Account: {}".format(ee)) # raise ee return render_template('500.html'), 500