本文整理汇总了Python中web.setcookie函数的典型用法代码示例。如果您正苦于以下问题:Python setcookie函数的具体用法?Python setcookie怎么用?Python setcookie使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setcookie函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: GET
def GET(self):
global session_time
global session_id
web.header("Content-Type","text/html; charset=utf-8")
content = ""
showNavBar = False #Should show the navigation bar
if (get_status() == "PROTECTED"):
if check_sid(web.cookies().get('sid')):
content += "Serving current user. Please give up before creating new session.\n"
showNavBar = True
else:
content += "Serving other user in protected period.\nACCESS DENIED.\n"
else:
content += "Killing background utilities.\n"
content += os.popen("./stopall.sh").read()
content += "Genearting new session ID.\n"
session_time = time.time()
new_sid = str(random.randint(100000000, 999999999)); #sid is 9 digits integer in string
session_id = new_sid
set_status("PROTECTED")
content += "New seesion ID is " + str(new_sid) + ".\n"
content += "Status is " + get_status() + ".\n"
web.setcookie("sid", new_sid, expires=3600)
showNavBar = True
return render.new(get_status(), showNavBar, content)
开发者ID:BillWSY,项目名称:netfpga,代码行数:25,代码来源:netfpga.py
示例2: POST_login
def POST_login(self, i):
# make sure the username is valid
if not forms.vlogin.valid(i.username):
return self.error("account_user_notfound", i)
# Try to find account with exact username, failing which try for case variations.
account = accounts.find(username=i.username) or accounts.find(lusername=i.username)
if not account:
return self.error("account_user_notfound", i)
if i.redirect == "/account/login" or i.redirect == "":
i.redirect = "/"
status = account.login(i.password)
if status == 'ok':
expires = (i.remember and 3600*24*7) or ""
web.setcookie(config.login_cookie_name, web.ctx.conn.get_auth_token(), expires=expires)
raise web.seeother(i.redirect)
elif status == "account_not_verified":
return render_template("account/not_verified", username=account.username, password=i.password, email=account.email)
elif status == "account_not_found":
return self.error("account_user_notfound", i)
elif status == "account_blocked":
return self.error("account_blocked", i)
else:
return self.error("account_incorrect_password", i)
开发者ID:RaceList,项目名称:openlibrary,代码行数:27,代码来源:account.py
示例3: SetSecureCookie
def SetSecureCookie(name, value, expires, **kwargs):
timestamp = str(int(time.time()))
value = base64.b64encode(value)
sig = GenerateCookieSig(name, value, timestamp, expires)
value = '|'.join((name, value, timestamp, str(expires), sig))
web.setcookie(name, value, expires=expires, secure=True, **kwargs)
开发者ID:psnfiller,项目名称:auth,代码行数:7,代码来源:insecure_code.py
示例4: POST
def POST(self):
var = web.input()
if 'fb' in var:
xsrf = util.select_one('xsrf', where='token=$tok', vars={'tok': var.xsrf})
if xsrf is None:
raise status.ApiError('401 Unauthorized')
try:
xsrf = util.select_one('xsrf', where='token=$tok', vars={'tok': var.xsrf})
if xsrf is None:
raise status.ApiError('401 Unauthorized')
user = self.user_auth(var.email, var.pword)
if user is None:
print "this one"
raise status.ApiError('401 Unauthorized')
sess = str(uuid.uuid4())[:64]
values = {
'sess': sess,
'uid': user['id']
}
util.insert('sessions', **values)
web.setcookie('wsid_login', sess, path='/')
except AttributeError as err:
print "that one"
raise status.ApiError('401 Unauthorized (%s)' % err)
web.redirect('/')
开发者ID:AriellaLev,项目名称:whatShouldIDo,代码行数:31,代码来源:main.py
示例5: GET
def GET(self, param):
entity = model.get_model_by_name(param)
form = forms.getSearchForm(entity.exposed_search_properties())
pagination = Paginator(web.input(), entity)
display_message=web.cookies().get('display_message')
web.setcookie('display_message', '')
return render_admin.listar(form, pagination, display_message=display_message)
开发者ID:ProfessionalIT,项目名称:professionalit-webiste,代码行数:7,代码来源:manager.py
示例6: POST
def POST(self):
i = web.input(imagefile={})
assert(not i.has_key('email'))
assert(not i.has_key('password'))
if i.has_key('birthday'):
try:
i.age = self.calcAge(i.birthday)
except:
return page_helper.failed('修改失败,生日格式填写错误 ')
session = site_helper.session
if session.is_login:
if i.has_key('username'):
user_name = i.username.encode('utf-8', 'ignore')
if self.existsUsername(user_name, session.user_id):
return page_helper.failed('修改失败, 用户名 ' +user_name+ ' 已被使用')
web.setcookie('name', user_name)
site_helper.session.user_name = user_name
if i.has_key('self_domain'):
self_domain = i.self_domain.encode('utf-8', 'ignore')
if self.existsDomain(self_domain, session.user_id):
return page_helper.failed('修改失败, 域名' +self_domain+ ' 已被使用')
i.model_name = 'User'
i.model_id = session.user_id
return Update.POST(self, i, )
else:
return page_helper.redirectToLogin()
开发者ID:ajiexw,项目名称:old-zarkpy,代码行数:26,代码来源:Modify.py
示例7: GET
def GET(self, accept_str):
if accept_str in model.accept_list():
return render({'title': settings.SITE_NAME}).notaccept()
else:
model.accept_code(accept_str)
web.setcookie('accept_str', accept_str, settings.EXPIRES)
raise web.redirect('/')
开发者ID:chu888chu888,项目名称:ChuGuangming-Python-web.py-example-01,代码行数:7,代码来源:mypassword.py
示例8: GET
def GET(self):
client = web.cookies().get("client")
if client == None:
client = len(runners)
web.setcookie('client', client)
runners[client] = (Runner(randint(-5, 5), randint(-5, 5)))
开发者ID:nuance,项目名称:processing-experiments,代码行数:7,代码来源:center.py
示例9: GET
def GET(self,name): #идентификация сессии и идентификация пользователя.
print '2222', 'cdx'
web.header('Content-type', 'text/html; charset=utf-8')
con = sqlite3.connect('overhead.sqlite')
cur = con.cursor()
i = web.input()
if i: #Открыть навую сессию после идентификации пользователя
n = i.name
p = i.passw
sql = u"select * from auth_ko where user=? and passw=?"
cur.execute(sql, (n, p))
r = cur.fetchall()
if r:
rez = r[0][1]
sid = uuid.uuid4().hex
sid = str(sid)
sqlu = u"update auth_ko set sid=? where user=? and passw=?"
cur.execute(sqlu, (sid, n, p))
con.commit
web.setcookie('sid', sid, 3600)
print rez, 'sid=',sid
raise web.redirect('/cdx1') #Начата новая сессия. Переходим на следующий шаг.
else:
return render.index('Логин или пароль неверен! ')
else:
raise web.redirect('/cdn') #Сюда попал, если логин и пароль не введены.
开发者ID:AnatolK,项目名称:python_webdev,代码行数:26,代码来源:app.py
示例10: POST
def POST(self):
"""Overrides `account_login` and infogami.login to prevent users from
logging in with Open Library username and password if the
payload is json. Instead, if login attempted w/ json
credentials, requires Archive.org s3 keys.
"""
from openlibrary.plugins.openlibrary.code import BadRequest
d = simplejson.loads(web.data())
access = d.get('access', None)
secret = d.get('secret', None)
test = d.get('test', False)
# Try S3 authentication first, fallback to infogami user, pass
if access and secret:
audit = audit_accounts(None, None, require_link=True,
s3_access_key=access,
s3_secret_key=secret, test=test)
error = audit.get('error')
if error:
raise olib.code.BadRequest(error)
web.setcookie(config.login_cookie_name, web.ctx.conn.get_auth_token())
# Fallback to infogami user/pass
else:
from infogami.plugins.api.code import login as infogami_login
infogami_login().POST()
开发者ID:lukasklein,项目名称:openlibrary,代码行数:25,代码来源:account.py
示例11: POST
def POST(self):
i = web.input()
sql = "select * from myuser where name = \""+i.username.encode('utf-8','latin1')+"\""
results = db.query(sql)
if results:
err = "reg_name"
other = "OK"
return render.login(err,other)
sql = "select * from myuser where email = \""+i.email.encode('utf-8','latin1')+"\""
results = db.query(sql)
if results:
err = "reg_email"
other = "OK"
return render.login(err,other)
id = db.insert('myuser',name=i.username.encode('utf-8','latin1'),password=i.passwd.encode('utf-8','latin1'),email=i.email.encode('utf-8','latin1') )
web.setcookie('nomadicid',id, 18000)
ip = web.ctx.ip
sql = "replace into mysession (ip,id) values (" + "\"" + ip +"\"," + str(id) +")"
db.query(sql)
web.setcookie('nomadicpass', ip, 18000)
return render.welcome()
开发者ID:tianshu-secret,项目名称:nomadic,代码行数:26,代码来源:code.py
示例12: POST
def POST(self):
msg = None
i = web.input()
uid = i.get('userid')
pwd = i.get('password')
user_iter=model.get_user(uid,pwd)
user = list(user_iter)
user_info = web.ctx.session.userinfo
if user:
user_info['Name'] = user[0].username
user_info['ID'] = uid
user_info['Contact'] = user[0].contactname
user_info['UnitAddr'] = user[0].unitaddress
user_info['Tel'] = user[0].tel
redirect_url = web.ctx.session.redirecturl
#print next_page
web.ctx.session.logged_in = True
web.setcookie('backstep',-2,3600)
if redirect_url:
return web.seeother(redirect_url)
else: #default
return web.seeother('/member')
else:
msg="用户名或密码不正确"
web.setcookie('login_id',uid,3600)
return render.login()
开发者ID:overwindows,项目名称:OTM_Web,代码行数:28,代码来源:login.py
示例13: POST
def POST(self):
""" Handle login """
inp = web.input()
# FIXME: Use const for cookie lifetime and hash secret
if 'user_mail' in inp and 'user_pwd' in inp:
try:
user = User.get(
User.mail == inp.user_mail,
User.password == inp.user_pwd
)
logging.info("Login by user {}".format(user.id))
web.setcookie(
'_k',
hashlib.md5(
"{0}-{1}".format(HASH_SALT, inp.user_mail)
).hexdigest(),
360000
)
web.ctx.session.auth = 1
raise web.seeother("/admin/")
except DoesNotExist:
# User not found in DB
logging.warning("Login attempt")
raise web.seeother("/login/")
else:
# Form params not present
raise web.seeother("/login/")
开发者ID:kristiannissen,项目名称:jazz-hands,代码行数:28,代码来源:views.py
示例14: POST
def POST(self, cursor):
form = web.input(user_name=None, password=None)
pass_hash = crypt.crypt(form.password+"baa", "8tr034FhaM4qg")
cursor.execute("""
SELECT user_id FROM public.user
WHERE user_name = %s AND pass_hash = %s
;""", (form.user_name, pass_hash))
user = cursor.fetchone()
if not user:
return header(page_title="Logging in") + \
"""<p><b>Sorry, we couldn't log you in.
Did you get your password wrong?</b></p>
<form method="POST">
Username: <input name="user_name"><br>
Password: <input type="password" name="password"><br>
<input type="Submit" value="Log in">
</form>""" + footer()
else:
user_id = user[0]
auth = random.randint(1, 1000000)
cursor.execute("""
UPDATE public.user SET user_auth = %s WHERE user_id = %s;
""", (auth, user_id))
cursor.execute("""
SELECT * FROM public.user WHERE user_id = %s;
""", (user_id,))
web.setcookie("user_id", str(user_id), 3600*24*365)
web.setcookie("auth", str(auth), 3600*24*365)
web.header("Refresh", "0; /")
return "Logged in, redirecting"
开发者ID:codl,项目名称:ponyshack,代码行数:30,代码来源:ponyshack.py
示例15: GET
def GET(self):
u = web.cookies().get('username')
web.setcookie('username','logout',expires=-1)
web.setcookie('session','logout',expires=-1)
db.delete('sessions',where="username=$u",vars=locals())
raise web.seeother('/')
开发者ID:nighelles,项目名称:editr,代码行数:7,代码来源:index.py
示例16: POST
def POST(self):
# unlike the usual scheme of things, the POST is actually called
# first here
i = web.input(return_to='/')
if i.get('action') == 'logout':
web.webopenid.logout()
return web.redirect(i.return_to)
i = web.input('openid', return_to='/')
going = owevent.going_to_auth(owglobal.session.datapath,
owglobal.session.host,
i['openid'])
owglobal.server.post_event(going)
output.dbg(str(owglobal.session.host)+\
" is going to "+going.server()+" to authenticate",
self.__class__.__name__)
n = web.webopenid._random_session()
web.webopenid.sessions[n] = {'webpy_return_to': i.return_to}
c = openid.consumer.consumer.Consumer(web.webopenid.sessions[n],
web.webopenid.store)
a = c.begin(i.openid)
f = a.redirectURL(web.ctx.home, web.ctx.home + web.ctx.fullpath)
web.setcookie('openid_session_id', n)
return web.redirect(f)
开发者ID:carriercomm,项目名称:OpenWiFi,代码行数:27,代码来源:webpage.py
示例17: GET
def GET(self):
arg = web.input()
# check parameters
if('nickname' not in arg or \
'password' not in arg or \
'cpu' not in arg):
return app.debug_string
# do authentification
if(check_authentification(arg['nickname'], arg['password']) == False):
return "no authentification"
# check credential (session)
# usefull to ban people or force disconnexion
cookie = check_credential(["x"], "nickname", arg['nickname'])
if(cookie == None):
return app.debug_string
# set cookie
# warning : cookie is already saved for us in db
web.setcookie(app.cookie_name, cookie, app.cookie_age)
# save cpu power
t = app.db.transaction()
try:
app.db.update('client', client_cpu=float(arg['cpu']), \
where="client_cookie=$cookie", vars= {'cookie' : cookie})
except:
t.rollback()
else:
t.commit()
return "register"
开发者ID:ricklesauceur,项目名称:Lazy-Hamilton,代码行数:35,代码来源:client.py
示例18: GET
def GET(self):
cookie = web.cookies()
web.setcookie('user', '', 3600)
web.setcookie('color', '', 3600)
db.delete('user', where='user="{0}"'.format(cookie.user))
db.delete('data', where='user="{0}"'.format(cookie.user))
return render.bye()
开发者ID:faustinoaq,项目名称:Chat,代码行数:7,代码来源:main.py
示例19: GET
def GET(self):
"""
Clears the client cookies and returns the user to the login page.
"""
web.setcookie("token", "", -1, util.portal_ip, path=util.portal_root)
web.setcookie("tenant_id", "", -1, util.portal_ip, path=util.portal_root)
raise web.seeother(".." + util.portal_root)
开发者ID:lixmgl,项目名称:Intern_OpenStack_Swift,代码行数:7,代码来源:auth.py
示例20: POST
def POST(self):
form = web.input(form_login={})
email = form['email']
remember = form['remember']
password = form['password']
flag = _RE_EMAIL.match(email)
if flag:
email = email.strip().lower()
else:
email = email.strip()
if not email:
return '请输入用户名/Email地址'
if not password:
return '请输入'
if flag:
user = model.find_item_by_email(model.User,email)
else:
user = model.find_item_by_name(model.User,email)
if user is None:
return '用户名不存在'
elif password != user['password']:
return '密码错误'
max_age = 86400 if remember=='true' else 3600
ip = web.ctx.ip
cookie = utils.make_signed_cookie(user['id'],password,ip)
web.setcookie(utils._COOKIE_NAME,cookie,expires=max_age)
#更新用户ip
model.update_user_ip(user['id'],ip)
开发者ID:nianyuguai,项目名称:Python,代码行数:32,代码来源:blog.py
注:本文中的web.setcookie函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论