本文整理汇总了Python中evap.evaluation.models.EmailTemplate.get_login_key_template方法的典型用法代码示例。如果您正苦于以下问题:Python EmailTemplate.get_login_key_template方法的具体用法?Python EmailTemplate.get_login_key_template怎么用?Python EmailTemplate.get_login_key_template使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类evap.evaluation.models.EmailTemplate
的用法示例。
在下文中一共展示了EmailTemplate.get_login_key_template方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from evap.evaluation.models import EmailTemplate [as 别名]
# 或者: from evap.evaluation.models.EmailTemplate import get_login_key_template [as 别名]
def index(request):
"""Main entry page into EvaP providing all the login options available. THe username/password
login is thought to be used for internal users, e.g. by connecting to a LDAP directory.
The login key mechanism is meant to be used to include external participants, e.g. visiting
students or visiting contributors.
"""
# parse the form data into the respective form
submit_type = request.POST.get("submit_type", "no_submit")
new_key_form = NewKeyForm(request.POST if submit_type == "new_key" else None)
login_key_form = LoginKeyForm(request.POST if submit_type == "login_key" else None)
login_username_form = LoginUsernameForm(request, request.POST if submit_type == "login_username" else None)
# process form data
if request.method == 'POST':
if new_key_form.is_valid():
# user wants a new login key
profile = new_key_form.get_user()
profile.generate_login_key()
profile.save()
EmailTemplate.get_login_key_template().send_to_user(new_key_form.get_user(), cc=False)
messages.success(request, _(u"Successfully sent email with new login key."))
elif login_key_form.is_valid():
# user would like to login with a login key and passed key test
auth_login(request, login_key_form.get_user())
elif login_username_form.is_valid():
# user would like to login with username and password and passed password test
auth_login(request, login_username_form.get_user())
# clean up our test cookie
if request.session.test_cookie_worked():
request.session.delete_test_cookie()
# if not logged in by now, render form
if not request.user.is_authenticated():
# set test cookie to verify whether they work in the next step
request.session.set_test_cookie()
template_data = dict(new_key_form=new_key_form, login_key_form=login_key_form, login_username_form=login_username_form)
return render(request, "index.html", template_data)
else:
user, created = UserProfile.objects.get_or_create(username=request.user.username)
# check for redirect variable
redirect_to = request.GET.get("next", None)
if redirect_to is not None:
if redirect_to.startswith("/staff/"):
if request.user.is_staff:
return redirect(redirect_to)
elif redirect_to.startswith("/contributor/"):
if user.is_contributor:
return redirect(redirect_to)
elif redirect_to.startswith("/student/"):
if user.is_participant:
return redirect(redirect_to)
else:
return redirect(redirect_to)
# redirect user to appropriate start page
if request.user.is_staff:
return redirect('evap.staff.views.index')
elif user.is_editor_or_delegate:
return redirect('evap.contributor.views.index')
elif user.is_participant:
return redirect('evap.student.views.index')
else:
return redirect('evap.results.views.index')