Exemple #1
0
def register_user_view(request):
    logger.debug("register_user_view called by user %s" % request.user)
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        logger.debug("Request type POST contains form valid: %s" % form.is_valid())
        if form.is_valid():

            if not User.objects.filter(username=form.cleaned_data['username']).exists():
                user = User.objects.create_user(form.cleaned_data['username'],
                                                form.cleaned_data['email'], form.cleaned_data['password'])

                user.save()
                logger.info("Created new user %s" % user)
                messages.warning(request, 'Add an API key to set up your account.')
                return redirect("auth_dashboard")

            else:
                logger.error("Unable to register new user: username %s already exists." % form.cleaned_data['username'])
                return render(request, 'public/register.html', context={'form': form, 'error': True})
        else:
            logger.debug("Registration form invalid. Returning for user %s to make corrections." % request.user)

    else:
        logger.debug("Returning blank registration form.")
        form = RegistrationForm()

    return render(request, 'public/register.html', context={'form': form})
Exemple #2
0
 def test_registration_form_matching_passwords(self):
     """
     Test that ``RegistrationForm`` has matching passwords
     """
     form_data = RegistrationFormTest.form_data_dict[2]
     form = RegistrationForm(data=form_data['data'])
     self.assert_(not form.is_valid())
Exemple #3
0
def register_view(request, *args, **kwargs):
    if request.method == "GET":
        context = {
            'user_form': RegistrationForm(),
            'profile_form': ProfileForm(),
        }

        return render(request, 'auth/register.html', context)

    elif request.method == 'POST':

        user_form = RegistrationForm(request.POST)
        profile_form = ProfileForm(request.POST, request.FILES)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            profile.save()

            login(request, user)
            return redirect('home view')

    context = {
        'user_form': RegistrationForm(),
        'profile_form': ProfileForm(),
    }
    return render(request, 'auth/register.html', context)
Exemple #4
0
 def test_registration_form_valid_username_syntax(self):
     """
     Test that ``RegistrationForm`` enforces username syntax constraints
     """
     form_data = RegistrationFormTest.form_data_dict[0]
     form = RegistrationForm(data=form_data['data'])
     self.assert_(not form.is_valid())
Exemple #5
0
def register(request):
    """
    Sign up a user
    :param request:
    :return:
    """
    if request.method == "POST":
        form = RegistrationForm(request.POST)
        phone = request.POST.get("phone")
        if form.is_valid():
            user = form.save(commit=False)
            user.email = form.cleaned_data.get("username")
            user.set_password(form.cleaned_data.get("password1"))
            user.is_active = False
            user.save()
            profile = Profile.objects.create(user=user, telephone_number=phone)
            profile.save()
            url_name = "authentication:activate_user"
            activation_link = generate_activation_url(request, user, url_name)
            message_body = constants.ACCOUNT_ACTIVATION_MESSAGE.format(
                activation_link=activation_link)
            mailing_list = [user.email]
            send_mail("FreshCollections", message_body,
                      "*****@*****.**", mailing_list)
            user.backend = "authentication.backend.EmailAuthBackend"
            _login(
                request,
                user)  # , backend="authentication.backend.EmailAuthBackend")
            next_url = request.GET.get("next")
            return redirect("authentication:registration_success")
        else:
            import pdb
            pdb.set_trace()

    return redirect("authentication:auth_get")
Exemple #6
0
def register(request):
    if request.method == 'POST':
        user_form = RegistrationForm(request.POST)
        if user_form.is_valid():
            username = user_form.cleaned_data.get('username')
            email = user_form.cleaned_data.get('email')
            password = user_form.cleaned_data.get('password')

            User.objects.create_user(
                username=username,
                email=email,
                password=password,
            )
            user = authenticate(username=username, password=password)
            login(request, user)
            _success_msg = 'User {0} added'.format(user.username)
            feed = Feed(user=user, posts=_success_msg)
            feed.save()
            return redirect('/feeds/')
        else:
            return render(request, 'authentication/register.html',
                          {'form': user_form})
    else:
        user_form = RegistrationForm()

    return render(request, 'authentication/register.html', {'form': user_form})
Exemple #7
0
def register(request, *args, **kwargs):
    if request.method == 'POST':
        registration_form = RegistrationForm(request.POST)
        if registration_form.is_valid():
            registration_form.save()
            return redirect('/login/')
    else:
        registration_form = RegistrationForm()
    return render(request, 'authentication/registration.html', {'form': registration_form})
Exemple #8
0
def register(request, *args, **kwargs):
    if request.method == 'POST':
        registration_form = RegistrationForm(request.POST)
        if registration_form.is_valid():
            registration_form.save()
            return redirect('/login/')
    else:
        registration_form = RegistrationForm()
    return render(request, 'authentication/registration.html',
                  {'form': registration_form})
