Exemple #1
0
    def post(self, request):
        user_create_form = UserCreationWithEmailFieldForm(request.POST)
        account_registration_form = AccountRegistrationForm(request.POST)

        if user_create_form.is_valid() and account_registration_form.is_valid():
            new_user = user_create_form.save()
            group_status = request.POST['group_status']

            if group_status == 'SALES':
                g = Group.objects.get(name='Sales') 
                g.user_set.add(new_user)
            elif group_status == 'ENGSUP':
                email_subject = 'New user registration for Engineering/Support user - %s' % new_user.username
                email_message = 'Please reach out to user %s at %s to add them to the appropriate group' % (new_user.username, new_user.email) 
                email_addresses = Group.objects.get(name='Enablement').user_set.values_list('email', flat=True)
                send_mail(email_subject, email_message, 'NEWT Admin', email_addresses, html_message=email_message)

                email_message = 'Thank you for your account registration.  A member of the Enablement Team will reach out to you about adding you to the Engineering or Support groups in the NEWT system.'
                email_addresses = [new_user.email]

            account_registration_form.save(user=new_user)

            user = authenticate(username=request.POST['username'], password=request.POST['password1'])
            login(request, user)
            
            return HttpResponseRedirect('/')

        context = {'user_create_form': user_create_form, 'account_registration_form': account_registration_form}
        return render(request, self.template_name, context)
def cw_register(request):
    form = AccountRegistrationForm(request.POST or None)
    if request.method == 'POST':
        # Form Validation
        if form.is_valid():
            username = form.clean_username()
            password = form.clean_password()
            email = form.clean_email()

            # Create a New Account
            try:
                User.objects.create_user(username, email, password)
                user = authenticate(username=username, password=password)

                account = Account(user=user)
                if not settings.CLOSED_BETA:
                    account.beta_access = True
                account.save()

                user.is_active = True
                user.save()

                uid = urlsafe_base64_encode(force_bytes(user.pk))
                token = account_activation_token.make_token(user)
                domain = get_current_site(request).domain
                base_url = "http://{domain}/auth/activate_account/{uid}/{token}/"
                url_with_code = base_url.format(domain=domain, uid=uid, token=token)
                # Send Email Verification Message
                # TODO: Move this to string templates
                email_context = {
                    'title' : 'Verify your email with CiviWiki',
                    'body' : "Welcome to CiviWiki! Follow the link below to verify your email with us. We're happy to have you on board :)",
                    'link': url_with_code
                }

                send_email.delay(
                    subject="CiviWiki Account Setup",
                    recipient_list=[email],
                    context=email_context
                )

                login(request, user)
                return HttpResponse()

            except Exception as e:
                return HttpResponseServerError(reason=str(e))

        else:
            response = {
                'success': False,
                'errors' : [error[0] for error in form.errors.values()]
            }
            return JsonResponse(response, status=400)
    else:
        return HttpResponseBadRequest(reason="POST Method Required")
Exemple #3
0
def cw_register(request):
    form = AccountRegistrationForm(request.POST or None)
    if request.method == 'POST':
        # Form Validation
        if form.is_valid():
            username = form.clean_username()
            password = form.clean_password()
            email = form.clean_email()

            # Create a New Account
            try:
                User.objects.create_user(username, email, password)
                user = authenticate(username=username, password=password)

                account = Account(user=user)
                if not settings.CLOSED_BETA:
                    account.beta_access = True
                account.save()

                user.is_active = True
                user.save()

                uid = urlsafe_base64_encode(force_bytes(user.pk))
                token = account_activation_token.make_token(user)
                domain = get_current_site(request).domain
                base_url = "http://{domain}/auth/activate_account/{uid}/{token}/"
                url_with_code = base_url.format(domain=domain,
                                                uid=uid,
                                                token=token)
                # Send Email Verification Message
                # TODO: Move this to string templates
                email_context = {
                    'title':
                    'Verify your email with CiviWiki',
                    'body':
                    ("Welcome to CiviWiki! Follow the link below to verify your email with us. "
                     "We're happy to have you on board :)"),
                    'link':
                    url_with_code
                }

                send_email.delay(subject="CiviWiki Account Setup",
                                 recipient_list=[email],
                                 context=email_context)

                login(request, user)
                return HttpResponse()

            except Exception as e:
                return HttpResponseServerError(reason=str(e))

        else:
            response = {
                'success': False,
                'errors': [error[0] for error in form.errors.values()]
            }
            return JsonResponse(response, status=400)
    else:
        return HttpResponseBadRequest(reason="POST Method Required")
