本文整理汇总了Python中meeplib.get_user函数的典型用法代码示例。如果您正苦于以下问题:Python get_user函数的具体用法?Python get_user怎么用?Python get_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_user函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_user
def create_user(self, environ, start_response):
# get cookie if there is one
try:
cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
username = cookie["username"].value
except:
username = ''
user = meeplib.get_user(username)
if user is not None:
headers = [('Content-type', 'text/html')]
headers.append(('Location', '/'))
start_response("302 Found", headers)
return ["You must be logged out to use that feature."]
headers = [('Content-type', 'text/html')]
print environ['wsgi.input']
form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
try:
username = form['username'].value
except KeyError:
username = ''
try:
password = form['password'].value
except KeyError:
password = ''
s=[]
##if we have username and password
if username != '':
user = meeplib.get_user(username)
## user already exists
if user is not None:
s.append('''Creation Failed! <br>
User already exists, please use a different username.<p>''')
## user doesn't exist but they messed up the passwords
elif password == '':
s.append('''Creation Failed! <br>
Please fill in the Password field<p>''')
else:
u = meeplib.User(username, password)
meeplib.save_state()
## send back a redirect to '/'
k = 'Location'
v = '/'
headers.append((k, v))
cookie_name, cookie_val = meepcookie.make_set_cookie_header('username',username)
headers.append((cookie_name, cookie_val))
start_response('302 Found', headers)
s.append(render_page("create_user.html", username=username))
return [''.join(s)]
示例2: reply_action
def reply_action(self, environ, start_response):
print environ["wsgi.input"]
form = cgi.FieldStorage(fp=environ["wsgi.input"], environ=environ)
post = form["post"].value
# username = 'aLlama'
cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
username = cookie["username"].value
user = meeplib.get_user(username)
new_message = meeplib.Message(post, user)
thread_id = int(form["thread_id"].value)
t = meeplib.get_thread(thread_id)
t.add_post(new_message)
meeplib.save()
headers = [("Content-type", "text/html")]
headers.append(("Location", "/m/list"))
start_response("302 Found", headers)
return ["reply added"]
示例3: reply
def reply(self, environ, start_response):
print "enter reply"
username = check_cookie(environ)
user = meeplib.get_user(username)
if user is None:
headers = [('Content-type', 'text/html')]
headers.append(('Location', '/'))
start_response("302 Found", headers)
return ["log in to use that feature"]
headers = [('Content-type', 'text/html')]
form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
thread_id = int(form['thread_id'].value)
t = meeplib.get_thread(thread_id)
s = []
try:
post = form['post'].value
except KeyError:
post = ''
if post != '':
new_message = meeplib.Message(post, user)
t.add_post(new_message)
meeplib.save_state()
headers.append(('Location','/m/list'))
start_response("302 Found", headers)
s.append(render_page("reply.html", thread=t))
print "exit reply"
return ["".join(s)]
示例4: index
def index(self, environ, start_response):
start_response("200 OK", [("Content-type", "text/html")])
# get cookie if there is one
try:
cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
username = cookie["username"].value
print "Username = %s" % username
except:
print "session cookie not set! defaulting username"
username = ""
user = meeplib.get_user(username)
print "User = %s" % user
if user is None:
s = [
"""<h1>Welcome <i style = "color:red;">Human</i>!</h1><h2>Please Login or create an account.</h2>
<form action='login' method='POST'>
Username:<input type='text' name='username'><br>
Password:<input type='password' name='password'> <br>
<input type='submit' value='Login'></form>
<p>Don't have an account? Create a user <a href='/create_user'>here</a>"""
]
elif user is not None:
s = [
"""%s logged in!<p><a href='/m/add_message'>Add a Message</a><p><a href='/create_user'>Create a User</a><p><a href='/logout'>Log out</a><p><a href='/m/list'>Show All Messages</a>"""
% (username,)
]
return s
示例5: login
def login(self, environ, start_response):
username = 'sessionuser'
session_cookie = str(uuid.uuid4())
username=str(username)
cur.execute('INSERT INTO sessions (username, cookie) VALUES (?, ?)', (username, session_cookie))
con.commit()
print "THE COOKIE",session_cookie
usernameDB=session_get(cur,session_cookie)
print "THE USERNAMEDB ",usernameDB
# hard code the username for now; this should come from Web input!
# retrieve user
user = meeplib.get_user(username)
# set content-type
headers = [('Content-type', 'text/html')]
#cookies
cookie_name, cookie_val = meepcookie.make_set_cookie_header('username',session_cookie)
headers.append((cookie_name, cookie_val))
# send back a redirect to '/'
k = 'Location'
v = '/'
headers.append((k, v))
start_response('302 Found', headers)
return "no such content"
示例6: delete_message_action
def delete_message_action(self, environ, start_response):
# get cookie if there is one
try:
cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
username = cookie["username"].value
#print "Username = %s" % username
except:
#print "session cookie not set! defaulting username"
username = ''
user = meeplib.get_user(username)
if user is None:
headers = [('Content-type', 'text/html')]
headers.append(('Location', '/'))
start_response("302 Found", headers)
return ["You must be logged in to use that feature."]
print environ['wsgi.input']
form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
thread_id = int(form['thread_id'].value)
post_id = int(form['post_id'].value)
t = meeplib.get_thread(thread_id)
post = t.get_post(post_id)
t.delete_post(post)
meeplib.save_state()
headers = [('Content-type', 'text/html')]
headers.append(('Location', '/m/list'))
start_response("302 Found", headers)
return["post deleted"]
示例7: add_message_action
def add_message_action(self, environ, start_response):
if self.username is None:
headers = [('Content-type', 'text/html')]
start_response("302 Found", headers)
return ["You must be logged in to use this feature <p><a href='/login'>Log in</a><p><a href='/m/list'>Show messages</a>"]
print environ['wsgi.input']
form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
title = form['title'].value
message = form['message'].value
parent = int(form['parent_id'].value)
user = meeplib.get_user(self.username)
new_message = meeplib.Message(title, message, user, parent)
with con:
cur.execute("INSERT INTO Messages (ID, Title, Post, Author, Parent) VALUES (?, ?, ?, ?, ?)", (new_message.id, title, message, self.username, parent))
con.commit()
#meeplib.save()
headers = [('Content-type', 'text/html')]
headers.append(('Location', '/m/list'))
start_response("302 Found", headers)
return ["message added"]
示例8: logout
def logout(self, environ, start_response):
# get cookie if there is one
try:
cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
username = cookie["username"].value
#print "Username = %s" % username
except:
#print "session cookie not set! defaulting username"
username = ''
user = meeplib.get_user(username)
if user is None:
headers = [('Content-type', 'text/html')]
headers.append(('Location', '/'))
start_response("302 Found", headers)
return ["You must be logged in to use that feature."]
headers = [('Content-type', 'text/html')]
# send back a redirect to '/'
k = 'Location'
v = '/'
headers.append((k, v))
cookie_name, cookie_val = meepcookie.make_set_cookie_header('username','')
headers.append((cookie_name, cookie_val))
start_response('302 Found', headers)
return "no such content"
示例9: login
def login(self, environ, start_response):
# hard code the username for now; this should come from Web input!
username = 'test'
# retrieve user
user = meeplib.get_user(username)
# set content-type
headers = [('Content-type', 'text/html')]
cookie_name, cookie_val = \
meepcookie.make_set_cookie_header('username',
user.username)
print "setting cookie!!!"
headers.append((cookie_name, cookie_val))
# send back a redirect to '/'
k = 'Location'
v = '/'
headers.append((k, v))
start_response('302 Found', headers)
return "no such content"
示例10: add_message_action
def add_message_action(self, environ, start_response):
print environ['wsgi.input']
form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
title = form['title'].value
message = form['message'].value
pID = form['pID'].value
username = meeplib.get_curr_user()
user = meeplib.get_user(username)
conn = sqlite3.connect('meep.db')
c = conn.cursor()
c.execute("INSERT INTO Message VALUES('" + title + "', '" + message + "', '" + username + "', '" + pID + "')")
conn.commit()
#new_message = meeplib.Message(title, message, user, pID)
headers = [('Content-type', 'text/html')]
headers.append(('Location', '/m/list'))
start_response("302 Found", headers)
#SaveMessages()
if(pID != '!'):
return ["Message Added"]
else:
return ["Reply Added"]
示例11: add_message_topic_action
def add_message_topic_action(self, environ, start_response):
form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
topicId = form['topicid'].value
topic = meeplib.get_topic(int(topicId))
title = form['title'].value
message = form['message'].value
cookie = environ.get('HTTP_COOKIE', '')
username = meepcookie.load_username(cookie)
print username
user = meeplib.get_user(username)
print user
if username != "":
#print title, message, user
new_message = meeplib.Message(title, message, user)
topic.add_message(new_message)
print "Message added to topic" + topicId
headers = [('Content-type', 'text/html')]
headers.append(('Location', '/m/topics/view?id=%d' % (topic.id)))
start_response("302 Found", headers)
return ["message added to topic"]
else:
headers = [('Content-type', 'text/html')]
headers.append(('Location', '/login'))
start_response("302 Found", headers)
return ["session expired"]
示例12: add_topic_action
def add_topic_action(self, environ, start_response):
print environ['wsgi.input']
form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
title = form['title'].value
msgtitle = form['msgtitle'].value
message = form['message'].value
cookie = environ.get('HTTP_COOKIE', '')
username = meepcookie.load_username(cookie)
if username == "":
headers = [('Content-type', 'text/html')]
headers.append(('Location', '/login'))
start_response("302 Found", headers)
return ["session ended"]
user = meeplib.get_user(username)
new_message = meeplib.Message(msgtitle, message, user)
new_topic = meeplib.Topic(title, new_message, user)
headers = [('Content-type', 'text/html')]
headers.append(('Location', '/m/list_topics'))
start_response("302 Found", headers)
return ["topic added"]
示例13: authHandler
def authHandler(self, environ):
try:
cookie = Cookie.SimpleCookie(environ["HTTP_COOKIE"])
username = cookie["username"].value
return meeplib.get_user(username)
except:
return None
示例14: create_user
def create_user(self, environ, start_response):
print "enter create user"
username = check_cookie(environ)
user = meeplib.get_user(username)
if user is not None:
headers = [('Content-type', 'text/html')]
headers.append(('Location', '/'))
start_response("302 Found", headers)
return ["log out to use that feature"]
headers = [('Content-type', 'text/html')]
form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
try:
username = form['username'].value
except KeyError:
username = ''
try:
password = form['password'].value
except KeyError:
password = ''
s=[]
##if we have username and password
if username != '':
user = meeplib.get_user(username)
## user already exists
if user is not None:
s.append('''user already exists; <br>
please use a different username.<p>''')
## user doesn't exist but they messed up the passwords
elif password == '':
s.append('''enter a password <br/>''')
else:
u = meeplib.User(username, password)
meeplib.save_state()
## send back a redirect to '/'
k = 'Location'
v = '/'
headers.append((k, v))
cookie_name, cookie_val = meepcookie.make_set_cookie_header('username',username)
headers.append((cookie_name, cookie_val))
start_response('302 Found', headers)
s.append(render_page("create_user.html", username=username))
print "exit create user"
return [''.join(s)]
示例15: alter_message_action
def alter_message_action(self, environ, start_response):
post = (environ.get('REQUEST_METHOD') == 'POST')
if post:
form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
else:
form = parse_qs(environ['QUERY_STRING'])
"""
try:
form = cgi.FieldStorage(fp=environ['wsgi.input'], environ=environ)
#params = dict([part.split('=') for part in environ['QUERY_STRING'].split('&')])
#msgId = int(params['id'])
except:
headers = [('Content-type', 'text/html')]
start_response("200 OK", headers)
return ["Error Processing provided ID"]
id = int(form['id'].value)
action = form['bttnSubmit'].value
"""
print 'post %s' % (post,)
id = int(self.get_value(form,post,'id',''))
action = self.get_value(form,post,'bttnSubmit','')
msg = meeplib.get_message(id)
error = False
errorMsg = ""
response = "200 OK"
headers = [('Content-type', 'text/html')]
u = self.getUser(environ)
if u == None:
error = True
errorMsg = """You must be logged in to proceed."""
if msg == None:
error = True
errorMsg = """Message id: %d could not be found.""" % (id,)
elif action == "Delete":
if msg.author.username == u.username:
meeplib.delete_message(msg)
response = "302 Found"
headers.append(('Location', '/'))
errorMsg = "message removed"
else:
errorMsg = "You cannot delete another user's post."
elif action == "Reply":
title = ""
message = form['replyText'].value
user = meeplib.get_user(u.username)
new_message = meeplib.Message(title, message, user, True)
msg.add_reply(new_message)
response = "302 Found"
headers.append(('Location', '/'))
errorMsg = "message replied"
start_response(response, headers)
return [errorMsg]