Exemple #9
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)

        if form.is_valid():
            profile = form.save()
            return redirect('registration_completed')
    else:
        form = RegistrationForm()

    return TemplateResponse(request, 'auth/register.html', {'form': form})
Exemple #10
0
def register_user_view(request):
    logger.debug("register_user_view called by user %s" % request.user)
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        logger.debug("Request type POST contains form valid: %s" %
                     form.is_valid())
        if form.is_valid():

            if not User.objects.filter(
                    username=form.cleaned_data['username']).exists():
                user = User.objects.create_user(form.cleaned_data['username'],
                                                form.cleaned_data['email'],
                                                form.cleaned_data['password'])

                user.save()
                logger.info("Created new user %s" % user)
                login(request, user)
                messages.warning(request,
                                 _('Add an API key to set up your account.'))
                return redirect("auth_dashboard")

            else:
                logger.error(
                    "Unable to register new user: username %s already exists."
                    % form.cleaned_data['username'])
                return render(request,
                              'public/register.html',
                              context={
                                  'form': form,
                                  'error': True
                              })
        else:
            logger.debug(
                "Registration form invalid. Returning for user %s to make corrections."
                % request.user)

    else:
        logger.debug("Returning blank registration form.")
        form = RegistrationForm()

    return render(request, 'public/register.html', context={'form': form})
Exemple #11
0
def signin(request):
    args = {}
    args.update(csrf(request))
    if request.method == "POST":
        form = RegistrationForm(request.POST)
        args["form"] = form
        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/applist")
    else:
        args["form"] = RegistrationForm()
    return render_to_response("signin.html", args, context_instance=RequestContext(request))
Exemple #12
0
 def test_registration_form_valid_existing_username(self):
     """
     Test that ``RegistrationForm`` enforces username length constraints
     """
     self.user = User.objects.create(
         username='******',
         password='******',
         email='*****@*****.**',
     )
     form_data = RegistrationFormTest.form_data_dict[1]
     form = RegistrationForm(data=form_data['data'])
     self.assert_(not form.is_valid())
Exemple #13
0
def signin(request):
    args = {}
    args.update(csrf(request))
    if (request.method == 'POST'):
        form = RegistrationForm(request.POST)
        args['form'] = form
        if form.is_valid():
            form.save()
            return (HttpResponseRedirect("/applist"))
    else:
        args['form'] = RegistrationForm()
    return (render_to_response('signin.html',
                               args,
                               context_instance=RequestContext(request)))
Exemple #14
0
def database_check(response):
    form = RegistrationForm(response.POST)
    if form.is_valid():
        email = form.cleaned_data["email"]
        has_email = database(
            'db.sqlite3', "SELECT email FROM User WHERE email = ?;", (email,))
        logged_in = None
        if has_email:
            logged_in = database(
                'db.sqlite3', "SELECT logged_in FROM User WHERE email = ?;", (email,))
        if not logged_in:
            return redirect('authentication:login')
        else:
            response.session['email'] = email
            return redirect('authentication:register')
Exemple #15
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect(reverse('home'))
        else:
            form = RegistrationForm()
            args = {'form': form}
            return render(request, 'registration/signup.html', args)
    else:
        form = RegistrationForm()

        args = {'form': form}
        return render(request, 'registration/signup.html', args)
Exemple #16
0
def register(request):
    if request.method == 'POST':
        user_form = RegistrationForm(request.POST)
        if user_form.is_valid():
            user = user_form.save()
            login(request, user)
            messages.success(request, 'Your profile was created successfully!')
            return redirect('details', pk=user.pk)
        else:
            user_form = RegistrationForm(request.POST)
            messages.warning(request, 'Correct the errors bellow.')
            return render(request, template_name='register.html', context={'user_form': user_form})
    elif request.method == 'GET':
        user_form = RegistrationForm()

    return render(request, template_name='register.html', context={'user_form': user_form})
Exemple #17
0
def register(request):
    form = RegistrationForm()
    if request.method=='POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            new_user = User.objects.create_user(username=form.cleaned_data['username'], 
                                                email=form.cleaned_data['email'], 
                                                password=form.cleaned_data['password1'])
            new_user.is_active = new_user.is_staff = True
            new_user.save()
            user = authenticate(username=form.cleaned_data['username'],password=form.cleaned_data['password1'])
            if user is not None:
                if user.is_active:
                    login(request, user)
                    return HttpResponseRedirect(reverse('polls:index'))
    return render_to_response('registration/registration_form.html',{'form':form,'errors':dict(form.errors.viewitems())},context_instance=RequestContext(request))
