db._common_fields.append(Field('request_tenant',
default=request.env.http_host,
writable=False))
default=session.workspace,
if auth.is_logged_in:
db.related_table_1._common_filter = lambda query: db.related_table_1.workspace = auth.user.workspace
db.related_table_2._common_filter = lambda query: db.related_table_2.workspace = auth.user.workspace
db.related_table_3._common_filter = lambda query: db.related_table_3.workspace = auth.user.workspace
db.related_table_4._common_filter = lambda query: db.related_table_4.workspace = auth.user.workspace
...etc...
--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/6SscBvMorU0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
# ---- example index page ----
@auth.requires_login()
def index():
response.flash= T("Hello World")
return dict(message=T('Welcome to web2py!'))
def user():
"""
exposes:
http://..../[app]/default/user/login
http://..../[app]/default/user/logout
http://..../[app]/default/user/register
http://..../[app]/default/user/profile
http://..../[app]/default/user/retrieve_password
http://..../[app]/default/user/change_password
http://..../[app]/default/user/bulk_register
use @auth.requires_login()
@auth.requires_membership('group name')
@auth.requires_permission('read','table name',record_id)
to decorate functions that need access control
also notice there is http://..../[app]/appadmin/manage/auth to allow administrator to manage users
"""
return dict(form=auth())
# ---- User functions ---
def login(): return dict(form=auth.login())
def register(): return dict(form=auth.register())
def retrieve_password(): return dict(form=auth.reset_password())
def logout(): return dict(form=auth.logout())
def profile(): return dict(form=auth.profile())
auth.settings.extra_fields['auth_user'] = [
Field ('workspace', length=128),
# ---- User functions ---
def login(): return dict(form=auth.login())
def register(): return dict(form=auth.register())
def retrieve_password(): return dict(form=auth.reset_password())
def logout(): return dict(form=auth.logout())
def profile(): return dict(form=auth.profile())
# ---- User functions ---
'''def login(): return dict(form=auth.login())
def register(): return dict(form=auth.register())
def retrieve_password(): return dict(form=auth.reset_password())
def logout(): return dict(form=auth.logout())
def profile(): return dict(form=auth.profile())
'''
@auth.requires_login()
def index():
response.flash = T("Hello User")
#redirect(URL(r=request, c='default/user', f='login')) # Redirects user to login page
return dict(message=T('Welcome to web2py!'))
I even decorated index - It does take me to the login screen but from there nothing happens. It just wont log me in like it did before. Also, I have two users in database but none work now. Again, register seems to fail (It did work earlier) but now it doesnt. See screenshot of both screens. Looks like I must be really doing something weird. If this wont work by this Sunday. I may go back to my old style of coding and do it all by myself. I've seriously lost 10 days reading and experimenting with Auth to make it work . Not too much coded.
## after auth = Auth(db)
db.define_table('workspaces',
Field('workspace', 'string', requires=IS_NOT_EMPTY()))
auth.settings.extra_fields['auth_user']= [ Field('workspace', 'reference workspaces', label=T('workspace')]
db.auth_user.workspace
.requires = IS_IN_DB(db, db.workspaces
.id, '%(workspace
)s')