During registration I want to check on the fly, if login chosen by the user is already in use or is it not in db and available to be used.
def ajaxuserexist(): username = request.vars.values()[0] query = (db.auth_user.login==username) numres = db(query).count() if numres > 0 : return 'yes' else: return 'no' When I test it on any other table that doesn't have prefix auth_ then the above code works, but unfortunatelly I need to test auth_user table :-( On 30 Cze, 21:19, Chris S <sanders.ch...@gmail.com> wrote: > Probably a dumb question, but what are you checking the user against? > > Both my and your example above are checking for username and you > didn't define a username in your auth_user. > > Your query then is not working as: > > def userexist(emailcheck): > if db(db.auth_user.email==emailcheck).count() > 0: > return 'yes' > else: > return 'no' > > I know I've returned searches on auth_user it's no different than > other tables. Just gotta find whey your getting no results. Might > help if you post the exact search code that goes with the above > auth_user and the error message that's generated. > > On Jun 30, 2:12 pm, elfuego1 <elfue...@gmail.com> wrote: > > > Since I had added some fields (and intend to customize it further) to > > my auth_user table the code for auth_user in db.py looks like that: > > > from gluon.tools import * > > auth=Auth(globals(),db) > > > db.define_table('auth_user', > > SQLField('login', 'string', length=50, default=''), > > SQLField('password', 'password', length=512, readable=False, > > label='Password'), > > SQLField('registration_key', length=512, default= '', > > writable=False, readable=False), > > SQLField('reset_password_key', length=512, default='', > > writable=False, readable=False), > > SQLField('first_name', length=128,default=''), > > SQLField('last_name', length=128,default=''), > > SQLField('email', length=128,default='', unique=True), > > SQLField('phone', 'string', length=30, default=''), > > ) > > > On 30 Cze, 20:59, Chris S <sanders.ch...@gmail.com> wrote: > > > > And you've defined auth in db.py with: > > > > from gluon.tools import Auth > > > auth = Auth(globals(), db) > > > auth.define_tables() > > > > I've done searches on auth_user before... I think. > > > > On Jun 30, 1:44 pm, elfuego1 <elfue...@gmail.com> wrote: > > > > > Unfortunatelly it doesn't. > > > > I can access any other table that's available through my application > > > > but I can't get any value out of auth_user table. > > > > Is it somehow protected? > > > > Do I need to add some extra piece of code to expose them in my > > > > application in order to be able to acqiure any value out of them? > > > > > Desperate searcher. > > > > > On 30 Cze, 06:25, Chris S <sanders.ch...@gmail.com> wrote: > > > > > > I don't guess I follow. Isn't that the same as: > > > > > > def userexist(namecheck): > > > > > if db(db.auth_user.username==namecheck).count() > 0: > > > > > return 'yes' > > > > > else: > > > > > return 'no' > > > > > > So I"m saying your querry should be: > > > > > query = (db.auth_user.username==username) > > > > > > Hope that helps > > > > > > On Jun 29, 5:34 pm, elfuego1 <elfue...@gmail.com> wrote: > > > > > > > Hello, > > > > > > > On this page:http://web2pyslices.com/main/slices/take_slice/53Ihave > > > > > > found a great pice of code which allows to check on the fly if > > > > > > there > > > > > > is an exact value already in database. > > > > > > > Oryginal code: > > > > > > > def ajaxuserexist(): > > > > > > username = request.vars.values()[0] > > > > > > query = db.users.name.like(username) > > > > > > numres = db(query).count() > > > > > > if numres > 0 : > > > > > > return 'yes' > > > > > > > return 'no' > > > > > > > But when I try to implement the same solution on auth_user table for > > > > > > login column it stops working: > > > > > > > query = db.auth_users.login.like(username) > > > > > > > Do you know some solution/workaround to this problem? > > > > > > > Best regards.