本文整理汇总了Python中models.Token.save方法的典型用法代码示例。如果您正苦于以下问题:Python Token.save方法的具体用法?Python Token.save怎么用?Python Token.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Token
的用法示例。
在下文中一共展示了Token.save方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: forward_token
# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import save [as 别名]
def forward_token(request, token_str=None, **kwargs):
kwargs['extra_context'] = {}
error = None
token = get_object_or_404(Token, token=token_str)
user_tokens = get_tokens_from_cookie(request)
if not token.can_forward:
error = _("Apologies! This token can not be forwarded.")
else:
if request.user.is_staff:
pass
elif not token.token in user_tokens:
error = _("Apologies! You are not allowed to forward this token.")
kwargs['extra_context']['token'] = token
kwargs['extra_context']['error'] = error
if not error:
if request.method == 'POST':
form = ForwardProtectedURLForm(token, request.POST)
if form.is_valid():
if token.forward_count:
token.forward_count = token.forward_count - len(form.cleaned_data['emails'])
token.save()
for email in form.cleaned_data['emails']:
forwarded_token = Token( url=token.url, valid_until=token.valid_until, forward_count=0, email=email )
forwarded_token.save()
forwarded_token.send_token_email()
return HttpResponseRedirect(reverse('token_list'))
else:
form = ForwardProtectedURLForm(token)
kwargs['extra_context']['form'] = form
return direct_to_template(request, template='token_auth/forward_token.html', **kwargs)
示例2: save_token
# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import save [as 别名]
def save_token(token, request, *args, **kwargs):
user = request.user
toks = Token.objects(
client_id=request.client.client_id,
user_id=user.id
)
# make sure that every client has only one token connected to a user
for t in toks:
t.delete()
expires_in = token.pop('expires_in')
expires = datetime.utcnow() + timedelta(seconds=expires_in)
tok = Token(
access_token=token['access_token'],
refresh_token=token['refresh_token'],
token_type=token['token_type'],
_scopes=token['scope'],
expires=expires,
client_id=request.client.client_id,
user_id=user.id,
user=user
)
tok.save()
return tok
示例3: consumer_create
# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import save [as 别名]
def consumer_create(request):
if request.method == "POST":
form = ConsumerCreateForm(request.POST)
if form.is_valid():
consumer = Consumer()
consumer.name = form.cleaned_data['name']
consumer.description = form.cleaned_data['description']
consumer.user_id = request.user.username
consumer.refresh_key_secret()
consumer.save()
token = Token()
token.key = Token.generate_token()
token.secret = Token.generate_token()
token.consumer = consumer
token.user = request.user.username
token.type = 'A'
token.save()
return HttpResponseRedirect('/accounts/profile')
else:
form = ConsumerCreateForm()
params = {'form': form}
return render_to_response('oauth/consumer_form.tpl', params,
context_instance=RequestContext(request))
示例4: email_key
# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import save [as 别名]
def email_key(user):
token = Token(key=registration_key(),
email=user.email)
g = Global.objects()[0]
g.n_tokens += 1
g.save()
token.save()
body = "Hey! Create an account by clicking on the link below:"
body += "localhost:5000/createAccount?accountEmail={0}&signupToken={1}".format(user.email, token.key)
send_email("Lsten.fm, all the music.", body, user.email)
示例5: save_token
# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import save [as 别名]
def save_token(self, session, user):
uid = user.username
try:
token = Token.objects.get(uid=uid, user=user)
except Exception:
token = Token(uid=uid, user=user)
token.access_token = session.access_token
token.expires = session.expires
token.save()
return token
示例6: _make_token_with_timestamp
# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import save [as 别名]
def _make_token_with_timestamp(self, user, timestamp):
from django.utils.hashcompat import sha_constructor
hash = sha_constructor(settings.SECRET_KEY + unicode(user.id) +
user.password +
unicode(timestamp)).hexdigest()[::2]
self.delete_token(user)
token = Token(user = user, hash = hash)
token.save()
return hash
示例7: CreateToken
# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import save [as 别名]
def CreateToken (house_id, protocol='http://', idp=''):
try:
video = Video.objects.get(house_id=house_id)
except:
return ''
token = Token()
token.protocol = protocol
token.idp_code = idp
token.expiration = datetime.now() + timedelta(0,7200)
token.token = _get_md5_hash(house_id)
token.video = video
token.save()
return token.token
示例8: createProject
# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import save [as 别名]
def createProject(request):
pd = ocpcaproj.OCPCAProjectsDB()
if request.method == 'POST':
if 'createproject' in request.POST:
form = ProjectForm(request.POST)
# RBRM I think this is not right. Omit and delete by 8/1. 6/9/15
# # restrict datasets to user visible fields
# form.fields['dataset'].queryset = Dataset.objects.filter(user_id=request.user.id) | Dataset.objects.filter(public=1)
if form.is_valid():
new_project=form.save(commit=False)
new_project.user_id=request.user.id
if request.POST.get('legacy') == 'yes':
new_project.ocp_version='0.0'
else:
new_project.ocp_version=OCP_VERSION
new_project.schema_version=SCHEMA_VERSION
new_project.save()
try:
# create a database when not linking to an existing databases
if not request.POST.get('nocreate') == 'on':
pd.newOCPCAProject( new_project.project_name )
if 'token' in request.POST:
tk = Token ( token_name = new_project.project_name, token_description = 'Default token for public project', project_id=new_project, user_id=request.user.id, public=new_project.public )
tk.save()
## RBTODO create a default channel
except Exception, e:
logger.error("Failed to create project. Error {}".format(e))
messages.error(request,"Failed to create project Error {}".format(e))
return HttpResponseRedirect(get_script_prefix()+'ocpuser/projects/')
else:
context = {'form': form}
return render_to_response('createproject.html',context,context_instance=RequestContext(request))
else:
#default
return redirect(getProjects)
示例9: register
# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import save [as 别名]
def register(request):
info = ''
if request.method == 'POST':
form = CustomerRegisterForm(request.POST)
if form.is_valid():
email = form.cleaned_data['email']
if Customer.objects.filter(email= email).count() == 0:
customer = form.save()
customer.save()
token = Token(token = utility.generate_token(), customer = customer)
token.save()
content = '''<!DOCTYPE HTML><html><head><meta charset="utf-8"><title>Guo Hao Hotel注册验证</title></head><body><a href='http://10.131.255.124/account/%s/'>激活</a></body></html>'''
utility.send_mail(customer.email, 'GuoHaoHotel', content % token.token)
info = '已经发送一封邮件至%s,请点击链接激活账户' % customer.email
else:
info = '邮箱已经注册!'
elif request.method == 'GET':
form = CustomerRegisterForm()
return render(request, 'register.html', {'form' : form, 'info' : info})
示例10: create_token
# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import save [as 别名]
def create_token(request, url_id=None, **kwargs):
kwargs['extra_context'] = {}
if request.method == 'POST':
form = TokenAddForm(request.POST)
if form.is_valid():
email=form.cleaned_data['email']
token = Token(
url=form.cleaned_data['url'],
valid_until=form.cleaned_data['valid_until'],
forward_count=form.cleaned_data['forward_count'],
email=email,
name=form.cleaned_data['name'],
)
token.save()
messages.add_message(request, messages.SUCCESS, 'Token successfully created for %s.' % token.email)
return HttpResponseRedirect(reverse('token_list'))
else:
initial_data = None
if not url_id is None:
url = ProtectedURL.objects.get(id=url_id)
initial_data = {'url': url.url, }
form = TokenAddForm( initial=initial_data )
kwargs['extra_context']['form'] = form
return direct_to_template(request, template='token_auth/create_token.html', **kwargs)
示例11: forgot_password
# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import save [as 别名]
def forgot_password(request):
if request.method == 'POST':
try:
email = request.POST.get('email', None)
if email:
user = User.objects.get(email=email)
message = 'An email was sent to you.'
try:
token = Token.objects.get(user=user)
# send email to user with token
send_mail(
'iSpark Password Reset',
'Click on the following link to reset your password http://www.isparkegypt.com/password_reset/%s' % token.token,
'[email protected]',
['%s' % user.email],
fail_silently=False,
)
except Token.DoesNotExist:
token = Token(user=user)
token.save()
# send email to user with token
send_mail(
'iSpark Password Reset',
'Click on the following link to reset your password http://www.isparkegypt.com/password_reset/%s' % token.token,
'[email protected]',
['%s' % user.email],
fail_silently=False,
)
else:
message = 'Enter a valid email.'
except User.DoesNotExist:
message = 'You are not registered.'
addresses = Contact.objects.filter(type='AD')
emails = Contact.objects.filter(type='EM')
phones = Contact.objects.filter(type='PH')
try:
fb = Contact.objects.get(type='FB')
except Contact.DoesNotExist:
fb = ''
try:
tw = Contact.objects.get(type='TW')
except Contact.DoesNotExist:
tw = ''
try:
ins = Contact.objects.get(type='IN')
except Contact.DoesNotExist:
ins = ''
try:
yt = Contact.objects.get(type='YT')
except Contact.DoesNotExist:
yt = ''
return render(request, 'forgot_password.html', {'message': message, 'emails': emails, 'addresses': addresses, 'phones': phones, 'fb': fb, 'tw': tw, 'in': ins, 'yt': yt})
else:
addresses = Contact.objects.filter(type='AD')
emails = Contact.objects.filter(type='EM')
phones = Contact.objects.filter(type='PH')
try:
fb = Contact.objects.get(type='FB')
except Contact.DoesNotExist:
fb = ''
try:
tw = Contact.objects.get(type='TW')
except Contact.DoesNotExist:
tw = ''
try:
ins = Contact.objects.get(type='IN')
except Contact.DoesNotExist:
ins = ''
try:
yt = Contact.objects.get(type='YT')
except Contact.DoesNotExist:
yt = ''
return render(request, 'forgot_password.html', {'emails': emails, 'addresses': addresses, 'phones': phones, 'fb': fb, 'tw': tw, 'in': ins, 'yt': yt})