On Thursday, April 6, 2017 at 1:43:46 AM UTC+6:30, Massimo Di Pierro wrote:
>
> there is a pending PR that will expose an API. One approach is to do it 
> manually as follows:
>
> 1) App POSTs username/password which uses web2py auth.login_bare(....)
> 2) store the user id (and only the user id) in a session
> 3) configure web2py to store the session in an encrypted cookie so no 
> server disk IO
> 4) retrieve and user id from session and retrieve the full user from DB 
> only when needed.
>
> web3py will have built-in client and server code to handle login from apps 
> and perhaps we can backport to web2py.
>
> Massimo
>
>
> On Saturday, 1 April 2017 00:35:25 UTC-5, PK wrote:
>>
>> how can i register from mobile app rest client to web2py???
>>
>
@request.restful()
def login():
    response.view = 'generic.json'
    response.headers["Access-Control-Allow-Origin"] = '*'
    response.headers['Access-Control-Max-Age'] = 86400
    response.headers['Access-Control-Allow-Headers'] = '*'
    response.headers['Access-Control-Allow-Methods'] = '*'
    response.headers['Access-Control-Allow-Credentials'] = 'true'
    
    def POST(*args,**vars):
        if args[0]=='auth_user':
            user = auth.login_bare(vars['username'],vars['password'])
            response.cookies['mycookie'] = user['id']
            response.cookies['mycookie']['expires'] = 24 * 3600
            response.cookies['mycookie']['path'] = 
'https://ppk.pythonanywhere.com/'
            session.usrId=user['id']
            return dict(user=session.usrId)
        #return db[table_name].validate_and_insert(**vars)
        return locals()
    
    return dict(POST=POST) 
so how should i create secure cookie and after login success how should i 
 call another json data with session
@auth.requires_login()
@request.restful()
def api():
can i use auth.requires_login()
or should i get request cookie and if it was in session allow request json 
data?

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to