Automatic user logout & redirect

58 views
Skip to first unread message

mostwanted

unread,
Aug 18, 2019, 6:26:13 AM8/18/19
to web...@googlegroups.com
I am trying to create a subscription enforcement functionality here, i have not written the code because i do not know where to start, what i want is after 3 months log out a user & redirect them to the subscription page & if they are not logged in if they try to log in when their subscription has expired get logged out immediately & be redirected to the subscription page. At the subscription page they should not be able to access any menu at all till after they have renewed their subscription.

Regards;

Mostwanted.

mostwanted

unread,
Aug 19, 2019, 2:17:31 AM8/19/19
to web2py-users
So I decided to give my problem a try, here is the code:
import datetime
def index():
    current_date
= request.now - datetime.timedelta(days=0)
   
if db(db.expiry_date_table.expiry_date < current_date ):
        redirect
(URL('subscribe'))
   
return locals()


But now the problem is that its always redirecting, it does not respect the condition of the if statement even if the expiry date is greater than the current_date!

How can i emprove this to work right?

Regards;

Mostwanted

Val K

unread,
Aug 19, 2019, 6:16:55 AM8/19/19
to web2py-users
There is no 'select' in your code. Is that a typo?

mostwanted

unread,
Aug 19, 2019, 7:18:44 AM8/19/19
to web2py-users
WOOOW, you saved my life @Val K, a million thanks, that was curelessness on my part, sometimes one gets so tired you miss the obvious.
I modified the code to this & it works, thank you again.
import datetime
def index():
    exp_date
=db(db.expiry_date_table).select()
   
for exp_d in exp_date:
        current_date
= request.now.date()- datetime.timedelta(days=0)
       
if exp_d.expiry_date < current_date:

            redirect
(URL('subscribe'))
   
return locals()
Regards;

Mostwanted

mostwanted

unread,
Aug 19, 2019, 7:59:50 AM8/19/19
to web...@googlegroups.com
Another issue i am facing with redirecting is here, i am using ajax to take the registration key from the user to a controller, what is supposed to happen is that if the registration key is valid the user should be redirected to another page allowing them normal application usage. The directing not cant redirect to a new page instead it opens the page redirected to in the div where it should display the Incorrect Code . How can i manipulate this to be able to redirect to an enirely new page if the Registration Key is correct & still be able to display the Incorrect Code message in the relevant div?

VIEW CODE
<div id="code">
 
<input id="regcode"  maxlength="10" type="text" class="field" name="regCode" autocomplete="off" onkeyup="ajax('reg_key_entry', ['regCode'], 'regCodeTarget')" placeholder="Enter Product Key"/><br />
               
<div id="regCodeTarget"></div>
'regCodeTarget' is where the page keeps getting displayed

CONTROLLER CODE
def reg_key_entry():
    key_exists
= not db(db.regKeys.regKey == request.vars.regCode).isempty()
   
if key_exists:
       
#A used reg key should get deleted so that it cant be used twice
        db
(db.regKeys.regKey == request.vars.regCode).delete()
        redirect
(URL('index'))
   
else:
       
return DIV("INCORRECT PRODUCT KEY", _id="regCodeTarget", _style="color: white; border: solid 1px red; width: 160px; background-color: red; font-weight: bold; padding: 3px; border-radius:5px;")

There must be something I can do which i dont know, please help!

Regards;

Mostwanted

On Monday, August 19, 2019 at 12:16:55 PM UTC+2, Val K wrote:

Paco Bernal

unread,
Aug 19, 2019, 6:10:50 PM8/19/19
to web2py-users
redirect(URL('index'), client_side=True)
Reply all
Reply to author
Forward
0 new messages