How can Google SingIn not log in automatically when entering the login page?

1

I have a login page where there is the option to login via Google SingIn to web, however I want to avoid the following behaviors:

  • If I have already logged into the google account in the browser, when entering the site it automatically identifies that I am logged in, I want that even logged in google, the site allows the user to enter or not clicking on login.

  • There is a rule that only emails with domain @uniriotec.br will be accepted, if the domain is @gmail.com the site shows a modal with the warning, however due to the above item the site recharges infinitely because it identifies there is already a connected google account and tries to log into the application in an infinite loop.

  • NOTE: I'm having problems trying to use the function to revoke access, it returns an error in api .

I pass user information from Google via form , below I go by the codes used.

<!-- formulario que submete os parametros do usuario via Google SingIn -->
    <form id="singin" action="{% url 'uniriotecValid' %}" method="POST">
        {% csrf_token %}
        <input type="hidden" name="name" id="Gname" value=''/>
        <input type="hidden" name="imageUrl" id="Gimage" value=''/>
        <input type="hidden" name="email" id="Gmail" value='/'>
    </form>

Function javascript submitting form

function onSignIn(googleUser) {
    var profile = googleUser.getBasicProfile();
    var credential_form = document.forms['singin'];

    credential_form.elements["name"].value = profile.getName();
    credential_form.elements["imageUrl"].value = profile.getImageUrl();
    credential_form.elements["email"].value = profile.getEmail();

    document.getElementById("singin").submit();
}

view that the domain rule is applied

def uniriotecValid(request):
if request.method == "POST":
    email = request.POST.get('email')
    if email.find('@uniriotec.br') >= 0:
        name = request.POST.get('name')
        imageUrl = request.POST.get('imageUrl')

        return HttpResponse(email)
    else:
        return render(request, 'index.html', {'invalid': True})

Rule to show modal

{% if invalid == True %}
<script type="text/javascript">
    $('#invalidDomain').modal('show');
</script>
{% endif %}
    
asked by anonymous 23.10.2018 / 16:02

0 answers