Пример #1
0
 def attach_access_key(cls,
                       user: '******',
                       key: Authentication,
                       auto_save: bool = True):
     key.user_id = user.id
     if auto_save:
         key.save()
Пример #2
0
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))
Пример #3
0
def signup():
    """ The SignUp Page - Send Form to /SignUpFormPost . """

    if Authentication(session).is_signed_in():
        return redirect("/")

    return render_template("auths/signup.html")
Пример #4
0
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")
Пример #5
0
def login():
    """ The LogIn Page - Send Form to /LogInFormPost . """

    if Authentication(session).is_signed_in():
        return redirect("/")

    return render_template("auths/signin.html")
Пример #6
0
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")
Пример #7
0
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")
Пример #8
0
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", )
Пример #9
0
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)
Пример #10
0
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("/")
Пример #11
0
 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
Пример #12
0
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("/")
Пример #13
0
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("/")
Пример #14
0
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("/")
Пример #15
0
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()
Пример #16
0
    def decorated(*args, **kwargs):

        g.is_signed_in = Authentication(session).is_signed_in()

        return f(*args, **kwargs)
Пример #17
0
 def __check_is_admin(*args, **kwargs):
     result = f(*args, **kwargs)
     if not Authentication(session).is_admin():
         abort(401)
     return result
Пример #18
0
def check_is_admin():
    if not request.full_path.startswith("/static"):
        if not Authentication(session).is_admin():
            abort(401)
Пример #19
0
def is_it_admin():
    if not request.full_path.startswith("/static"):
        g.is_admin = Authentication(session).is_admin()