healthier/views.py
def login(request):
    """
    login and redirects to myaccount or create a new user and redirects
    to myaccount or logout and redirects to home if user logged-in
    """
    request.session["visited"] = True
    form1 = FoodQuery(auto_id="form1")
    if not request.user.is_authenticated:
        sign_form = Signin(auto_id="signin%s")
        log_form = Login(auto_id="login%s")
        message = {
            "form1": form1,
            "sign_form": sign_form,
            "log_form": log_form,
        }
        if request.method == "POST":
            sign_form = Signin(request=request, data=request.POST, auto_id="signin%s")
            try:
                e = sign_form.save()
                if e == True:
                    return redirect(reverse("healthier:myaccount"))
                else:
                    message.update(
                        {"sign_form": sign_form, "modaltoshow": "SigninModal"}
                    )
            except:
                return HttpResponseServerError(
                    "Désolé, une erreur s'est produite dans le traitement de votre inscription !"
                )
        elif "username" in request.GET:
            log_form = Login(request, data=request.GET, auto_id="login%s")
            try:
                log_form.log_user()
                return redirect(reverse("healthier:myaccount"))
            except:
                message.update({"modaltoshow": "LoginModal", "log_form": log_form})

        return render(request, "healthier/_login_signin.html", message)
    else:
        logout(request)
        return redirect(reverse("healthier:home"))
    return render(request, "healthier/_results.html", message)

    login and redirects to myaccount or create a new user and redirects
    to myaccount or logout and redirects to home if user logged-in
    
login and redirects to myaccount or create a new user and redirects
to myaccount or logout and redirects to home if user logged-in
login and redirects to myaccount or create a new user and redirects to myaccount or logout and redirects to home if user logged - in
def login(request):
    request.session["visited"] = True
    form1 = FoodQuery(auto_id="form1")
    if not request.user.is_authenticated:
        sign_form = Signin(auto_id="signin%s")
        log_form = Login(auto_id="login%s")
        message = {
            "form1": form1,
            "sign_form": sign_form,
            "log_form": log_form,
        }
        if request.method == "POST":
            sign_form = Signin(request=request, data=request.POST, auto_id="signin%s")
            try:
                e = sign_form.save()
                if e == True:
                    return redirect(reverse("healthier:myaccount"))
                else:
                    message.update(
                        {"sign_form": sign_form, "modaltoshow": "SigninModal"}
                    )
            except:
                return HttpResponseServerError(
                    "Désolé, une erreur s'est produite dans le traitement de votre inscription !"
                )
        elif "username" in request.GET:
            log_form = Login(request, data=request.GET, auto_id="login%s")
            try:
                log_form.log_user()
                return redirect(reverse("healthier:myaccount"))
            except:
                message.update({"modaltoshow": "LoginModal", "log_form": log_form})
        return render(request, "healthier/_login_signin.html", message)
    else:
        logout(request)
        return redirect(reverse("healthier:home"))
    return render(request, "healthier/_results.html", message)
def login ( request ) : request . session [ "visited" ] = True form1 = FoodQuery ( auto_id = "form1" ) if not request . user . is_authenticated : sign_form = Signin ( auto_id = "signin%s" ) log_form = Login ( auto_id = "login%s" ) message = { "form1" : form1 , "sign_form" : sign_form , "log_form" : log_form , } if request . method == "POST" : sign_form = Signin ( request = request , data = request . POST , auto_id = "signin%s" ) try : e = sign_form . save ( ) if e == True : return redirect ( reverse ( "healthier:myaccount" ) ) else : message . update ( { "sign_form" : sign_form , "modaltoshow" : "SigninModal" } ) except : return HttpResponseServerError ( "Désolé, une erreur s'est produite dans le traitement de votre inscription !" ) elif "username" in request . GET : log_form = Login ( request , data = request . GET , auto_id = "login%s" ) try : log_form . log_user ( ) return redirect ( reverse ( "healthier:myaccount" ) ) except : message . update ( { "modaltoshow" : "LoginModal" , "log_form" : log_form } ) return render ( request , "healthier/_login_signin.html" , message ) else : logout ( request ) return redirect ( reverse ( "healthier:home" ) ) return render ( request , "healthier/_results.html" , message )
login and redirects to myaccount or create a new user and redirects
to myaccount or logout and redirects to home if user logged-in
login and redirects to myaccount or create a new user and redirects to myaccount or logout and redirects to home if user logged - in
"""
    login and redirects to myaccount or create a new user and redirects
    to myaccount or logout and redirects to home if user logged-in
    """
request