示例#1
0
def user(userId):
    """Get user information"""

    u = mew.getUser(userId)
    for x in u:
        print str(x) + ":", u[x]
    print
示例#2
0
def processSignup( ch, cook_hash ):

  if "username" not in ch: return False, "badusername", "Please provide a username"
  if "password" not in ch: return False, "badpassword", "Please provide a password"

  username = ch["username"]
  password = ch["password"]
  email = ""

  if "email" in ch: email = ch["email"]

  if len( username ) == 0: return False, "badusername", "The username field is empty"
  if len( password ) == 0: return False, "badpassword","The password field is empty"

  x = mew.getUserName( username )

  if x:
    return False, "badusername", "We're sorry, but the username '" + str(username) + "' is already taken!"

  if not mew.passwordTest( password ):
    return False, "badpassword", "Passwords must be at least 7 charactesr long with numerals and mixed case or be longer than 20 characters."

  retStr = "ok"

  user = {}
  if ("userId" in cook_hash):
    u = mew.getUser( cook_hash["userId"] )

    if (u is not None) and ("type" in u) and (str(u["type"]) == "anonymous"):
      user["id"] = cook_hash["userId"]
      mew.transferUser( cook_hash["userId"], username, password )
      retStr = "anonymous"

    else:
      # In case something went really south with the userId,
      # just create one
      user = mew.createUser( username, password, email )
      userId = user["id"]
      mew.createProject( userId, "My-New-Project", "user" )
      retStr = "newuser"

  else:
    user = mew.createUser( username, password, email )
    userId = user["id"]
    mew.createProject( userId, "My-New-Project", "user" )
    retStr = "newuser"

  if ("email" in ch) and len(ch["email"]) > 0:
    mew.addemail( user["id"], ch["email"] )

  return True, retStr, user["id"]
    </body>
</html>
"""

cookie_hash = mew.getCookieHash(os.environ)

if (("userId" not in cookie_hash)
        or ("sessionId" not in cookie_hash) or (mew.authenticateSession(
            cookie_hash["userId"], cookie_hash["sessionId"]) == 0)):
    print "Location:/index"
    print
    sys.exit(0)

userId = cookie_hash["userId"]
sessionId = cookie_hash["sessionId"]
userData = mew.getUser(userId)
userName = userData["userName"]

r = mew.deactivateSession(userId, sessionId)

cookie = Cookie.SimpleCookie()
cookie["message"] = str(userName) + " logged out"

expiration = datetime.datetime.now() + datetime.timedelta(days=-1)
exp_str = expiration.strftime("%a, %d-%b-%Y %H:%M:%S PST")

if "userId" in cookie_hash:
    cookie["userId"] = cookie_hash["userId"]
    cookie["userId"]["expires"] = exp_str
    cookie["userId"]["path"] = "/"
示例#4
0
userId = None
if "userId" in cookie_hash:
    userId = cookie_hash["userId"]

msg, msgType = mew.processCookieMessage(cookie, cookie_hash)

template = mew.slurp_file("template/search.html")
nav = mew.slurp_file("template/navbar_template.html")
footer = mew.slurp_file("template/footer_template.html")
analytics = mew.slurp_file("template/analytics_template.html")

userData = {}
userId = None
if loggedInFlag:
    userData = mew.getUser(cookie_hash["userId"])
    userName = userData["userName"]
    userId = userData["id"]

    unamestr = "[" + str(userName) + "]"

    if userData["type"] == "anonymous":
        unamestr = "[" + str(userName) + "]"
        #print "Location:/register"
        #print cookie.output()
        #print
        #sys.exit(0)

if loggedInFlag:
    nav = mew.processLoggedInNavTemplate(nav, userData["userName"],
                                         userData["type"])