'Authenticate the current user with the given db, login and
password. If successful, store the authentication parameters in the
current session and request.
:param uid: If not None, that user id will be used instead the login
to authenticate the user.'

def authenticate(self, db, login=None, password=None, uid=None):

    if (uid is None):
        wsgienv = request.httprequest.environ
        env = dict(base_location=request.httprequest.url_root.rstrip('/'), HTTP_HOST=wsgienv['HTTP_HOST'], REMOTE_ADDR=wsgienv['REMOTE_ADDR'])
        uid = dispatch_rpc('common', 'authenticate', [db, login, password, env])
    else:
        security.check(db, uid, password)
    self.db = db
    self.uid = uid
    self.login = login
    self.password = password
    request.uid = uid
    request.disable_db = False
    if uid:
        self.get_context()
    return uid
