On Saturday, September 24, 2022 at 1:43:13 AM UTC-7 mostwanted wrote:
> So I was able to figure my problem out thanks to Arglanir. I put in
> alittle effort & I achieved positive results with the code below.
>
> def onetimecode(func):
> def wrapper():
> details=['not logged', session.logged]
> if not request.vars.type or request.vars.type not in details:
> redirect(URL('default', 'subscribe'))
> else:
> return func()
> return wrapper
>
>
>
>
Glad you got it figured out, and thanks for sharing.
/dps
>
> On Wednesday, September 21, 2022 at 10:33:45 AM UTC+2 mostwanted wrote:
>
>> *STATEMENT OF THE PROBLEM*
>>
>>
>> I have an infinite loop problem that i don't know how to escape so i need
>> help I have never used a decorator before I'm not even sure i fully
>> understand how they work but i have used one & it's giving me a headache.
>>
>> I have registration form that's supposed to be protected by a one time
>> code login page that i put inside a decorator trying to simulate
>> *@auth.requires_login()*. The idea is that if the one time code is
>> correct the user should access the registration form but *NEVER* if it's
>> wrong and the user should never be able to bypass the security feature by
>> directly typing the page address in the URL! But now I'm stuck in a loop
>> with a page(one time code page) that keeps calling itself. How can I fix
>> this to get what I want??
>>
>>
>> *ONE TIME CODE FORM*
>>
>> def subscribe():
>> key_exists = not db(db.regKeys.regKey == request.vars.regCode).isempty()
>> if request.vars.regCode is None:
>> message=''
>> if key_exists:
>> db(db.regKeys.regKey == request.vars.regCode).delete()
>> redirect(URL('register_product'))
>> if request.vars.regCode is not None and not key_exists:
>> message="INCORRECT REG CODE"
>> return locals()
>>
>>
>> *DECORATOR CODE*
>>
>> def onetimecode(func):
>> def wrapper():
>> redirect(URL('default', 'subscribe'))
>> return wrapper
>>
>>
>> *REGISTRATION FORM WITH THE DECORATOR*
>>
>> @onetimecodedef register_product():
>> timeout = auth.settings.expiration
>> details=db(db.thirdParty).select()
>> form=SQLFORM(db.black_market2)
>> if form.process().accepted:
>> response.flash=T('Successfully Registered')
>> return locals()
>>
>>
>>
>>
>>
>>
>>
>>
>>
--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/735e20a2-a1db-4b8c-a8fd-146812b028b6n%40googlegroups.com.