Search code examples
pythonhtmlcssweb2pytwo-factor-authentication

Web2Py: customizing two-step verification form


I want to customize the two-step verification form of web2py. I read this question which explains how to customize a normal auth form which was useful, but I still don't know how to use a custom form for the second step (submitting the verification code). Does anyone know how to do this or have already succeeded at this? I hope someone can help.


Solution

  • To determine whether you are on the second step of the login process, you can check the value of session.auth_two_factor_user (it will have a value during the second step but be None otherwise). So, in the user.html view, you could include conditional logic like this:

    {{if request.args(0) == 'login':}}
      {{if not session.auth_two_factor_user:}}
      [Custom first step login form]
      {{else:}}
      [Custom second step code verification form]
      {{pass}}
    {{pass}}