Exemplo n.º 1
0
def test_timeBeforeSession():
    TEST_TIME = time.time()
    time.sleep(1)

    s = Session.createSession()
    s.endSession()

    assert s.isSessionWithin(TEST_TIME) == True
Exemplo n.º 2
0
def test_timeAfterSession():
    s = Session.createSession()
    time.sleep(1)
    s.endSession()

    TEST_TIME = time.time()
    time.sleep(1)

    assert s.isSessionWithin(TEST_TIME) == False
Exemplo n.º 3
0
class Login:
    def __init__(self):

        self.username = None
        self.password = None
        self.session = Session()

    def fetchLoginValues(self):
        form = cgi.FieldStorage()
        self.username = form.getvalue('username')
        self.password = form.getvalue('password')
        self.session.username = self.username

    def login(self):
        try:
            self.session.database.connect()
            sql = (
                'select * from user where username = "******" and password = "******"'
                % (self.username, self.password))
            chk = self.session.database.cursor.execute(sql)
            if chk == 1L:
                checkUser = self.session.checkUserSession()
                if checkUser == 1:
                    self.session.createSession()
                    cookie = CookieGenerator()
                    cookie.genCookie(self.session.sessionId)
                    print "Content-type:text/html\r\n\r\n"
                    print("Login Successfull")
                else:
                    print "User  is already logged in."
            else:
                print "Check username or password."
        except Exception as e:
            print("Login Failed")
            print e

    def redirectToDashboard(self):
        print('<html>')
        print('  <head>')
        print(
            '    <meta http-equiv="refresh" content="0;url=http://127.0.0.1/scripts/Dashboard.py" />'
        )
        print('  </head>')
        print('</html>')
Exemplo n.º 4
0
def test_timeDuringSession():
    s = Session.createSession()
    time.sleep(1)

    TEST_TIME = time.time()
    time.sleep(1)

    s.endSession()

    assert s.isSessionWithin(TEST_TIME) == True