本文整理汇总了Python中gluon.utils.web2py_uuid方法的典型用法代码示例。如果您正苦于以下问题:Python utils.web2py_uuid方法的具体用法?Python utils.web2py_uuid怎么用?Python utils.web2py_uuid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gluon.utils
的用法示例。
在下文中一共展示了utils.web2py_uuid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: refresh_token
# 需要导入模块: from gluon import utils [as 别名]
# 或者: from gluon.utils import web2py_uuid [as 别名]
def refresh_token(self, orig_payload):
now = time.mktime(datetime.datetime.now().timetuple())
if self.verify_expiration:
orig_exp = orig_payload['exp']
if orig_exp + self.leeway < now:
# token already expired, can't be used for refresh
raise HTTP(400, u'Token already expired')
orig_iat = orig_payload.get('orig_iat') or orig_payload['iat']
if orig_iat + self.refresh_expiration_delta < now:
# refreshed too long ago
raise HTTP(400, u'Token issued too long ago')
expires = now + self.expiration
orig_payload.update(
orig_iat=orig_iat,
iat=now,
exp=expires,
hmac_key=web2py_uuid()
)
self.alter_payload(orig_payload)
return orig_payload
示例2: email_registration
# 需要导入模块: from gluon import utils [as 别名]
# 或者: from gluon.utils import web2py_uuid [as 别名]
def email_registration(self, subject, body, user):
"""
Sends and email invitation to a user informing they have been registered with the application
"""
reset_password_key = str(int(time.time())) + '-' + web2py_uuid()
link = self.url(self.settings.function,
args=('confirm_registration',), vars={'key': reset_password_key},
scheme=True)
d = dict(user)
d.update(dict(key=reset_password_key, link=link, site=current.request.env.http_host))
if self.settings.mailer and self.settings.mailer.send(
to=user.email,
subject=subject % d,
message=body % d):
user.update_record(reset_password_key=reset_password_key)
return True
return False
示例3: login_user
# 需要导入模块: from gluon import utils [as 别名]
# 或者: from gluon.utils import web2py_uuid [as 别名]
def login_user(self, user):
"""
Logins the `user = db.auth_user(id)`
"""
from gluon.settings import global_settings
if global_settings.web2py_runtime_gae:
user = Row(self.table_user()._filter_fields(user, id=True))
delattr(user, 'password')
else:
user = Row(user)
for key, value in user.items():
if callable(value) or key == 'password':
delattr(user, key)
if self.settings.renew_session_onlogin:
current.session.renew(clear_session=not self.settings.keep_session_onlogin)
current.session.auth = Storage(user=user,
last_visit=current.request.now,
expiration=self.settings.expiration,
hmac_key=web2py_uuid())
self.user = user
self.update_groups()
示例4: plaid_exchange
# 需要导入模块: from gluon import utils [as 别名]
# 或者: from gluon.utils import web2py_uuid [as 别名]
def plaid_exchange():
import urllib
import urllib2
import json
from gluon.utils import web2py_uuid
data = urllib.urlencode(dict(public_token=request.vars.public_token,
account_id=request.vars.account_id,
client_id=PLAID_CLIENT_ID,
secret=PLAID_SECRET))
exchange = json.loads(urllib2.urlopen(PLAID_EXCHANGE_URL,
data=data).read())
session.payment_tokens = dict(
stripe_bank_account_token=exchange.get('stripe_bank_account_token'),
transaction_token=web2py_uuid())
response.headers['Content-Type'] = 'application/json'
return json.dumps(dict(institution=request.vars.institution.get('name'),
name=request.vars.account.get('name'),
transaction_token=session.payment_tokens['transaction_token']))
示例5: login_user
# 需要导入模块: from gluon import utils [as 别名]
# 或者: from gluon.utils import web2py_uuid [as 别名]
def login_user(self, user):
"""
Logins the `user = db.auth_user(id)`
"""
from gluon.settings import global_settings
if global_settings.web2py_runtime_gae:
user = Row(self.table_user()._filter_fields(user, id=True))
delattr(user, 'password')
else:
user = Row(user)
for key in list(user.keys()):
value = user[key]
if callable(value) or key == 'password':
delattr(user, key)
if self.settings.renew_session_onlogin:
current.session.renew(clear_session=not self.settings.keep_session_onlogin)
current.session.auth = Storage(user=user,
last_visit=current.request.now,
expiration=self.settings.expiration,
hmac_key=web2py_uuid())
self.user = user
self.update_groups()
示例6: refresh_token
# 需要导入模块: from gluon import utils [as 别名]
# 或者: from gluon.utils import web2py_uuid [as 别名]
def refresh_token(self, orig_payload):
now = time.mktime(datetime.datetime.utcnow().timetuple())
if self.verify_expiration:
orig_exp = orig_payload['exp']
if orig_exp + self.leeway < now:
# token already expired, can't be used for refresh
raise HTTP(400, u'Token already expired')
orig_iat = orig_payload.get('orig_iat') or orig_payload['iat']
if orig_iat + self.refresh_expiration_delta < now:
# refreshed too long ago
raise HTTP(400, u'Token issued too long ago')
expires = now + self.refresh_expiration_delta
orig_payload.update(
orig_iat=orig_iat,
iat=now,
exp=expires,
hmac_key=web2py_uuid()
)
self.alter_payload(orig_payload)
return orig_payload
示例7: login_user
# 需要导入模块: from gluon import utils [as 别名]
# 或者: from gluon.utils import web2py_uuid [as 别名]
def login_user(self, user):
"""
Logins the `user = db.auth_user(id)`
"""
if False: # FIX THIS global_settings.web2py_runtime_gae:
user = Row(self.table_user()._filter_fields(user, id=True))
delattr(user, 'password')
else:
user = Row(user)
for key, value in user.items():
if callable(value) or key == 'password':
delattr(user, key)
if self.settings.renew_session_onlogin:
current.session.renew(clear_session=not self.settings.keep_session_onlogin)
current.session.auth = Storage(user=user,
last_visit=current.request.now,
expiration=self.settings.expiration,
hmac_key=web2py_uuid())
self.user = user
self.update_groups()
示例8: login_user
# 需要导入模块: from gluon import utils [as 别名]
# 或者: from gluon.utils import web2py_uuid [as 别名]
def login_user(self, user):
"""
Logins the `user = db.auth_user(id)`
"""
from gluon.settings import global_settings
if global_settings.web2py_runtime_gae:
user = Row(self.table_user()._filter_fields(user, id=True))
delattr(user,'password')
else:
user = Row(user)
for key, value in user.items():
if callable(value) or key=='password':
delattr(user,key)
if self.settings.renew_session_onlogin:
current.session.renew(clear_session=not self.settings.keep_session_onlogin)
current.session.auth = Storage(
user = user,
last_visit=current.request.now,
expiration=self.settings.expiration,
hmac_key=web2py_uuid())
self.user = user
self.update_groups()
示例9: _create_id
# 需要导入模块: from gluon import utils [as 别名]
# 或者: from gluon.utils import web2py_uuid [as 别名]
def _create_id(self):
return long(web2py_uuid().replace('-',''),16)
示例10: saml2_handler
# 需要导入模块: from gluon import utils [as 别名]
# 或者: from gluon.utils import web2py_uuid [as 别名]
def saml2_handler(session, request, config_filename = None):
config_filename = config_filename or os.path.join(request.folder,'private','sp_conf')
client = Saml2Client(config_file = config_filename)
idps = client.metadata.with_descriptor("idpsso")
entityid = idps.keys()[0]
bindings = [BINDING_HTTP_REDIRECT, BINDING_HTTP_POST]
binding, destination = client.pick_binding(
"single_sign_on_service", bindings, "idpsso", entity_id=entityid)
if request.env.request_method == 'GET':
binding = BINDING_HTTP_REDIRECT
elif request.env.request_method == 'POST':
binding = BINDING_HTTP_POST
if not request.vars.SAMLResponse:
req_id, req = client.create_authn_request(destination, binding=binding)
relay_state = web2py_uuid().replace('-','')
session.saml_outstanding_queries = {req_id: request.url}
session.saml_req_id = req_id
http_args = client.apply_binding(binding, str(req), destination,
relay_state=relay_state)
return {'url':dict(http_args["headers"])['Location']}
else:
relay_state = request.vars.RelayState
req_id = session.saml_req_id
unquoted_response = request.vars.SAMLResponse
res = {}
try:
data = client.parse_authn_request_response(
unquoted_response, binding, session.saml_outstanding_queries)
res['response'] = data if data else {}
except Exception as e:
import traceback
res['error'] = traceback.format_exc()
return res
示例11: compute_uuid
# 需要导入模块: from gluon import utils [as 别名]
# 或者: from gluon.utils import web2py_uuid [as 别名]
def compute_uuid(self):
self._uuid = '%s/%s.%s.%s' % (
self.application,
self.client.replace(':', '_'),
self.now.strftime('%Y-%m-%d.%H-%M-%S'),
web2py_uuid())
return self._uuid
示例12: _update_session_user
# 需要导入模块: from gluon import utils [as 别名]
# 或者: from gluon.utils import web2py_uuid [as 别名]
def _update_session_user(self, user):
if global_settings.web2py_runtime_gae:
user = Row(self.table_user()._filter_fields(user, id=True))
delattr(user, self.settings.password_field)
else:
user = Row(user)
for key in list(user.keys()):
value = user[key]
if callable(value) or key == self.settings.password_field:
delattr(user, key)
current.session.auth = Storage(user=user,
last_visit=current.request.now,
expiration=self.settings.expiration,
hmac_key=web2py_uuid())
return user
示例13: get_or_create_key
# 需要导入模块: from gluon import utils [as 别名]
# 或者: from gluon.utils import web2py_uuid [as 别名]
def get_or_create_key(filename=None, alg='sha512'):
request = current.request
if not filename:
filename = os.path.join(request.folder, 'private', 'auth.key')
if os.path.exists(filename):
key = open(filename, 'r').read().strip()
else:
key = alg + ':' + web2py_uuid()
open(filename, 'w').write(key)
return key
示例14: __str__
# 需要导入模块: from gluon import utils [as 别名]
# 或者: from gluon.utils import web2py_uuid [as 别名]
def __str__(self):
"""
Encrypted self.password and caches it in self.crypted.
If self.crypt.salt the output is in the format <algorithm>$<salt>$<hash>
Try get the digest_alg from the key (if it exists)
else assume the default digest_alg. If not key at all, set key=''
If a salt is specified use it, if salt is True, set salt to uuid
(this should all be backward compatible)
Options:
key = 'uuid'
key = 'md5:uuid'
key = 'sha512:uuid'
...
key = 'pbkdf2(1000,64,sha512):uuid' 1000 iterations and 64 chars length
"""
if self.crypted:
return self.crypted
if self.crypt.key:
if ':' in self.crypt.key:
digest_alg, key = self.crypt.key.split(':', 1)
else:
digest_alg, key = self.crypt.digest_alg, self.crypt.key
else:
digest_alg, key = self.crypt.digest_alg, ''
if self.crypt.salt:
if self.crypt.salt is True:
salt = str(web2py_uuid()).replace('-', '')[-16:]
else:
salt = self.crypt.salt
else:
salt = ''
hashed = simple_hash(self.password, key, salt, digest_alg)
self.crypted = '%s$%s$%s' % (digest_alg, salt, hashed)
return self.crypted
示例15: test_web2py_uuid
# 需要导入模块: from gluon import utils [as 别名]
# 或者: from gluon.utils import web2py_uuid [as 别名]
def test_web2py_uuid(self):
from uuid import UUID
self.assertTrue(UUID(web2py_uuid()))