def loginView(request): username = request.POST['username'] password = request.POST['password'] user = authenticate(request, username=username, password=password) if user is not None: login(request, user) else: # Return an 'invalid login' error message. return HttpResponse.Redirect("/login")
def enroll(user, course_id, mode_slug): """ Enroll the user in a course for a certain mode. This is the view you send folks to when they click on the enroll button. This does NOT cover changing enrollment modes -- it's intended for new enrollments only, and will just redirect to the dashboard if it detects that an enrollment already exists. """ # If the user is already enrolled, jump to the dashboard. Yeah, we could # do upgrades here, but this method is complicated enough. if CourseEnrollment.is_enrolled(user, course_id): return HttpResponseRedirect(reverse('dashboard')) available_modes = CourseModes.modes_for_course(course_id) # If they haven't chosen a mode... if not mode_slug: # Does this course support multiple modes of Enrollment? If so, redirect # to a page that lets them choose which mode they want. if len(available_modes) > 1: return HttpResponseRedirect( reverse('choose_enroll_mode', kwargs={'course_id': course_id}) ) # Otherwise, we use the only mode that's supported... else: mode_slug = available_modes[0].slug # If the mode is one of the simple, non-payment ones, do the enrollment and # send them to their dashboard. if mode_slug in ("honor", "audit"): CourseEnrollment.enroll(user, course_id, mode=mode_slug) return HttpResponseRedirect(reverse('dashboard')) if mode_slug == "verify": if SoftwareSecurePhotoVerification.has_submitted_recent_request(user): # Capture payment info # Create an order # Create a VerifiedCertificate order item return HttpResponse.Redirect(reverse('verified')) # There's always at least one mode available (default is "honor"). If they # haven't specified a mode, we just assume it's if not mode: mode = available_modes[0] elif len(available_modes) == 1: if mode != available_modes[0]: raise Exception() mode = available_modes[0] if mode == "honor": CourseEnrollment.enroll(user, course_id) return HttpResponseRedirect(reverse('dashboard'))