本文整理汇总了Python中registration.backends.simple.views.RegistrationView.register方法的典型用法代码示例。如果您正苦于以下问题:Python RegistrationView.register方法的具体用法?Python RegistrationView.register怎么用?Python RegistrationView.register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类registration.backends.simple.views.RegistrationView
的用法示例。
在下文中一共展示了RegistrationView.register方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Authenticate
# 需要导入模块: from registration.backends.simple.views import RegistrationView [as 别名]
# 或者: from registration.backends.simple.views.RegistrationView import register [as 别名]
def Authenticate(request):
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password'].encode('utf-8')
email = None
authenticated = False
#Setup request url and parameter for API
moodleUrl = os.environ['MOODLE_API_URL']
payload = {'username': username}
#Get values from the API
try:
api = requests.get(moodleUrl, params=payload).json()[0]
salt = api['password'].encode('utf-8')
email = api['email']
#Check if the user and password match with moodle
if clean(password, salt):
authenticated = True
#Check if the user is in the local database and if the password matches
new_user = authenticate(username=username, password=password)
#Check if the username exists
try:
user = get_object_or_404(User, username=username)
except:
user = None
#If the user exists, is authenticated but wrong password
#then the username exists in our database.
if authenticated and new_user is None and user is not None:
messages.error(request, "Username already in local database")
return MoodleLogin(request)
#Login the user with moodle
if new_user:
login(request, new_user)
#If this is the first moodle login then register the user
else:
reg = RegistrationView()
data = {'username': username,
'email': email,
'password1': password}
#Register the user and log him in
reg.register(request, **data)
#Username in moodle but wrong password
else:
messages.error(request, "Invalid moodle credentials")
return MoodleLogin(request)
#Username not in moodle
except:
messages.error(request, "Username not in our moodle database")
return MoodleLogin(request)
return HttpResponseRedirect('/')
示例2: register_home
# 需要导入模块: from registration.backends.simple.views import RegistrationView [as 别名]
# 或者: from registration.backends.simple.views.RegistrationView import register [as 别名]
def register_home(request):
loginform = AuthenticationForm()
if request.method == "POST": # If the form registration has been submitted
form = RegistrationFormUniqueEmail(request.POST)
if form.is_valid():
usr, em, pw = form.cleaned_data["username"], form.cleaned_data["email"], form.cleaned_data["password1"]
user = RegistrationView.register(RegistrationView, request=request, username=usr, email=em, password1=pw)
return HttpResponseRedirect("/playlist")
else:
return render(request, "home.html", {"regform": form, "anchor": "register", "loginform": loginform})
else:
form = RegistrationFormUniqueEmail()
return render(request, "home.html", {"regform": form, "loginform": loginform})
示例3: register
# 需要导入模块: from registration.backends.simple.views import RegistrationView [as 别名]
# 或者: from registration.backends.simple.views.RegistrationView import register [as 别名]
def register(self, request, **cleaned_data):
new_user = RegistrationView.register(self, request, **cleaned_data)
UserProfile(user=new_user).save()
return new_user