[web2py] Re: REF: Bare Ajax Login
I solved the ajax login the follwing way controllers/user.py def login(): ''' ajax login function return login form error/success message and serialized user as JSON object ''' form = SQLFORM.factory( Field('email', requires=[IS_EMAIL()]), Field('password', 'password') ) user = dict() message = '' success = None if form.accepts(request.vars, session): success = auth.login_bare(form.vars.email, form.vars.password) if success: from gluon.contrib import simplejson if not auth.is_logged_in(): return simplejson.dumps({'id': None}) user = dict([(k, v) for k, v in auth.user.iteritems() if k in 'first_name last_name email id'.split()]) user['groups'] = [row.auth_group.role for row in db(db. auth_membership.user_id == auth.user.id)( db.auth_membership.group_id == db.auth_group.id).select()] success = True; else: message = 'invalid login' from gluon.contrib import simplejson return simplejson.dumps({'user': user, 'form': str(form), 'message':message , 'success': success}) in index.html div id=login-form/div in my JavaScript lib function trapForm(target, url, success_callback) { $(target + ' form').submit(function(e) { getForm(target, url, $(this).serialize(), success_callback); e.preventDefault(); }); } function getForm(target, url, fdata, success_callback) { $.ajax({ url: url, data: fdata, method: 'post', dataType: 'json', success: function(data) { if (data.message) { $.jGrowl(data.message); // I juse jGrown instead of the build in .flash } $(target).html(data.form) trapForm(target, url, success_callback); if (data.success == true) { success_callback(data.user) } }, error: function() { $.jGrowl('getForm failed'); } }); } /** * get the login form via ajax and render it into the page */ function getLoginForm() { // load login form getForm('#login-form', localconfig.baseurl + '/user/login', undefined, function(user) { framework.this_user.update(user);// this is where I process the returned result ... // further front end actions that should be done on login follow here }); } Hope this helps other facing this problem. -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] Re: REF: Bare Ajax Login
Was fighting with the problem in 2011 and still do, how to log in with ajax? The problem is that I have a one pager app with client site js code that needs to register if the user is logged in when I login with e.g. index.html: div id=i-login-form/div js code: web2py_component(localconfig.baseurl + '/default/user.load/login', 'i-login-form') default.py unchanged from welcome app user.load {{=form}} I have not found a way to register in the js code if the login was a success or fail I modified web2py_component so that it has a callback that is executed every time the ajax call in web2py_ajax_page (via web2py_component) is completed web2py_component(localconfig.baseurl + '/default/user.load/login', 'i-login-form', undefined, undefined, function() { // do some other ajax call if the login was a success }); But this is far from ideal. The callback code must check if this is the first call and if the login was a success. Also if the login failed (e.g. an email was provided but no password) no form is returned :( Do I really have to write my own server side login methods to make this work? Any news on this? On Friday, May 24, 2013 6:14:06 AM UTC+2, software.ted wrote: In addition, auth.login_bare() seems to check only with auth_user table, if my authentication is based on LDAP it may not work. Any progress that has been made on auth.ajax_login()? On 24 May 2013 05:58, Teddy Nyambe softwa...@gmail.com javascript: wrote: Why I asked cause a 2 months or so Massimo contributed to a similar thread and this is what he wrote: Should we offer something like {{=auth.ajax_login()}} helper which submits to /user/login? If would not be difficult to write. How should it work? The guy who hd asked a question on pure Ajax login had used auth.login_bare() and from my assessment he seemed to hv challenges with it. On 24 May 2013 05:46, Teddy Nyambe softwa...@gmail.com javascript: wrote: Of course read the book, auth.login_bare() manages my sessions automatically? Will check it out thanx On 23 May 2013 20:09, Anthony abas...@gmail.com javascript: wrote: Basic authentication won't do anything with the session -- it requires sending the credentials on every request -- probably not what's desired here. Instead, the very next section in the book may help: http://www.web2py.com/book/default/chapter/09#Manual-Authentication. You can post the login credentials via Ajax and then use auth.login_bare() to handle the login. Anthony On Thursday, May 23, 2013 1:39:13 PM UTC-4, Derek wrote: You did read the book before you asked, yes? http://www.web2py.com/book/default/chapter/09#Access- Control-and-Basic-Authentication On Thursday, May 23, 2013 9:49:21 AM UTC-7, software.ted wrote: Is there a way of using a pure Ajax request to web2py authentication and create a session for a successfully logged in user? -- ... Teddy Lubasi Nyambe Opensource Zambia Lusaka, ZAMBIA Cell: +260 97 7760473 website: http://www.opensource.org.zm ~/ Human Knowledge belongs to the world! - AntiTrust Man is a tool-using animal. Without tools he is nothing, with tools he is all - Thomas Carlyle 1795-1881 /~ -- --- 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 javascript:. For more options, visit https://groups.google.com/groups/opt_out. -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] Re: REF: Bare Ajax Login
I just wanted to mention that a similar problem exist for request_reset_password, the call works, passoword is restet the email is send but there is just a blank return and I have no idea how to react on that on the client side without rewriting the web2py_ajax... routines On Thursday, April 24, 2014 12:05:10 AM UTC+2, select wrote: Was fighting with the problem in 2011 and still do, how to log in with ajax? The problem is that I have a one pager app with client site js code that needs to register if the user is logged in when I login with e.g. index.html: div id=i-login-form/div js code: web2py_component(localconfig.baseurl + '/default/user.load/login', 'i-login-form') default.py unchanged from welcome app user.load {{=form}} I have not found a way to register in the js code if the login was a success or fail I modified web2py_component so that it has a callback that is executed every time the ajax call in web2py_ajax_page (via web2py_component) is completed web2py_component(localconfig.baseurl + '/default/user.load/login', 'i-login-form', undefined, undefined, function() { // do some other ajax call if the login was a success }); But this is far from ideal. The callback code must check if this is the first call and if the login was a success. Also if the login failed (e.g. an email was provided but no password) no form is returned :( Do I really have to write my own server side login methods to make this work? Any news on this? On Friday, May 24, 2013 6:14:06 AM UTC+2, software.ted wrote: In addition, auth.login_bare() seems to check only with auth_user table, if my authentication is based on LDAP it may not work. Any progress that has been made on auth.ajax_login()? On 24 May 2013 05:58, Teddy Nyambe softwa...@gmail.com wrote: Why I asked cause a 2 months or so Massimo contributed to a similar thread and this is what he wrote: Should we offer something like {{=auth.ajax_login()}} helper which submits to /user/login? If would not be difficult to write. How should it work? The guy who hd asked a question on pure Ajax login had used auth.login_bare() and from my assessment he seemed to hv challenges with it. On 24 May 2013 05:46, Teddy Nyambe softwa...@gmail.com wrote: Of course read the book, auth.login_bare() manages my sessions automatically? Will check it out thanx On 23 May 2013 20:09, Anthony abas...@gmail.com wrote: Basic authentication won't do anything with the session -- it requires sending the credentials on every request -- probably not what's desired here. Instead, the very next section in the book may help: http://www.web2py.com/book/default/chapter/09#Manual-Authentication. You can post the login credentials via Ajax and then use auth.login_bare() to handle the login. Anthony On Thursday, May 23, 2013 1:39:13 PM UTC-4, Derek wrote: You did read the book before you asked, yes? http://www.web2py.com/book/default/chapter/09#Access- Control-and-Basic-Authentication On Thursday, May 23, 2013 9:49:21 AM UTC-7, software.ted wrote: Is there a way of using a pure Ajax request to web2py authentication and create a session for a successfully logged in user? -- ... Teddy Lubasi Nyambe Opensource Zambia Lusaka, ZAMBIA Cell: +260 97 7760473 website: http://www.opensource.org.zm ~/ Human Knowledge belongs to the world! - AntiTrust Man is a tool-using animal. Without tools he is nothing, with tools he is all - Thomas Carlyle 1795-1881 /~ -- --- 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. For more options, visit https://groups.google.com/groups/opt_out. -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] Re: REF: Bare Ajax Login
Web2py has excellent backend processing. I think the way Massimo made web2py to work supports less pure Ajax calls. I would recommend and request that core functions are made to support pure Ajax say a one page website, cause users now want to experience web apps as if they are desktop apps. On the other hand I have also been developing an app with dhtmlx framework client based and using web2py calls. Works well but don't use inbuilt cool features of web2py to process foreinstance forms. It would be cool to see how a Ajax call can be handled by say form.procesd(). Teddy On 24 Apr 2014 00:22, select falko.kra...@gmail.com wrote: I just wanted to mention that a similar problem exist for request_reset_password, the call works, passoword is restet the email is send but there is just a blank return and I have no idea how to react on that on the client side without rewriting the web2py_ajax... routines On Thursday, April 24, 2014 12:05:10 AM UTC+2, select wrote: Was fighting with the problem in 2011 and still do, how to log in with ajax? The problem is that I have a one pager app with client site js code that needs to register if the user is logged in when I login with e.g. index.html: div id=i-login-form/div js code: web2py_component(localconfig.baseurl + '/default/user.load/login', 'i-login-form') default.py unchanged from welcome app user.load {{=form}} I have not found a way to register in the js code if the login was a success or fail I modified web2py_component so that it has a callback that is executed every time the ajax call in web2py_ajax_page (via web2py_component) is completed web2py_component(localconfig.baseurl + '/default/user.load/login', 'i-login-form', undefined, undefined, function() { // do some other ajax call if the login was a success }); But this is far from ideal. The callback code must check if this is the first call and if the login was a success. Also if the login failed (e.g. an email was provided but no password) no form is returned :( Do I really have to write my own server side login methods to make this work? Any news on this? On Friday, May 24, 2013 6:14:06 AM UTC+2, software.ted wrote: In addition, auth.login_bare() seems to check only with auth_user table, if my authentication is based on LDAP it may not work. Any progress that has been made on auth.ajax_login()? On 24 May 2013 05:58, Teddy Nyambe softwa...@gmail.com wrote: Why I asked cause a 2 months or so Massimo contributed to a similar thread and this is what he wrote: Should we offer something like {{=auth.ajax_login()}} helper which submits to /user/login? If would not be difficult to write. How should it work? The guy who hd asked a question on pure Ajax login had used auth.login_bare() and from my assessment he seemed to hv challenges with it. On 24 May 2013 05:46, Teddy Nyambe softwa...@gmail.com wrote: Of course read the book, auth.login_bare() manages my sessions automatically? Will check it out thanx On 23 May 2013 20:09, Anthony abas...@gmail.com wrote: Basic authentication won't do anything with the session -- it requires sending the credentials on every request -- probably not what's desired here. Instead, the very next section in the book may help: http://www.web2py.com/book/default/chapter/09#Manual-Authentication. You can post the login credentials via Ajax and then use auth.login_bare() to handle the login. Anthony On Thursday, May 23, 2013 1:39:13 PM UTC-4, Derek wrote: You did read the book before you asked, yes? http://www.web2py.com/book/default/chapter/09#Access-Control -and-Basic-Authentication On Thursday, May 23, 2013 9:49:21 AM UTC-7, software.ted wrote: Is there a way of using a pure Ajax request to web2py authentication and create a session for a successfully logged in user? -- ... Teddy Lubasi Nyambe Opensource Zambia Lusaka, ZAMBIA Cell: +260 97 7760473 website: http://www.opensource.org.zm ~/ Human Knowledge belongs to the world! - AntiTrust Man is a tool-using animal. Without tools he is nothing, with tools he is all - Thomas Carlyle 1795-1881 /~ -- --- 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. For more options, visit https://groups.google.com/groups/opt_out. -- 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. For more options, visit
[web2py] Re: REF: Bare Ajax Login
You did read the book before you asked, yes? http://www.web2py.com/book/default/chapter/09#Access-Control-and-Basic-Authentication On Thursday, May 23, 2013 9:49:21 AM UTC-7, software.ted wrote: Is there a way of using a pure Ajax request to web2py authentication and create a session for a successfully logged in user? -- ... Teddy Lubasi Nyambe Opensource Zambia Lusaka, ZAMBIA Cell: +260 97 7760473 website: http://www.opensource.org.zm ~/ Human Knowledge belongs to the world! - AntiTrust Man is a tool-using animal. Without tools he is nothing, with tools he is all - Thomas Carlyle 1795-1881 /~ -- --- 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. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: REF: Bare Ajax Login
Basic authentication won't do anything with the session -- it requires sending the credentials on every request -- probably not what's desired here. Instead, the very next section in the book may help: http://www.web2py.com/book/default/chapter/09#Manual-Authentication. You can post the login credentials via Ajax and then use auth.login_bare() to handle the login. Anthony On Thursday, May 23, 2013 1:39:13 PM UTC-4, Derek wrote: You did read the book before you asked, yes? http://www.web2py.com/book/default/chapter/09#Access-Control-and-Basic-Authentication On Thursday, May 23, 2013 9:49:21 AM UTC-7, software.ted wrote: Is there a way of using a pure Ajax request to web2py authentication and create a session for a successfully logged in user? -- ... Teddy Lubasi Nyambe Opensource Zambia Lusaka, ZAMBIA Cell: +260 97 7760473 website: http://www.opensource.org.zm ~/ Human Knowledge belongs to the world! - AntiTrust Man is a tool-using animal. Without tools he is nothing, with tools he is all - Thomas Carlyle 1795-1881 /~ -- --- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: [web2py] Re: REF: Bare Ajax Login
Of course read the book, auth.login_bare() manages my sessions automatically? Will check it out thanx On 23 May 2013 20:09, Anthony abasta...@gmail.com wrote: Basic authentication won't do anything with the session -- it requires sending the credentials on every request -- probably not what's desired here. Instead, the very next section in the book may help: http://www.web2py.com/book/default/chapter/09#Manual-Authentication. You can post the login credentials via Ajax and then use auth.login_bare() to handle the login. Anthony On Thursday, May 23, 2013 1:39:13 PM UTC-4, Derek wrote: You did read the book before you asked, yes? http://www.web2py.com/book/**default/chapter/09#Access-** Control-and-Basic-**Authenticationhttp://www.web2py.com/book/default/chapter/09#Access-Control-and-Basic-Authentication On Thursday, May 23, 2013 9:49:21 AM UTC-7, software.ted wrote: Is there a way of using a pure Ajax request to web2py authentication and create a session for a successfully logged in user? -- ..**..** ... Teddy Lubasi Nyambe Opensource Zambia Lusaka, ZAMBIA Cell: +260 97 7760473 website: http://www.opensource.org.zm ~/ Human Knowledge belongs to the world! - AntiTrust Man is a tool-using animal. Without tools he is nothing, with tools he is all - Thomas Carlyle 1795-1881 /~ -- --- 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. For more options, visit https://groups.google.com/groups/opt_out. -- --- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: [web2py] Re: REF: Bare Ajax Login
Why I asked cause a 2 months or so Massimo contributed to a similar thread and this is what he wrote: Should we offer something like {{=auth.ajax_login()}} helper which submits to /user/login? If would not be difficult to write. How should it work? The guy who hd asked a question on pure Ajax login had used auth.login_bare() and from my assessment he seemed to hv challenges with it. On 24 May 2013 05:46, Teddy Nyambe software@gmail.com wrote: Of course read the book, auth.login_bare() manages my sessions automatically? Will check it out thanx On 23 May 2013 20:09, Anthony abasta...@gmail.com wrote: Basic authentication won't do anything with the session -- it requires sending the credentials on every request -- probably not what's desired here. Instead, the very next section in the book may help: http://www.web2py.com/book/default/chapter/09#Manual-Authentication. You can post the login credentials via Ajax and then use auth.login_bare() to handle the login. Anthony On Thursday, May 23, 2013 1:39:13 PM UTC-4, Derek wrote: You did read the book before you asked, yes? http://www.web2py.com/book/**default/chapter/09#Access-** Control-and-Basic-**Authenticationhttp://www.web2py.com/book/default/chapter/09#Access-Control-and-Basic-Authentication On Thursday, May 23, 2013 9:49:21 AM UTC-7, software.ted wrote: Is there a way of using a pure Ajax request to web2py authentication and create a session for a successfully logged in user? -- ..**..** ... Teddy Lubasi Nyambe Opensource Zambia Lusaka, ZAMBIA Cell: +260 97 7760473 website: http://www.opensource.org.zm ~/ Human Knowledge belongs to the world! - AntiTrust Man is a tool-using animal. Without tools he is nothing, with tools he is all - Thomas Carlyle 1795-1881 /~ -- --- 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. For more options, visit https://groups.google.com/groups/opt_out. -- --- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: [web2py] Re: REF: Bare Ajax Login
In addition, auth.login_bare() seems to check only with auth_user table, if my authentication is based on LDAP it may not work. Any progress that has been made on auth.ajax_login()? On 24 May 2013 05:58, Teddy Nyambe software@gmail.com wrote: Why I asked cause a 2 months or so Massimo contributed to a similar thread and this is what he wrote: Should we offer something like {{=auth.ajax_login()}} helper which submits to /user/login? If would not be difficult to write. How should it work? The guy who hd asked a question on pure Ajax login had used auth.login_bare() and from my assessment he seemed to hv challenges with it. On 24 May 2013 05:46, Teddy Nyambe software@gmail.com wrote: Of course read the book, auth.login_bare() manages my sessions automatically? Will check it out thanx On 23 May 2013 20:09, Anthony abasta...@gmail.com wrote: Basic authentication won't do anything with the session -- it requires sending the credentials on every request -- probably not what's desired here. Instead, the very next section in the book may help: http://www.web2py.com/book/default/chapter/09#Manual-Authentication. You can post the login credentials via Ajax and then use auth.login_bare() to handle the login. Anthony On Thursday, May 23, 2013 1:39:13 PM UTC-4, Derek wrote: You did read the book before you asked, yes? http://www.web2py.com/book/**default/chapter/09#Access-** Control-and-Basic-**Authenticationhttp://www.web2py.com/book/default/chapter/09#Access-Control-and-Basic-Authentication On Thursday, May 23, 2013 9:49:21 AM UTC-7, software.ted wrote: Is there a way of using a pure Ajax request to web2py authentication and create a session for a successfully logged in user? -- ..**..** ... Teddy Lubasi Nyambe Opensource Zambia Lusaka, ZAMBIA Cell: +260 97 7760473 website: http://www.opensource.org.zm ~/ Human Knowledge belongs to the world! - AntiTrust Man is a tool-using animal. Without tools he is nothing, with tools he is all - Thomas Carlyle 1795-1881 /~ -- --- 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. For more options, visit https://groups.google.com/groups/opt_out. -- --- 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. For more options, visit https://groups.google.com/groups/opt_out.