+ form = LoginForm(request.POST, request=request)
+
+ if form.is_valid():
+ try:
+ auth_args = dict(username=form.cleaned_data['email'],
+ password=form.cleaned_data['password'])
+ if merge:
+ # We only want to send the merge argument if it's
+ # True. If it it's False, we want it to propagate
+ # through the auth backends properly.
+ auth_args['merge'] = merge
+ user = authenticate(**auth_args)
+ except SameEmailMismatchedPasswords:
+ # Need to merge the accounts?
+ if merge:
+ # We shouldn't get here...
+ raise
+ else:
+ base_url = reverse('cas_provider_merge')
+ args = dict(
+ success_redirect=success_redirect,
+ email=form.cleaned_data['email'],
+ )
+ if service is not None:
+ args['service'] = service
+ args = urllib.urlencode(args)
+
+ return HttpResponseRedirect('%s?%s' % (base_url, args))