def beta_register(request):
    """ Special registration request for beta access """
    # Beta Check
    beta_token = request.POST.get('beta_token', '')
    if beta_token:
        email = request.POST.get('email' '')
        try:
            invitation = Invitation.objects.get(invitee_email=email)
        except Invitation.DoesNotExist:
            response_data = {
                "message": "Beta invitation does not exist for this email",
                "error": "NO_BETA_INVITE"
            }
            return JsonResponse(response_data, status=400)

        if invitation.verification_code != beta_token:
            response_data = {
                "message": "The beta token is not valid",
                "error": "INVALID_BETA_TOKEN"
            }
            return JsonResponse(response_data, status=400)

    else:
        response_data = {
            "message": "Missing Beta Token",
            "error": "MISSING_BETA_TOKEN"
        }
        return JsonResponse(response_data, status=400)

    form = AccountRegistrationForm(request.POST or None)
    if request.method == 'POST':
        # Form Validation
        if form.is_valid():
            username = form.clean_username()
            password = form.clean_password()
            email = form.clean_email()

            # Create a New Account
            try:
                User.objects.create_user(username, email, password)
                user = authenticate(username=username, password=password)
                account = Account(user=user)
                account.beta_access = True
                account.is_verfied = True
                account.save()

                invitation = Invitation.objects.get(invitee_email=email)
                invitation.invitee_user = user
                invitation.save()

                user.is_active = True
                user.save()

                login(request, user)
                return HttpResponse()

            except Exception as e:
                return HttpResponseServerError(reason=str(e))

        else:
            response = {
                'success': False,
                'errors': [error[0] for error in form.errors.values()]
            }
            return JsonResponse(response, status=400)
    else:
        return HttpResponseBadRequest(reason="POST Method Required")
Exemple #5
0
    def get(self, request):
        user_create_form = UserCreationWithEmailFieldForm()
        account_registration_form = AccountRegistrationForm()

        context = {'user_create_form': user_create_form, 'account_registration_form': account_registration_form}
        return render(request, self.template_name, context)
def beta_register(request):
    """ Special registration request for beta access """
    # Beta Check
    beta_token = request.POST.get('beta_token', '')
    if beta_token:
        email = request.POST.get('email' '')
        try:
            invitation = Invitation.objects.get(invitee_email=email)
        except Invitation.DoesNotExist:
            response_data = {
                "message": "Beta invitation does not exist for this email",
                "error":"NO_BETA_INVITE"
            }
            return JsonResponse(response_data, status=400)

        if invitation.verification_code != beta_token:
            response_data = {
                "message": "The beta token is not valid",
                "error":"INVALID_BETA_TOKEN"
            }
            return JsonResponse(response_data, status=400)

    else:
        response_data = {
            "message": "Missing Beta Token",
            "error":"MISSING_BETA_TOKEN"
        }
        return JsonResponse(response_data, status=400)


    form = AccountRegistrationForm(request.POST or None)
    if request.method == 'POST':
        # Form Validation
        if form.is_valid():
            username = form.clean_username()
            password = form.clean_password()
            email = form.clean_email()

            # Create a New Account
            try:
                User.objects.create_user(username, email, password)
                user = authenticate(username=username, password=password)
                account = Account(user=user)
                account.beta_access = True
                account.is_verfied = True
                account.save()

                invitation = Invitation.objects.get(invitee_email=email)
                invitation.invitee_user = user
                invitation.save()

                user.is_active = True
                user.save()

                login(request, user)
                return HttpResponse()

            except Exception as e:
                return HttpResponseServerError(reason=str(e))

        else:
            response = {
                'success': False,
                'errors' : [error[0] for error in form.errors.values()]
            }
            return JsonResponse(response, status=400)
    else:
        return HttpResponseBadRequest(reason="POST Method Required")