p4web auth issues

84 views
Skip to first unread message

Maurice Waka

unread,
Feb 22, 2020, 9:28:10 PM2/22/20
to web2py-users
Using this code,

File "apps/_scaffolds/controllers.py", line 82, in index db.posts.insert(message="Welcome "+auth_user.first_name+'.'+' Thank you for signing in with us. Blah blah blah.', author=auth.user_id, created_by=auth.user_id, modified_by=auth.user_id)


I get an error:

NameError: name 'auth_user' is not defined

I also tried:

Auth.first_name;
auth
.first_name;
auth
.user.first_name


and the errors are the same

Please help here.

Regards

Ruslan Gareev

unread,
Feb 23, 2020, 8:38:25 AM2/23/20
to web2py-users
Hi! Looks like no import of auth

воскресенье, 23 февраля 2020 г., 7:28:10 UTC+5 пользователь Maurice Waka написал:

Maurice Waka

unread,
Feb 23, 2020, 11:57:31 AM2/23/20
to web2py-users
Hi
I have this with the same error:

from .common import db, session, T, cache, auth, logger, authenticated, unauthenticated
from py4web.utils.auth import Auth

Val K

unread,
Feb 23, 2020, 12:28:28 PM2/23/20
to web2py-users
Show your code, please

Maurice Waka

unread,
Feb 23, 2020, 12:47:46 PM2/23/20
to web2py-users

import os
import datetime as dt
from datetime import datetime, timedelta, date 
from .common import db, session, T, cache, auth, logger, authenticated, unauthenticated
from py4web import action, request, DAL, Field, Session, Cache, user_in, abort, redirect, URL, Field
from py4web.utils.auth import Auth
from py4web import action, request, abort, redirect, URL, Field
from py4web.utils.form import Form, FormStyleBulma
from py4web.utils.publisher import Publisher, ALLOW_ALL_POLICY
from pydal.validators import IS_NOT_EMPTY, IS_INT_IN_RANGE, IS_IN_SET, IS_IN_DB, IS_EMAIL, IS_MATCH
from yatl.helpers import INPUT, H1, HTML, BODY, A
from pydal.validators import *

db.define_table('answers',
                Field('author', 'reference auth_user', default=auth.user_id, readable=False, writable=False),
                Field('userId','reference auth_user',unique=True,readable=False,writable=False),
                Field('quest', 'text', requires=IS_NOT_EMPTY(),),
                auth.signature
                )
db.define_table('posts',
                Field('author', 'reference auth_user', default=auth.user_id, writable=False, readable=False),
                Field("message", 'text', requires=IS_NOT_EMPTY(), notnull=False),
                auth.signature
                )

@authenticated()
def index():
    codes = []
    del codes[:]
    r = []
    yesterday = dt.datetime.utcnow() - dt.timedelta(days=1)
    db(db.answers.modified_on < yesterday).delete()
    """Avoid an empty table"""
    user = db(db.posts.author== auth.user_id).select(db.posts.id, db.posts.author, orderby=~db.posts.id, limitby=(0,1)).first()
    if user.author if user else None == auth.user_id:
        pass
    else:
        db.posts.insert(message="Welcome "+auth_user.first_name+'.'+' Thank you for signing in with us. Blah blah blah.', author=auth.user_id, created_by=auth.user_id, modified_by=auth.user_id)
        db.commit()
On Sunday, February 23, 2020 at 8:28:28 PM UTC+3, Val K wrote:
Show your code, please

Val K

unread,
Feb 23, 2020, 6:02:48 PM2/23/20
to web2py-users
`auth` in py4web is no the same as in web2py
to get user-record you should
...
def index():
    user = auth.get_user()


Lovedie JC

unread,
Feb 23, 2020, 9:23:06 PM2/23/20
to web...@googlegroups.com
Thanks.
Before you replied I had tried :
user = auth.get.user()[first_name]

With an error.. 'first_name' is not defined
Regards 

--
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+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/19c4dd56-ffc3-40bb-9067-e5525ffafcf7%40googlegroups.com.

Scott Hunter

unread,
Feb 23, 2020, 10:14:24 PM2/23/20
to web2py-users
user = auth.get.user()['first_name']
To unsubscribe from this group and stop receiving emails from it, send an email to web...@googlegroups.com.

Maurice Waka

unread,
Feb 23, 2020, 10:28:34 PM2/23/20
to web...@googlegroups.com
Thanks a lot. 
Regards 

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/_x-OLtei8XE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/25dfd7d0-f876-4e97-a3ba-ff06a1415cba%40googlegroups.com.

Maurice Waka

unread,
Feb 24, 2020, 4:53:38 AM2/24/20
to web2py-users
Something is not right...
Now I get this error:


Traceback (most recent call last):
 
File "/home/maurice/py4web/py4web/core.py", line 551, in wrapper
 ret
= func(*func_args, **func_kwargs)
 
File "/home/maurice/py4web/py4web/core.py", line 512, in wrapper
 ret
= func(*args, **kwargs)
 
File "apps/_scaffolds/controllers.py", line 74, in index
 user
= auth.get.user()['first_name']
AttributeError: 'Auth' object has no attribute 'get'

Val K

unread,
Feb 24, 2020, 4:58:10 AM2/24/20
to web2py-users
get_user(), not get.user()

Maurice Waka

unread,
Feb 24, 2020, 6:56:12 AM2/24/20
to web2py-users
Working now.

I had to reinstall the app.
Regards

On Monday, February 24, 2020 at 12:58:10 PM UTC+3, Val K wrote:
get_user(), not get.user()

Oasis Agano

unread,
May 28, 2020, 11:16:40 PM5/28/20
to web2py-users
By the way reinstalling the app solved another auth problem i had with an instance that had been idle for a few years.
I think there is something strange with auth that is solved with reinstalling the app.

Anyway thank you
Reply all
Reply to author
Forward
0 new messages