Exemplo n.º 1
0
 def test_user_is_created(self):
     user_qs = UserProfile.objects.filter(email='*****@*****.**')
     assert not user_qs.exists()
     views.register_user(self.request, self.identity)
     assert user_qs.exists()
     user = user_qs.get()
     assert user.username == '*****@*****.**'
     assert user.fxa_id == '9005'
     assert not user.has_usable_password()
     self.login.assert_called_with(self.request, user)
Exemplo n.º 2
0
 def test_user_is_created(self):
     user_qs = UserProfile.objects.filter(email='*****@*****.**')
     assert not user_qs.exists()
     views.register_user(self.request, self.identity)
     assert user_qs.exists()
     user = user_qs.get()
     assert user.username == '*****@*****.**'
     assert user.fxa_id == '9005'
     assert not user.has_usable_password()
     self.login.assert_called_with(self.request, user)
Exemplo n.º 3
0
 def test_username_taken_creates_user(self):
     UserProfile.objects.create(
         email='*****@*****.**', username='******')
     user_qs = UserProfile.objects.filter(email='*****@*****.**')
     assert not user_qs.exists()
     views.register_user(self.request, self.identity)
     assert user_qs.exists()
     user = user_qs.get()
     assert user.username.startswith('anonymous-')
     assert user.fxa_id == '9005'
     assert not user.has_usable_password()
Exemplo n.º 4
0
 def test_username_taken_creates_user(self):
     UserProfile.objects.create(email='*****@*****.**',
                                username='******')
     user_qs = UserProfile.objects.filter(email='*****@*****.**')
     assert not user_qs.exists()
     views.register_user(self.request, self.identity)
     assert user_qs.exists()
     user = user_qs.get()
     assert user.username.startswith('*****@*****.**')
     assert user.username != '*****@*****.**'
     assert user.fxa_id == '9005'
     assert not user.has_usable_password()
Exemplo n.º 5
0
def add_user(request):
    # Authentication check
    authentication_result = views.authentication_check(
        request, [Account.ACCOUNT_ADMIN])
    if authentication_result is not None:
        return authentication_result
    # Get the template data from the session
    template_data = views.parse_session(request, {'form_button': "Register"})
    # Proceed with the rest of the view
    if request.method == 'POST':
        form = AddUserForm(request.POST)
        if form.is_valid():
            user = views.register_user(
                form.cleaned_data['email'],
                form.cleaned_data['password_first'],
                form.cleaned_data['firstname'],
                form.cleaned_data['lastname'],
                0,
                "",
                True,
                form.cleaned_data['member_type']
            )
            request.session['alert_success'] = "Successfully created new member account. Please ask them to change the password first"
            return HttpResponseRedirect(reverse('webadmin:admin/users'))
    else:
        form = AddUserForm()
    template_data['form'] = form
    return render(request, 'ienitk/admin/createuser.html', template_data)
Exemplo n.º 6
0
def new_client_signup(request):
    """
    Create a new client from an account with Recurly or other provider.
    """

    provider = request.REQUEST.get('provider')
    if provider != 'recurly':
        return HttpResponseBadRequest('Unexpected provider.')
    account_code = request.REQUEST.get('account_code')
    if not account_code:
        return HttpResponseBadRequest('"account_code" parameter is missing or empty.')
    plan_code = request.REQUEST.get('plan_code')
    if not plan_code:
        return HttpResponseBadRequest('"plan_code" parameter is missing or empty.')

    try:
        try:
            account = recurly.Account.get(account_code)
            email        = account.email
            company_name = account.company_name
        except:
            raise Exception('Unable to retreive Recurly account information for %s.' % account_code)

        if Client.objects.filter(email=email):
            raise Exception('%s already has an account with Povelli.' % email)

        if User.objects.filter(email=email):
            raise Exception('%s already has an account with Povelli.' % email)

        try:
            phone_number = account.billing_info.phone
        except:
            phone_number = ''  # Phone number is optional.

        client_type = Client.TYPE_SMB if plan_code.lower() == 'basic' else Client.TYPE_PREMIUM

        # Create a new client.
        new_client = Client.objects.create(
            name=company_name,
            phone=phone_number,
            email=email,
            sourcecode='1:recurly:%s' % account_code,
            client_type=client_type,
        )
        new_user, registration_profile = register_user(email, new_client, None, request)

        return redirect(reverse('registration_activate',
                                kwargs={'activation_key': registration_profile.activation_key}))
    except Exception as err:
        messages.error(request, err.message)
        return render(request, 'administration/recurly_signup_error.html', {})