I am really novice in both python and web2py. My project is using angularjs for front-end, and web2py for backend as Rest Service.
I have noticed that web2py has already developed the class Auth
which is used for authentication and authorization. However, if I use Rest Api, I don't really know how to re-use this class on Rest API.
For example, I try to do ajax call to register new user:
$http.post('/myapp/authentication/register', user)
The below code does not work at all:
def register():
return dict(form=auth.register())
I have to naively insert into 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 does work out to insert new user into auth_user
table. But, when I try to use method login_bare
:
login_bare(self, username, password)
It's always failed for user registered by above method. Is there any way I need to work around on this?