Reputation: 2451
Is there a way to password-protect a subdomain for a web2py-based page by using the routes file or other means? For instance, if you have mydomainname.com, can you make the main page public while password-protecting sub.mydomainname.com? Thanks.
Upvotes: 1
Views: 101
Reputation: 25536
You wouldn't use routes.py to do the password protecting, but you can use it to route sub.mydomainname.com to a particular application or controller within an application.
From that point, all you have to do is use the standard Auth checks to require login for access to the sub.mydomainname.com application or controller. To protect an entire application, somewhere in a model file after Auth has been defined, you can do something like:
if (not auth.user and
not (request.function == 'user' and request.args(0) == 'login')):
redirect(URL('default', 'user', args='login'))
If you just need to protect a controller, you can put similar code at the top of the controller (though you don't need to check for the /default/user/login URL if it isn't the default.py controller).
Upvotes: 1