def sign_in():
     connection = None
     try:
         connection = connect_db()
         login_data = request.json
         account_service = AccountService()
         token = account_service.signin(login_data, connection)
         return token
     except Exception as e:
         return jsonify({'MESSAGE': f'{e}'}), 400
     finally:
         if connection:
             connection.close()
def signin(request):
    signup_html_page = loader.get_template('../ui/index.html')
    context = {}
    if request.method == 'POST':
        email = request.POST["txtEmail"]
        password = request.POST["txtPassword"]
        if not email:
            context["error_msg"] = "Invalid email or password."
        else:
            account_service = AccountService()
            user = account_service.signin(email, password)
            if user is None:
                context["error_msg"] = "Invalid email or password."
            else:
                request.session["login_user"] = user
                context["success_msg"] = "Login successful."
                return redirect("AdminDash/")
    return HttpResponse(signup_html_page.render(context, request))
Example #3
0
def signin(request):
    signup_html_page = loader.get_template('../ui/index.html')
    context = {}
    if request.method == 'POST':
        email = request.POST["txtEmail"]
        password = request.POST["txtPassword"]
        if email == "*****@*****.**" and password == "12345678":
            request.session["login_user"] = email
            context["success_msg"] = "Login successful."
            return redirect("/account/admindash/index/")
        if not email:
            context["error_msg"] = "Invalid email or password."
        else:
            # ph = password_hash(password)
            account_service = AccountService()
            user = account_service.signin(email, password)
            if user is None:
                context["error_msg"] = "Invalid email or password."
            else:
                request.session["login_user"] = email
                context["success_msg"] = "Login successful."
                return redirect("/account/viewerdash/index/")
    return HttpResponse(signup_html_page.render(context, request))