def attach_access_key(cls, user: '******', key: Authentication, auto_save: bool = True): key.user_id = user.id if auto_save: key.save()
def sign_up(): if not request.form: return render_template('register.html', form=RegisterForm()) form = RegisterForm(request.form) if User.sign_up_user(form): login_form = LoginForm(request.form) Authentication.login(login_form) flash(config.REGISTRATION_SUCCEED, 'success') return redirect(url_for(config.END_POINT_INDEX)) else: flash(config.REGISTRATION_FAILED, 'error') return redirect(url_for(config.END_POINT_SIGN_UP))
def signup(): """ The SignUp Page - Send Form to /SignUpFormPost . """ if Authentication(session).is_signed_in(): return redirect("/") return render_template("auths/signup.html")
def logout(): """ The LogOut submit Page - Send request to /SignUpFormPost . """ if not Authentication(session).is_signed_in(): return redirect("/") return render_template("auths/logout.html")
def login(): """ The LogIn Page - Send Form to /LogInFormPost . """ if Authentication(session).is_signed_in(): return redirect("/") return render_template("auths/signin.html")
def profle(): """ The Profile page. """ # Handle if signed in if not Authentication(session).is_signed_in(): return redirect("/LogIn") return render_template("user/profile.html")
def urge_mails(): """ The Mail page. """ # Handle if signed in if not Authentication(session).is_signed_in(): return redirect("/LogIn") return render_template("user/mail.html")
def motivational_sentences(): """ The motivational wall sentences page. """ # Handle if signed in if not Authentication(session).is_signed_in(): return redirect("/LogIn") return render_template("basic/motivationwall.html", )
def login(): form = LoginForm(request.form) if request.form: if Authentication.login(form): return redirect(url_for(config.END_POINT_INDEX)) else: return redirect(url_for(config.END_POINT_LOGIN)) return render_template('login.html', form=form)
def logout_form(): """ The Logout request. """ # Handle if signed in if not Authentication(session).is_signed_in(): return redirect("/LogIn") session["logged_in"] = False session["admin"] = False return redirect("/")
def generate_access_key(self, expires: relativedelta = None, note: str = None, save: bool = False) -> Authentication: auth_key = Authentication(note=note) if expires is None: auth_key.never_expire() else: auth_key.expires_in(expires) self.attach_access_key(self, auth_key) if save: auth_key.save() return auth_key
def survey_topics(): if session.get("logged_in"): identity = session["Data"]["Email"] else: identity = "unknown" user_ip_address = request.remote_addr request_args = request.get_json() topics = PageDetails().get_survey_json_data()["questions"] user_survey_answer = {} for topic in topics: user_survey_answer[topic] = request_args[topic] user_survey_answer["secound_questions"] = request_args["secound_questions"] Database().add_user_survey_answer_to_db(user_ip_address, identity, dumps(user_survey_answer)) Authentication(session).user_answered_survey() return redirect("/")
def login_form(): """ The Login Data Form Post Api. """ try: recaptcha_request = requests.post( "https://www.google.com/recaptcha/api/siteverify", data={ "secret": setting.recaptcha_secret_key, "response": request.form["g-recaptcha-response"], }, ) google_response = json.loads(recaptcha_request.text) username_or_email = request.form.get("email") password = request.form.get("password") # Handle Wrong Form Data except KeyError: abort(400) # Handle Wrong ReCaptcha if not google_response["success"]: return render_template("auths/signin.html", message=" لطفا 'من ربات نیستم' را انجام دهید. ") # Handle Wrong Username or password sign_in_data = Authentication().signin(username_or_email, password) if not sign_in_data["result"]: return render_template("auths/signin.html", message=sign_in_data["message"]) # Set Up a sesson , make it permanent , session["Data"] = sign_in_data["session"] session.permanent = True session["logged_in"] = True if username_or_email == "*****@*****.**": session["admin"] = True else: session["admin"] = False return redirect("/")
def signup_form(): """ The Login Data Form Post Api. """ try: recaptcha_request = requests.post( "https://www.google.com/recaptcha/api/siteverify", data={ "secret": "6LfokdYZAAAAALgHTMNJ9vIZws16wKtlF7-529tW", "response": request.form["g-recaptcha-response"], }, ) google_response = json.loads(recaptcha_request.text) first_name = request.form.get("first_name") last_name = request.form.get("last_name") email = request.form.get("email") password = request.form.get("password") # Handle Wrong Form Data except KeyError: abort(400) # Handle Wrong ReCaptcha if not google_response["success"]: return render_template("auths/signup.html", message=' "من ربات نیستم" را انجام دهید ') # Handle Wrong signup info sign_up_data = Authentication().signup(first_name, last_name, email, password) if not sign_up_data["result"]: return render_template("auths/signup.html", message=sign_up_data["message"]) # Set Up a sesson , make it permanent , session["Data"] = sign_up_data["session"] session.permanent = True session["logged_in"] = True return redirect("/")
def survey_data(): if not request.full_path.startswith("/static"): if Authentication(session).has_user_answered_survey() is True: g.survey = False else: try: survey_data_session = session["survey"] except KeyError: survey_data_session = 0 session["survey"] = survey_data_session g.survey = True if type(survey_data_session) == int: if survey_data_session % 6 == 0: g.survey = True else: g.survey = False session["survey"] += 1 else: g.survey = True session["survey"] = 1 g.survey_data = PageDetails().get_survey_json_data()
def decorated(*args, **kwargs): g.is_signed_in = Authentication(session).is_signed_in() return f(*args, **kwargs)
def __check_is_admin(*args, **kwargs): result = f(*args, **kwargs) if not Authentication(session).is_admin(): abort(401) return result
def check_is_admin(): if not request.full_path.startswith("/static"): if not Authentication(session).is_admin(): abort(401)
def is_it_admin(): if not request.full_path.startswith("/static"): g.is_admin = Authentication(session).is_admin()