Advertisement
Mochinov

Untitled

Dec 6th, 2021
998
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.64 KB | None | 0 0
  1.  
  2. def register_step_first(request):
  3.     context = {}
  4.     if request.user.is_authenticated:
  5.         return redirect('/')
  6.  
  7.     positions = request.POST.get('position', '')
  8.     if request.method == 'POST':
  9.         form = RegisterUserFirstStep(request.POST)
  10.         if form.is_valid():
  11.             main_category = request.POST.get('main_category', '')
  12.             objects = form.save(commit=False)
  13.             objects.step_register = 2
  14.             objects.pos = positions
  15.             objects.main_category = Category.objects.get(id = main_category)
  16.             objects.save()
  17.             login(request, objects, backend='django.contrib.auth.backends.ModelBackend')
  18.             check_session_utm(request, objects)      
  19.             sms_confirm = getattr(settings, 'ACCOUNT_SMS_CONFIRMATION', '')
  20.             phone = phonenumbers.parse(objects.username)
  21.             cc = phonenumbers.region_code_for_number(phone)
  22.             send_email_confirmation(request, objects, signup=False)
  23.             if sms_confirm and cc == "RU":
  24.                 send_confirmation_code(request, objects)
  25.                 return redirect(objects.get_current_step_register(request.path))
  26.             else:
  27.                 objects.is_verified = True
  28.                 objects.save()
  29.                 return redirect(objects.get_current_step_register(request.path))
  30.         else:
  31.             form = RegisterUserFirstStep(request.POST)
  32.     else:
  33.         form = RegisterUserFirstStep()
  34.     context['form'] = form
  35.     context['positions'] = User.get_lector_position()
  36.     context['selectod_position'] = positions
  37.     return render(request, 'account/singup_step_1.html', context)
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement