python - How to re-use Auth to register, authenticate as Rest Api in Web2py -


i novice in both python , web2py. project using angularjs front-end, , web2py backend rest service.

i have noticed web2py has developed class auth used authentication , authorization. however, if use rest api, don't know how re-use class on rest api.

for example, try ajax call register new user:

 $http.post('/myapp/authentication/register', user) 

the below code not work @ all:

def register():     return dict(form=auth.register()) 

i have naively insert auth_user table in manual manner:

def register():     username = request.vars.username     password = request.vars.password     email = request.vars.email      row = db.auth_user(username=username)     if not row:         db.auth_user.insert(username=username, password=password, email=email)      else:         raise http(409, 'username exists') 

this method work out insert new user auth_user table. but, when try use method login_bare:

 login_bare(self, username, password) 

it's failed user registered above method. there way need work around on this?

db.auth_user.insert(username=username, password=password, email=email) 

above inserting plaintext password. however, default db.auth_user.password field has crypt() validator hashes password, , hash checked upon login. typically field validators (including password field's crypt validator) run when form submitted , processed (which doesn't happen in case because not using web2py form submit registration). however, can run validators follows:

db.auth_user.validate_and_insert(username=username, password=password,                                  email=email) 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -