Exemple #1
0
def login(req, username, password):
    req.content_type = 'text/html'
    # don't permit brute force password guessing:
    time.sleep(1)
    s = Session.Session(req)

    if not s.is_new():
	#TODO take the username from session
        return json.dumps({'status':True, 'username':username,
            'info':'Already logged in'})

    strout = websutil.OutputString()
    try:
        user = websutil.get_user(username, password)
    except:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType':ERR_EXCEPTION,
            'errorMessage':"",
            'errorTrace':strout.get()})  	

    if user is None:
        s.invalidate()
        return json.dumps({'status':False, 'username':"", 
            'info':'Invalid username/password'})

    s["username"] = username.lower()
    s.save()
    return json.dumps({'status':True, 'username':user,
            'info':'Succesfully logged in'})
Exemple #2
0
def login(req, username, password):
    req.content_type = 'text/html'
    # don't permit brute force password guessing:
    time.sleep(1)
    s = Session.Session(req)

    if not s.is_new():
	#TODO take the username from session
        return json.dumps({'status':True, 'username':username,
            'info':'Already logged in'})

    strout = websutil.OutputString()
    try:
        user = websutil.get_user(username, password)
    except:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType':ERR_EXCEPTION,
            'errorMessage':"",
            'errorTrace':strout.get()})  	

    if user is None:
        s.invalidate()
        return json.dumps({'status':False, 'username':"", 
            'info':'Invalid username/password'})

    s["username"] = username
    s.save()
    return json.dumps({'status':True, 'username':user,
            'info':'Succesfully logged in'})
Exemple #3
0
def login(req, username, password):

    #### BIG FAT WARNING: ####
    # If you ever try to use Vmchecker on a UserDir-type environment
    # (i.e., ~/public_html), **DON'T**.
    # It appears that mod_python tries to set a cookie with the path
    # determined by DocumentRoot. This means that the path itself
    # gets mangled and the browser doesn't send the cookie back.
    #
    # This results in the app never logging in, simply coming back
    # to the login screen.
    #
    # If you have access to the browser config, you can try and
    # manually set 'ApplicationPath' to '/' in order to circumvent
    # this.
    #### / BIG FAT WARNING ####

    req.content_type = 'text/html'
    # don't permit brute force password guessing:
    time.sleep(1)
    s = Session.Session(req)

    websutil.sanityCheckUsername(username)

    if not s.is_new():
        #TODO take the username from session
        return json.dumps({
            'status': True,
            'username': username,
            'info': 'Already logged in'
        })

    strout = websutil.OutputString()
    try:
        user = websutil.get_user(username, password)
    except:
        traceback.print_exc(file=strout)
        return json.dumps({
            'errorType': websutil.ERR_EXCEPTION,
            'errorMessage': "",
            'errorTrace': strout.get()
        })

    if user is None:
        s.invalidate()
        return json.dumps({
            'status': False,
            'username': "",
            'info': 'Invalid username/password'
        })

    s["username"] = username.lower()
    s.save()
    return json.dumps({
        'status': True,
        'username': user,
        'info': 'Succesfully logged in'
    })
Exemple #4
0
def login(username, password):
    time.sleep(1)
    strout = websutil.OutputString()
    try:
        user = websutil.get_user(username, password)
    except:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType':ERR_EXCEPTION,
            'errorMessage':"",
            'errorTrace':strout.get()})
    return json.dumps({'status':True, 'username':user,
            'info':'Succesfully logged in'})
Exemple #5
0
def login(req, username, password):
    req.content_type = "text/html"
    s = Session.Session(req)

    if not s.is_new():
        # TODO take the username from session
        return json.dumps({"status": True, "username": username, "info": "Already logged in"})

    strout = websutil.OutputString()
    try:
        user = websutil.get_user({"username": username, "password": password})
    except:
        traceback.print_exc(file=strout)
        return json.dumps({"errorType": ERR_EXCEPTION, "errorMessage": "", "errorTrace": strout.get()})

    if user is None:
        s.invalidate()
        return json.dumps({"status": False, "username": "", "info": "Invalid username/password"})

    s["username"] = username
    s.save()
    return json.dumps({"status": True, "username": user, "info": "Succesfully logged in"})
Exemple #6
0
def login(req,
          username,
          password,
          remember_me=False,
          locale=websutil.DEFAULT_LOCALE):

    websutil.install_i18n(websutil.sanityCheckLocale(locale))

    #### BIG FAT WARNING: ####
    # If you ever try to use Vmchecker on a UserDir-type environment
    # (i.e., ~/public_html), **DON'T**.
    # It appears that mod_python tries to set a cookie with the path
    # determined by DocumentRoot. This means that the path itself
    # gets mangled and the browser doesn't send the cookie back.
    #
    # This results in the app never logging in, simply coming back
    # to the login screen.
    #
    # If you have access to the browser config, you can try and
    # manually set 'ApplicationPath' to '/' in order to circumvent
    # this.
    #### / BIG FAT WARNING ####

    req.content_type = 'text/html'
    # don't permit brute force password guessing:
    time.sleep(1)
    s = Session.Session(req)

    websutil.sanityCheckUsername(username)

    strout = websutil.OutputString()

    if not s.is_new():
        try:
            s.load()
            username = s['username']
            fullname = s['fullname']
        except:
            traceback.print_exc(file=strout)
            return json.dumps({
                'errorType': websutil.ERR_EXCEPTION,
                'errorMessage':
                "Getting user info from existing session failed",
                'errorTrace': strout.get()
            })

        return json.dumps({
            'status': True,
            'username': username,
            'fullname': fullname,
            'info': 'Already logged in'
        })

    try:
        user = websutil.get_user(username, password)
    except:
        traceback.print_exc(file=strout)
        return json.dumps({
            'errorType': websutil.ERR_EXCEPTION,
            'errorMessage': "",
            'errorTrace': strout.get()
        })

    if user is None:
        s.invalidate()
        return json.dumps({
            'status': False,
            'username': "",
            'fullname': "",
            'info': _('Invalid username/password')
        })

    # Use extended session timeout if requested
    if remember_me != False:
        c = s.make_cookie()
        expiration = datetime.datetime.now()
        expiration += datetime.timedelta(
            seconds=websutil.EXTENDED_SESSION_TIMEOUT)
        c.expires = expiration.strftime("%a, %d-%b-%Y %H:%M:%S GMT")

        req.headers_out.clear()
        Cookie.add_cookie(req, c)

        s.set_timeout(websutil.EXTENDED_SESSION_TIMEOUT)

    username = username.lower()
    s["username"] = username
    s["fullname"] = user
    s.save()
    return json.dumps({
        'status': True,
        'username': username,
        'fullname': user,
        'info': 'Succesfully logged in'
    })
Exemple #7
0
def login(req, username, password, remember_me=False, locale=websutil.DEFAULT_LOCALE):

    websutil.install_i18n(websutil.sanityCheckLocale(locale))

    #### BIG FAT WARNING: ####
    # If you ever try to use Vmchecker on a UserDir-type environment
    # (i.e., ~/public_html), **DON'T**.
    # It appears that mod_python tries to set a cookie with the path
    # determined by DocumentRoot. This means that the path itself
    # gets mangled and the browser doesn't send the cookie back.
    #
    # This results in the app never logging in, simply coming back
    # to the login screen.
    #
    # If you have access to the browser config, you can try and
    # manually set 'ApplicationPath' to '/' in order to circumvent
    # this.
    #### / BIG FAT WARNING ####

    req.content_type = 'text/html'
    # don't permit brute force password guessing:
    time.sleep(1)
    s = Session.Session(req)

    websutil.sanityCheckUsername(username)

    strout = websutil.OutputString()

    if not s.is_new():
        try:
            s.load()
            username = s['username']
            fullname = s['fullname']
        except:
            traceback.print_exc(file = strout)
            return json.dumps({'errorType' : websutil.ERR_EXCEPTION,
                               'errorMessage' : "Getting user info from existing session failed",
                               'errorTrace' : strout.get()})

        return json.dumps({'status' : True,
                           'username' : username,
                           'fullname' : fullname,
                           'info' : 'Already logged in'})

    try:
        user = websutil.get_user(username, password)
    except:
        traceback.print_exc(file = strout)
        return json.dumps({'errorType' : websutil.ERR_EXCEPTION,
                           'errorMessage' : "",
                           'errorTrace' : strout.get()})

    if user is None:
        s.invalidate()
        return json.dumps({'status' : False,
                           'username' : "",
                           'fullname' : "",
                           'info':_('Invalid username/password')})

    # Use extended session timeout if requested
    if remember_me != False:
        c = s.make_cookie()
        expiration = datetime.datetime.now()
        expiration += datetime.timedelta(seconds = websutil.EXTENDED_SESSION_TIMEOUT)
        c.expires = expiration.strftime("%a, %d-%b-%Y %H:%M:%S GMT")

        req.headers_out.clear()
        Cookie.add_cookie(req, c)

        s.set_timeout(websutil.EXTENDED_SESSION_TIMEOUT)

    username = username.lower()
    s["username"] = username
    s["fullname"] = user
    s.save()
    return json.dumps({'status' : True,
                       'username' : username,
                       'fullname' : user,
                       'info' : 'Succesfully logged in'})