def auto_auth(request):
 unique_name = uuid.uuid4().hex[0:30]
 username = request.GET.get('username', unique_name)
 password = request.GET.get('password', unique_name)
 email = request.GET.get('email', (unique_name + '@example.com'))
 full_name = request.GET.get('full_name', username)
 is_staff = request.GET.get('staff', None)
 is_superuser = request.GET.get('superuser', None)
 course_id = request.GET.get('course_id', None)
 redirect_to = request.GET.get('redirect_to', None)
 active_status = request.GET.get('is_active')
 enrollment_mode = request.GET.get('enrollment_mode', 'honor')
 active_status = ((not active_status) or (active_status == 'true'))
 course_key = None
 if course_id:
  course_key = CourseLocator.from_string(course_id)
 role_names = [v.strip() for v in request.GET.get('roles', '').split(',') if v.strip()]
 redirect_when_done = ((request.GET.get('redirect', '').lower() == 'true') or redirect_to)
 login_when_done = ('no_login' not in request.GET)
 form = AccountCreationForm(data={'username': username, 'email': email, 'password': password, 'name': full_name}, tos_required=False)
 try:
  (user, profile, reg) = _do_create_account(form)
 except (AccountValidationError, ValidationError):
  user = User.objects.get(username=username)
  user.email = email
  user.set_password(password)
  user.is_active = active_status
  user.save()
  profile = UserProfile.objects.get(user=user)
  reg = Registration.objects.get(user=user)
 if (is_staff is not None):
  user.is_staff = (is_staff == 'true')
  user.save()
 if (is_superuser is not None):
  user.is_superuser = (is_superuser == 'true')
  user.save()
 if active_status:
  reg.activate()
  reg.save()
 year = datetime.date.today().year
 age_limit = settings.PARENTAL_CONSENT_AGE_LIMIT
 profile.year_of_birth = ((year - age_limit) - 1)
 profile.save()
 if (course_key is not None):
  CourseEnrollment.enroll(user, course_key, mode=enrollment_mode)
 for role_name in role_names:
  role = Role.objects.get(name=role_name, course_id=course_key)
  user.roles.add(role)
 if login_when_done:
  user = authenticate(username=username, password=password)
  login(request, user)
 create_comments_service_user(user)
 if redirect_when_done:
  if redirect_to:
   redirect_url = redirect_to
  elif course_id:
   try:
    redirect_url = reverse('info', kwargs={'course_id': course_id})
   except NoReverseMatch:
    redirect_url = reverse('course_handler', kwargs={'course_key_string': course_id})
  else:
   try:
    redirect_url = reverse('dashboard')
   except NoReverseMatch:
    redirect_url = reverse('home')
  return redirect(redirect_url)
 elif (request.META.get('HTTP_ACCEPT') == 'application/json'):
  response = JsonResponse({'created_status': (u'Logged in' if login_when_done else 'Created'), 'username': username, 'email': email, 'password': password, 'user_id': user.id, 'anonymous_id': anonymous_id_for_user(user, None)})
 else:
  success_msg = u'{} user {} ({}) with password {} and user_id {}'.format((u'Logged in' if login_when_done else 'Created'), username, email, password, user.id)
  response = HttpResponse(success_msg)
 response.set_cookie('csrftoken', csrf(request)['csrf_token'])
 return response

def auto_auth ( request ) : unique_name = uuid . uuid4 ( ) . hex [ 0 : 30 ] username = request . GET . get ( 'username' , unique_name ) password = request . GET . get ( 'password' , unique_name ) email = request . GET . get ( 'email' , ( unique_name + '@example.com' ) ) full_name = request . GET . get ( 'full_name' , username ) is_staff = request . GET . get ( 'staff' , None ) is_superuser = request . GET . get ( 'superuser' , None ) course_id = request . GET . get ( 'course_id' , None ) redirect_to = request . GET . get ( 'redirect_to' , None ) active_status = request . GET . get ( 'is_active' ) enrollment_mode = request . GET . get ( 'enrollment_mode' , 'honor' ) active_status = ( ( not active_status ) or ( active_status == 'true' ) ) course_key = None if course_id : course_key = CourseLocator . from_string ( course_id ) role_names = [ v . strip ( ) for v in request . GET . get ( 'roles' , '' ) . split ( ',' ) if v . strip ( ) ] redirect_when_done = ( ( request . GET . get ( 'redirect' , '' ) . lower ( ) == 'true' ) or redirect_to ) login_when_done = ( 'no_login' not in request . GET ) form = AccountCreationForm ( data = { 'username' : username , 'email' : email , 'password' : password , 'name' : full_name } , tos_required = False ) try : ( user , profile , reg ) = _do_create_account ( form ) except ( AccountValidationError , ValidationError ) : user = User . objects . get ( username = username ) user . email = email user . set_password ( password ) user . is_active = active_status user . save ( ) profile = UserProfile . objects . get ( user = user ) reg = Registration . objects . get ( user = user ) if ( is_staff is not None ) : user . is_staff = ( is_staff == 'true' ) user . save ( ) if ( is_superuser is not None ) : user . is_superuser = ( is_superuser == 'true' ) user . save ( ) if active_status : reg . activate ( ) reg . save ( ) year = datetime . date . today ( ) . year age_limit = settings . PARENTAL_CONSENT_AGE_LIMIT profile . year_of_birth = ( ( year - age_limit ) - 1 ) profile . save ( ) if ( course_key is not None ) : CourseEnrollment . enroll ( user , course_key , mode = enrollment_mode ) for role_name in role_names : role = Role . objects . get ( name = role_name , course_id = course_key ) user . roles . add ( role ) if login_when_done : user = authenticate ( username = username , password = password ) login ( request , user ) create_comments_service_user ( user ) if redirect_when_done : if redirect_to : redirect_url = redirect_to elif course_id : try : redirect_url = reverse ( 'info' , kwargs = { 'course_id' : course_id } ) except NoReverseMatch : redirect_url = reverse ( 'course_handler' , kwargs = { 'course_key_string' : course_id } ) else : try : redirect_url = reverse ( 'dashboard' ) except NoReverseMatch : redirect_url = reverse ( 'home' ) return redirect ( redirect_url ) elif ( request . META . get ( 'HTTP_ACCEPT' ) == 'application/json' ) : response = JsonResponse ( { 'created_status' : ( u'Logged in' if login_when_done else 'Created' ) , 'username' : username , 'email' : email , 'password' : password , 'user_id' : user . id , 'anonymous_id' : anonymous_id_for_user ( user , None ) } ) else : success_msg = u'{} user {} ({}) with password {} and user_id {}' . format ( ( u'Logged in' if login_when_done else 'Created' ) , username , email , password , user . id ) response = HttpResponse ( success_msg ) response . set_cookie ( 'csrftoken' , csrf ( request ) [ 'csrf_token' ] ) return response
logout and login with given credentials .