How are you setting is_active to False? Are you doing it manually, or is it 
happening via a delete with record versioning enabled (as described here 
<http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Record-versioning>)?
 
If the latter, you don't need to do any check, as a common filter 
automatically excludes all records with in_active == False from all queries.

If you are setting it manually, you can set up your own common filter 
<http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Common-filters>
:

db.auth_user._common_filter = lambda query: db.auth_user.is_active == True

By default, the above will affect all queries against the db.auth_user 
table (though can be disabled for specific queries).

If you want to be able to show an error message as in your code below for 
users who are in the system but simply not active (as opposed to users who 
are not in the system at all), then your approach is probably best.

Anthony

On Tuesday, April 2, 2019 at 8:52:20 PM UTC-4, João Matos wrote:
>
> Found a solution
>
> def check_if_user_is_active(form):
>     """Check if user is active."""
>     if not db.auth_user(username=form.vars.username).is_active:
>         session.flash = T('That username is not active.')
>         redirect(URL('user', 'login'))
>
>
> auth.settings.login_onvalidation.append(check_if_user_is_active)
>
>
> Is there a better way?
>
>
> quarta-feira, 3 de Abril de 2019 às 01:25:22 UTC+1, João Matos escreveu:
>>
>> Hello,
>>
>> How can I block logins from users with is_active == False?
>>
>> Thanks,
>>
>> JM
>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to