py4web Auth

139 views
Skip to first unread message

Boggy

unread,
Sep 28, 2019, 3:49:09 AM9/28/19
to web2py-users

Can i get py4web documentation of auth for both login form and Rest APi? 

Massimo Di Pierro

unread,
Sep 28, 2019, 3:51:00 AM9/28/19
to web2py-users
you can but the auth documentation does not exist yet.
the restapi is partially documented here: http://py4web.com/_documentation/static/index.html#chapter-06

Massimo Di Pierro

unread,
Sep 30, 2019, 12:39:09 AM9/30/19
to web2py-users
I added a page to the documentation:


I am sure it if full of spelling errors and I am making a fool of myself (my keyboard is acting up and my mother language is not english)
Also the examples could use an independent tester as I typed them without running them.

Anyway I thought this was better than nothing. :-)

Massimo

John Bannister

unread,
Sep 30, 2019, 4:07:23 AM9/30/19
to web...@googlegroups.com

Hi Massimo,

 

Thanks very much. Will test and give you some feedback hopefully today.

 

Is there some sort of way to access user info from layout.html for example across multiple modules without having to pass the user from each eaction in each module? I want to be able to display the user name as part of the menu something like Welcome John (if the user is logged in) irrespective of module or action??

 

Best Regards

John

--
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/e525e23a-199b-4b9b-83f6-ced97e1efaff%40googlegroups.com.

Massimo Di Pierro

unread,
Sep 30, 2019, 11:11:41 AM9/30/19
to web2py-users
In any action decorated with @action.uses(auth.user) you can do

first_name = auth.get_user()['first_name']

Is this what you are asking?

On Monday, 30 September 2019 01:07:23 UTC-7, John Bannister wrote:

Hi Massimo,

 

Thanks very much. Will test and give you some feedback hopefully today.

 

Is there some sort of way to access user info from layout.html for example across multiple modules without having to pass the user from each eaction in each module? I want to be able to display the user name as part of the menu something like Welcome John (if the user is logged in) irrespective of module or action??

 

Best Regards

John

 

 

From: web...@googlegroups.com [mailto:web2py@googlegroups.com] On Behalf Of Massimo Di Pierro
Sent: 30 September 2019 06:39
To: web2py-users
Subject: [web2py] Re: py4web Auth

 

I added a page to the documentation:

 

 

I am sure it if full of spelling errors and I am making a fool of myself (my keyboard is acting up and my mother language is not english)

Also the examples could use an independent tester as I typed them without running them.

 

Anyway I thought this was better than nothing. :-)

 

Massimo

--
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+unsubscribe@googlegroups.com.

John Bannister

unread,
Sep 30, 2019, 12:50:07 PM9/30/19
to web...@googlegroups.com

Hi Massimo,

 

Not quite what I am after. Scenario which I have is that I have a number of different models each has a number of different atctions. I have a menu defined in layout.html which is included in each view. I would like to display the logged in user name in the menu (so something like Welcome John) if the user is logged in or LOGIN if they are not.

 

I understand that I can use auth.get_user in the action to access any auth user info I need but the question is do I need to pass back the user information to each and every view for layout.html to have access to the information or is there some way to set a global/application wide variable so that can be access by all views(templates). Ideally I would like to be able to access auth.get_user() from layout.html

 

BR

John

To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.

--

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/44a408dc-40cc-4bf7-b599-05b3f2b66289%40googlegroups.com.

Massimo Di Pierro

unread,
Sep 30, 2019, 11:42:36 PM9/30/19
to web2py-users
I understand what you are  asking. Something like the ability of web2py to define stuff in a models file and it would be available to the views. Problem with that design is the overhead. With py4web we are trying to be more efficient.

There are many ways to do this:

1) create a function that returns the info you need and pass this function to the layout. For example:

def get_info(auth):
      return {... whatever you need ...}

@action('index')
@action.uses(auth)
def index():
        return dict(info=get_info(auth))

2) create a new fixture that injects data in the template

