Thanks Jonathan & Kenneth,
have successfully implemented the subdomain module based on your
feedback ( using request.env.http_host ) and setting it globally
( 0.py ) using the following function:
def get_subdomain():
"""
Extracts subdomain from the url
"""
try:
subdomain = request.env.http_host.split('.')[:-2].pop()
if subdomain == 'www':
return ''
return subdomain
except IndexError:
return ''
DOMAIN = 'mydomain.com'
SUBDOMAIN = get_subdomain()
Now I have to redirect to the user1.mydomain.com after user1 has
logged in .. which works but only if _next variable is not set.
in db.py I have set auth.settings.login_next =
URL(r=request,c='default',f='set_domain') where the set_domain method
goes like this..
def set_domain():
if auth.user and request.get_vars._next:
redirect('http://'+auth.user.username+'.'+DOMAIN
+request.get_vars._next)
elif auth.user:
redirect('http://'+auth.user.username+'.'+DOMAIN)
else:
redirect(URL(f='index'))
This works only if the _next variable is not set
If _next is set with some value ( eg: _next='myapp/default/show_id' :
show_id has @auth.login_required ) .. set_domain method will not get
called and it just redirects to the value set in _next variable in
which case I will not be able the redirect to username.mydomain.com.
How can I work this out.. or is their any better approach to achieve
this?
.. Thanks in advance!
On Feb 2, 10:28 am, Jonathan Lundell <[email protected]> wrote:
> On Feb 1, 2011, at 9:23 PM, Kenneth Lundström wrote:
>
>
>
> > >> Also user1 must be able to point user1.mydomain.com to his own domain (
> > >> custom domain feature) for the application interface. How can I achieve
> > >> this?
>
> >> I'm not sure what you mean by that.
>
> > I understod it like that a user should have the ability to in settings add
> > a custom domain (myowndomain.net) to point to user1.mydomain.com. Of course
> > the users takes care of DNS and things like that but how to get web2py to
> > understand that users own domain even should be used.
>
> By the time web2py sees it, request.env.http_host will be either
> myowndomain.net or user1.mydomain.net, depending on how the external
> redirection goes. Assuming all this is going to the same application, the
> easiest thing to do would be to look at http_host in a model file (before the
> controller gets it) and maybe stash it somewhere else, like
> request.env.user_domain or the like, for the controller to use.
>
> It could be tacked on to request.vars, too, but I don't think there's any
> great point in doing that.
>
> This all depends on what you want to *do* with the domain name information,
> of course.