Exemple #18
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)

        if form.is_valid():
            profile = form.save()
            return redirect('registration_completed')
    else:
        form = RegistrationForm()

        # Resource can be passed as get parameter when user is coming from main page
        resource = request.GET.get('resource', '')
        if resource in RESOURCE_DICT:
            form.fields['resources1'].initial = [resource]

    return TemplateResponse(request, 'auth/register.html', {'form': form})
Exemple #19
0
 def handle(self, *args, **options):
     if len(args) == 0:
         count = 50
     else:
         count = args[0]
         
     for x in range(0, int(count)):
         data = {
             'username': '******' % x,
             'password1': 'test_password_%s' % x,
             'password2': 'test_password_%s' % x,
             'email': '*****@*****.**' % x
         }
         form = RegistrationForm(data)
         if form.is_valid():
             user = form.save(True)
             self.stdout.write('Sucessfully created user id %s' % user.id)
Exemple #20
0
def user_registration(request):
    """
    Displays the user registration form and handles the user creation action.
    """
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(username=form.cleaned_data['username'],
                                            first_name=form.cleaned_data['first_name'],
                                            last_name=form.cleaned_data['last_name'],
                                            email=form.cleaned_data['email'],
                                            password=form.cleaned_data['password'])
            user.save()
            return HttpResponseRedirect('/accounts/registration_success/')
        else:
            return render_to_response('register.html', {'form': form},
                                      context_instance=RequestContext(request))
    else:
        form = RegistrationForm()
        context = {'form': form}
        return render_to_response('register.html', context,
                                  context_instance=RequestContext(request))
Exemple #21
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            acc_type = form.cleaned_data.get('account_type')
            user = authenticate(username=username, password=password)
            acc = Account(user=user,
                          account_type=acc_type,
                          user_id=user.id,
                          id=user.id)
            if form.cleaned_data['avatar'] is not None:
                acc.avatar = form.cleaned_data['avatar']
            acc.save()
            login(request, user)
            return HttpResponseRedirect(
                '/accounts/profile/')  #redirect path after login here
    else:
        form = RegistrationForm()
    return render(request, 'registration.html', {'form': form})
Exemple #22
0
def register(request):
    #if request.user.is_authenticated():
    # They already have an account; don't let them register again
    #    return render_to_response('core/register.html', {'has_account': True})
    if request.method == 'GET':
        c = {}
        c.update(csrf(request))
        c['form'] = RegistrationForm()
        return render_to_response('authentication/register.html', c)

    if not request.method == 'POST': return HttpResponseRedirect('/')
    registrationForm = RegistrationForm(request.POST)
    if registrationForm.is_valid():
        user = registrationForm.save(commit=False)
        user.is_active = False
        user.save()
        profile = UserProfile(
            user=user,
            activation_key=hashlib.sha224(user.username).hexdigest()[:40],
            key_expires=datetime.datetime.today() + datetime.timedelta(days=2))
        profile.save()

        host = request.META['SERVER_NAME']
        email_subject = 'Welcome!'
        email_body = """Thanks for signing up.  To activate your account, follow this link: http://%(host)s/accounts/confirm/%(hash)s"""
        email_body = email_body % {
            'host': host,
            'hash': profile.activation_key
        }

        send_mail(email_subject, email_body, 'account_creator@' + host,
                  [user.email])
        return render_to_response('authentication/register.html',
                                  {'created': True})
    c = {}
    c.update(csrf(request))
    c['form'] = registrationForm
    return render_to_response('authentication/register.html', c)
Exemple #23
0
def register_view(request):
    if request.method == 'POST':

        form = RegistrationForm(request.POST, request.FILES)
        if form.is_valid():
            # TODO: hash password!

            # form.save()
            user = Profile.objects.create_user(
                username=form.data.get('username', ''),
                email=form.data.get('email', ''),
                password=form.data.get('password', ''),
                profile_picture_url=request.FILES['profile_picture_url'])
            user.save()
            # return HttpResponse('ok')
            # import ipdb; ipdb.set_trace()# BREAKPOINT)

            return HttpResponseRedirect(reverse('login'))

        # If form is not valid post errors
    status_message = 'Something went wrong while registering you!'
    form = RegistrationForm()
    return render(request, 'registration/registration_form.html', locals())
Exemple #24
0
def register(request):
    """
    Register a new user onto the platform
    """
    #pylint: disable=unused-variable
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                username=form.cleaned_data['username'],
                password=form.cleaned_data['password1'],
                email=form.cleaned_data['email'],
                first_name=form.cleaned_data['first_name'],
                last_name=form.cleaned_data['last_name'],
            )
            return HttpResponseRedirect('/register/success/')
    else:
        form = RegistrationForm()
    variables = RequestContext(request, {'form': form})

    return render_to_response(
        'registration/register.html',
        variables,
    )
Exemple #25
0
 def test_registration_form_email(self):
     form = RegistrationForm(data={"email": ''})
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors["email"], ["This field is required."])