from py4web.core import Fixture
class InfoInjector(Fixture)
      def transform(self, output):
           if isinstance(output, dict) and 'info' not in output:
                output['info'] = get_info(auth)                                                    
           return output

@action('index')
@action.uses(auth, InfoInjector())
def index():
        return dict() # info is automatically injected

3) add logic directly to the template as in:

    [[from app.thisapp.common import get_info, auth]][[info = get_info(auth)]] ... [[=info]]

I like solution 2 best

On Monday, 30 September 2019 09:50:07 UTC-7, John Bannister wrote:

Hi Massimo,

 

Not quite what I am after. Scenario which I have is that I have a number of different models each has a number of different atctions. I have a menu defined in layout.html which is included in each view. I would like to display the logged in user name in the menu (so something like Welcome John) if the user is logged in or LOGIN if they are not.

To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.

--
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+unsubscribe@googlegroups.com.

John Bannister

unread,
Oct 1, 2019, 6:48:46 AM10/1/19
to web...@googlegroups.com

Thanks for the info. Have tried option 2 (which I also like the most) but problem I am having is as soon as I try to include a view i.e generic.html in the action the info is not being added to the output.

 

So

from py4web.core import Fixture

class InfoInjector(Fixture):

      def transform(self, output):

           if isinstance(output, dict) and 'info' not in output:

                output['info'] = get_info(auth)                                                    
           return output

 

@action('index')

@action.uses(auth, InfoInjector())

def index():

        message=’Hello there’   

        return dict(message=message ) # info is automatically injected I see the injected info + message

 

Output:-

{

  "info": {

    "info": {

      "email": "eudor...@gmail.com",

      "first_name": "John",

      "id": 1,

      "last_name": "Bannister",

      "username": "jab"

    }

  },

  "message": "Hello there"

}

 

 

@action('index')

@action.uses(auth, InfoInjector())

@action.uses(‘generic.html’)

 

def index():

        messate=”Hello there”   

        return dict(message=message) # info is automatically injected InfoInjector() is not called !!!!! and no info injected

 

 

 

From: web...@googlegroups.com [mailto:web...@googlegroups.com] On Behalf Of Massimo Di Pierro
Sent: 01 October 2019 05:43
To: web2py-users
Subject: Re: [web2py] Re: py4web Auth

 

I understand what you are  asking. Something like the ability of web2py to define stuff in a models file and it would be available to the views. Problem with that design is the overhead. With py4web we are trying to be more efficient.

To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.

--
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.

--

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/5ba7b3b0-4b32-42c3-a4f7-9ad46607b4c9%40googlegroups.com.

John Bannister

unread,
Oct 1, 2019, 1:18:56 PM10/1/19
to web...@googlegroups.com

Hi Massimo,

 

Got around to playing with Tags today (as per the new section you added to the py4web docs). Comments/feedback as follows:

 

As per the docs:

 

groups=Tags(db.auth_user)

groups.add(user.id, 'Dancer')

 

1: nothing is added from inside an action

2: if I add the line groups.add(1, 'Dancer') right after the groups initialization it adds the record to the auth_user_tag_default table

 

That’s about as far as I have got.

 

Some grammatical stuff on the English but it is easily understandable for those that want to understand and certainly a lot better than I could do in Italian J

 

If have also noticed looking at the auth plugins that the port from web2py hasn’t quite been finalised with things like current and storage() still in the code.

 

If you need a hand with proof reading/ correcting the docs you have done so far I am more than willing to help out.

 

Will continue to test and play and hopefully provide constructive feedback as part of the process.

 

Keep up the good work it is looking really cool !!!

 

Best Regards

John  

 

 

 

From: web...@googlegroups.com [mailto:web...@googlegroups.com] On Behalf Of Massimo Di Pierro


Sent: 01 October 2019 05:43

To: web2py-users
Subject: Re: [web2py] Re: py4web Auth

 

I understand what you are  asking. Something like the ability of web2py to define stuff in a models file and it would be available to the views. Problem with that design is the overhead. With py4web we are trying to be more efficient.

To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.

--
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.

--

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/5ba7b3b0-4b32-42c3-a4f7-9ad46607b4c9%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages