Exemplo n.º 1
0
def deleteAccount(environ, start_response):
    wasloggedin = login.isLoggedIn(login.getLoginToken(environ))

    conn = connectToDatabase.connect()
    c = conn.cursor()
    c.execute("DELETE FROM users WHERE userid = %s", [login.getUserId(login.getLoginToken(environ))])
    conn.commit()
    c.close()
    conn.close()

    string += genHTML.genPageHeader('EngCupid')
    string += genHTML.genMenuBar("EngCupid", [dict(link='browse.py', name='Browse', active=True)], login.getLoginToken(environ))
    string += genHTML.beginContainer()
    if wasloggedin:
        string += """\
            <div class='span12'>
              <div class="hero-unit">
                <H1>Account Deleted</H1>
                <p>Your account has been removed from our system.</p>
              </div>
            </div>
    """
    else:
        return forbidden.forbidden(environ,start_response)
    string += genHTML.endContainer()
    string += genHTML.genPageFooter()
    start_response(ok.code(), [('Content-type', 'text/html')])
    return string
Exemplo n.º 2
0
def printPage(environ, start_response):
    if not login.isLoggedIn(login.getLoginToken(environ)):
        return forbidden.forbidden(environ,start_response)
    string = ''
    qs =  parse_qs(environ['QUERY_STRING'], keep_blank_values=True)
    excepted = False
    try:
        if 'pagenum' in qs:
            pagenum = int(qs['pagenum'][0])
        else:
            pagenum = 0
    except:
        pagenum = 0
        excepted = True 
    try:
        search = qs['search'][0]
    except:
        search = ''
    responseCode = ok.code()

    string += genHTML.genPageHeader('EngCupid')
    string += genHTML.genMenuBar("EngCupid", [dict(link='browse.py', name='Browse', active=False)], login.getLoginToken(environ))
    string += genHTML.beginContainer()
    if excepted or pagenum > (countUserProfiles(search, '%', '%')-1)/10 and countUserProfiles(search, '%', '%')!= 0:
        return notFound.notFound(environ, start_response)
    else:
        if countUserProfiles(search, '%', '%') == 0:
            string +=  "<div class='span12'><div class=\"hero-unit\"><H1>No Results Found</H1><p>We're sorry but there are no users that meet your search criteria</p></div></div>"
        else:
            string += genHTML.genPagination((countUserProfiles(search, '%', '%') - 1)/10, environ['SCRIPT_NAME']+'?search='+search, pagenum)
            string += getUserProfiles(search, '%', '%', 10, pagenum)
    string += genHTML.endContainer()
    string += genHTML.genPageFooter()
    start_response(responseCode, [('Content-type', 'text/html')])
    return string
Exemplo n.º 3
0
def loginPage(environ, start_response):
    qs =  parse_qs(environ['QUERY_STRING'], keep_blank_values=True)
    loginFailure = False
    if ('username' in qs) and ('password' in qs):
        try:
            cookie = login(qs['username'][0], qs['password'][0], True)
            start_response('303 See Other',[('Set-Cookie','login_token=%s'%cookie),('Location', connectToDatabase.getDirBase())])
            cookie =  getLoginToken(environ)
            return cookie 
        except:
            loginFailure = True
    string = ''
    string += genHTML.genPageHeader('EngCupid')
    string += genHTML.genMenuBar("EngCupid", [dict(link='browse.py', name='Browse', active=True)], getLoginToken(environ))
    string += genHTML.beginContainer()
    string += """
<div class="span12">
"""
    if loginFailure:
        string += """\
  <div class="alert alert-error">
    <button class="close" data-dismiss="alert">&times;</button>
    <strong>Incorrect username or password</strong>
    You have entered a username/password combination that is not in our system, please try again
  </div>
"""
    string+= """\
  <h1>Login</h1>
  <form class="form-horizontal" method="GET" name='search' action="login.py" >
    <fieldset>
      <div class="control-group">
        <label class="control-label" for="username">Username</label>
        <div class="controls">
           <input id="username" class="input-xlarge" type="text">
        </div>
      </div>
      <div class="control-group">
        <label class="control-label" for="password" value="%(username)s">Password</label>
        <div class="controls">
           <input id="password" class="input-xlarge" type="password">
        </div>
      </div>
      <div class="form-actions">
        <button class="btn btn-primary" type="submit">Login</button>
      </div>
    </fieldset>
  </form>
""" % {'username': qs['username'] if 'username' in qs else ''}

    string += """\
</div>
"""
    string += genHTML.endContainer()
    string += genHTML.genPageFooter()
    start_response(ok.code(), [('Content-type', 'text/html')])
    return string
Exemplo n.º 4
0
def printPage(environ, start_response):
    responseCode = ok.code()
    string = ''
    string += genHTML.genPageHeader('EngCupid')
    string += genHTML.genMenuBar("EngCupid", [dict(link='browse.py', name='Browse', active=False)], login.getLoginToken(environ))
    string += genHTML.beginContainer()
    string += """\
        <div class='span12'>
          <div class="hero-unit">
            <H1>Welcome to Eng Cupid</H1>
            <p>The dating site tailor made for Engineers and Computer Scientists</p>
          </div>
        </div>
"""
    string += genHTML.endContainer()
    string += genHTML.genPageFooter()
    start_response(responseCode, [('Content-type', 'text/html')])
    return string
Exemplo n.º 5
0
def notFound(environ, start_response):
    string = ''

    string += genHTML.genPageHeader('EngCupid')
    string += genHTML.genMenuBar("EngCupid", [dict(link='browse.py', name='Browse', active=True)], login.getLoginToken(environ))
    string += genHTML.beginContainer()
    responseCode = notFound.code()
    string += """\
        <div class='span12'>
          <div class="hero-unit">
            <H1>404 :(</H1>
            <p>Sorry but that page seems not to exist</p>
          </div>
        </div>
"""
    string += genHTML.endContainer()
    string += genHTML.genPageFooter()
    start_response(responseCode, [('Content-type', 'text/html')])
    return string
Exemplo n.º 6
0
def printPage(environ, start_response):
    if not login.isLoggedIn(login.getLoginToken(environ)):
        return forbidden.forbidden(environ,start_response)
    qs =  parse_qs(environ['QUERY_STRING'], keep_blank_values=True)
    if ('userid' in qs):
        if countUserProfiles(qs['userid'], '', '') > 0:
            l = getUserInfo("SELECT * FROM users WHERE userid = %s", [qs['userid']])
        else:
            return notFound.notFound(environ,start_response)
    else:
        return notFound.notFound(environ,start_response)
    responseCode = ok.code()
    string = ''
    string += genHTML.genPageHeader('EngCupid')
    string += genHTML.genMenuBar("EngCupid", [dict(link='browse.py', name='Browse', active=False)], login.getLoginToken(environ))
    string += genHTML.beginContainer()
    string += printUser.getUserProfile(l)
    string += genHTML.endContainer()
    string += genHTML.genPageFooter()
    start_response(responseCode, [('Content-type', 'text/html')])
    return string
Exemplo n.º 7
0
def loginPage(environ, start_response):

    qs =  parse_qs(environ['QUERY_STRING'], keep_blank_values=True)
    loginFailure = False
    if ('username' in qs):
        try:
            cookie = login(qs['username'][0], qs['password'][0], True)
            start_response('303 See Other',[('Set-Cookie','login_token=%s'%cookie),('Location', connectToDatabase.getDirBase())])
            cookie =  getLoginToken(environ)
            return cookie
        except:
            loginFailure = True
    string = ''
    string += genHTML.genPageHeader('EngCupid')
    string += genHTML.genMenuBar("EngCupid", [dict(link='browse.py', name='Browse', active=True)], getLoginToken(environ))
    string += genHTML.beginContainer()
    string += """\
  <h1>Recover Password</h1>
  <form class="form-horizontal" method="GET" name='search' action="recoverPassword.py" >
    <fieldset>
      <div class="control-group">
        <label class="control-label" for="username">Username</label>
        <div class="controls">
           <input id="username" class="input-xlarge" type="text">
        </div>
      </div>
      <div class="form-actions">
        <button class="btn btn-primary" type="submit">Login</button>
      </div>
    </fieldset>
  </form>
""" % {'username': qs['username'] if 'username' in qs else ''}

    string += """\
</div>
"""
    string += genHTML.endContainer()
    string += genHTML.genPageFooter()
    start_response(ok.code(), [('Content-type', 'text/html')])
    return string
Exemplo n.º 8
0
def forbidden(environ, start_response):
    string = ''

    string += genHTML.genPageHeader('EngCupid')
    string += genHTML.genMenuBar("EngCupid", [dict(link='browse.py', name='Browse', active=True)], login.getLoginToken(environ))
    string += genHTML.beginContainer()
    responseCode = forbidden.code()
    string += """\
        <div class='span12'>
          <div class="hero-unit">
            <H1>403 Forbidden</H1>
            <p>It seems that you are trying to go somewhere you shouldn't.</p>
            <p><a class="btn btn-primary btn-large" href='index.php'>
              return to EngCupid
            </a></p>
          </div>
        </div>
"""
    string += genHTML.endContainer()
    string += genHTML.genPageFooter()
    start_response(responseCode, [('Content-type', 'text/html')])
    return string
Exemplo n.º 9
0
def deleteAccount(environ, start_response):
    loggedin = login.isLoggedIn(login.getLoginToken(environ))
    userid = ''
    qs =  parse_qs(environ['QUERY_STRING'], keep_blank_values=True)
    if loggedin:
        userid = login.getUserId(login.getLoginToken(environ))
    elif 'userid' in qs:
        userid = qs['userid']
    else:
        return forbidden.forbidden(environ,start_response)

    conn = connectToDatabase.connect()
    c = conn.cursor()
    c.execute("UPDATE FROM users SET account_status = 'Active' WHERE userid = %s", [userid])
    conn.commit()
    c.close()
    conn.close()

    string += genHTML.genPageHeader('EngCupid')
    string += genHTML.genMenuBar("EngCupid", [dict(link='browse.py', name='Browse', active=True)], login.getLoginToken(environ))
    string += genHTML.beginContainer()
    string += """\
            <div class='span12'>
              <div class="hero-unit">
                <H1>Account Deleted</H1>
                <p>Your account is now active.</p>
                <p><a class="btn btn-primary btn-large" href="login.py">
                 Login
                </a></p>
              </div>
            </div>
    """
    string += genHTML.endContainer()
    string += genHTML.genPageFooter()
    start_response(ok.code(), [('Content-type', 'text/html')])
    return string