Exemplo n.º 1
0
def index(request):
    """
    If a user is logged in, returns the main index of all of a user's
    clipboard history sorted with the most recent at the top.
    Paginates the data using django-pagination, currently uses
    Twitter style pagination.

    If a user is not logged in, just offers up a registration/login form.
    """
    clippings = Clipping.objects.filter(
        created_by=request.user.id).order_by("-time")
    if request.user.is_authenticated():
        context = {'clippings': clippings}
        if request.is_ajax():
            return render(request, 'pagination.html', context,)
        else:
            return render(request, 'index.html', context)
    else:
        form = RegistrationForm()
        context = {'form': form}
        if request.method == 'POST':
            form = RegistrationForm(request.POST)
            if form.is_valid():
                user = User.objects.create_user(
                    username=form.cleaned_data['username'],
                    email=form.cleaned_data['email'],
                    password=form.cleaned_data['password']
                )
                user.save()
                return redirect(reverse('login'))
            else:
                return render(request, 'index.html', {'form': form})
        else:
            return render(request, 'index.html', context)
Exemplo n.º 2
0
def User_Registration(request):

    if request.method == "POST":
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                username=form.cleaned_data["username"],
                email=form.cleaned_data["email"],
                password=form.cleaned_data["password"],
            )
            user.save()
            #                    users = user.get.profile()
            #                    users.name = form.cleaned_data['name']
            #                    users.birthday = form.cleaned_data['birthday']
            #                    users.save()
            users = Users(user=user, name=form.cleaned_data["name"], birthday=form.cleaned_data["birthday"])
            users.save()
            return HttpResponseRedirect("/")
        else:
            return render_to_response("RegisterUser.html", {"form": form}, context_instance=RequestContext(request))
    else:
        """ user is not submitting the form, show them a blank registration form """
        form = RegistrationForm()
        context = {"form": form}
        return render_to_response("RegisterUser.html", context, context_instance=RequestContext(request))
Exemplo n.º 3
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            email = form.cleaned_data['email']
            password = form.cleaned_data['password1']

            salt = sha.new(str(random.random())).hexdigest()[:5]
            activation_key = sha.new(salt+username).hexdigest()
            key_expires = datetime.datetime.today() + datetime.timedelta(2)

            user = User.objects.create_user(username, email, password)
            user.is_active = False
            user.save()

            user_profile = UserProfile(user=user, activation_key=activation_key, key_expires=key_expires)
            user_profile.save()
    
            email_subject = "PartyMaker EMail Bestätigung"
            email_text = "Hallo %s,\n du hast dich bei Party Maker regierstriert. Klicke auf den folgenden\
                Link um deinen Account zu aktivieren.\n http://localhost:8000/validate/%s\n mfG das PartyMaker Team" % (
                    username, activation_key)
            email_address=settings.REGISTRATION_EMAIL_ADDRESS
            send_mail(email_subject, email_text, email_address, [email])
            return HttpResponseRedirect('thanks')
    else: 
         form = RegistrationForm()
    return render_to_response('register.xhtml', {'form':form},  context_instance=RequestContext(request)) 
Exemplo n.º 4
0
def registration_view(request):
    cart = try_session(request)
    form = RegistrationForm(request.POST or None)
    if form.is_valid():
        new_user = form.save(commit=False)
        username = form.cleaned_data['username']
        password = form.cleaned_data['password']
        new_user.username = username
        new_user.set_password(password)
        new_user.first_name = form.cleaned_data['first_name']
        new_user.last_name = form.cleaned_data['last_name']
        phone = Phone(user= username, phone =form.cleaned_data['phone'] )
        new_user.email = form.cleaned_data['email']
        new_user.save()
        phone.save()
        login_user = authenticate(username=username, password=password)
        if login_user:
            login(request, login_user)
            return HttpResponseRedirect(reverse('base'))
    c = count(cart)
    context = {
        'c': c,
        'cart': cart,
        'categories': get_categories(),
        'form': form,
    }
    return render(request,'registration.html',context)
Exemplo n.º 5
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            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']
            sexe = form.cleaned_data['sexe']
            user_address = form.cleaned_data['user_address']
            type = form.cleaned_data['type']

            user = User.objects.create_user(username=username,
                                            password=password,
                                            email=email,
                                            last_name=last_name,
                                            first_name=first_name)
            user = authenticate(username=username, password=password)
            login(request, user)
            if type == 'candidate':
                user_account(user=user, user_address=user_address,
                             gender=sexe).save()
                return jobs(request)
            else:
                recruiter(user=user, user_address=user_address,
                          gender=sexe).save()
                return redirect('main:complete-company')

    return render(request=request,
                  template_name='main/signin.html',
                  context={'form': RegistrationForm})
Exemplo n.º 6
0
def register(request):
    args = {}
    args.update(csrf(request))
    if request.method == 'POST':
        register_form = RegistrationForm(request.POST)  # create form object
        if register_form.is_valid():
            register_form.save()
            username = request.POST['username']
            password = request.POST['password1']
            user = authenticate(username=username, password=password)
            if user is not None:
                auth.login(request, user)

            html_register = get_template('email_register.html', )
            register_html = Context({'first_name': request.user.first_name, 'last_name': request.user.last_name})
            html_content = html_register.render(register_html)
            subject = 'Regisration'
            from_email = '*****@*****.**'
            to = auth.get_user(request).email
            msg = EmailMultiAlternatives(subject, '', from_email, [to])
            msg.attach_alternative(html_content, "text/html")
            try:
                msg.send()
            except:
                pass
            return redirect('index')
        else:
            args['custom_error'] = register_form
        args['register_form'] = register_form
    else:
        register_form = RegistrationForm()
        args['register_form'] = register_form

    return render(request, 'register.html', args)
Exemplo n.º 7
0
def analyzer_signup(request):
    """
	Sign up for an assistant account.
	"""

    if request.user.is_authenticated():
        return redirect('internal:profile')
    if request.method == 'POST':
        post = request.POST.copy()
        request.POST = post

        form = RegistrationForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            password = cd['password1']
            user = form.save()
            g, created = Group.objects.get_or_create(name='assistant')
            g.user_set.add(user)
            g.save()
            user = auth.authenticate(username=user.email, password=password)
            auth.login(request, user)
            return redirect('internal:profile')
        return render(request, 'analyzer_signup.html', {'form': form})
    else:
        form = RegistrationForm()
        return render(request, 'analyzer_signup.html', {'form': form})
Exemplo n.º 8
0
 def test_UserForm_invalid(self):
     form = RegistrationForm(
         data={
             'name': 'vaibhav',
             'email': '[email protected]',
             'branch': 'cse',
             'year': 'first',
             'github_url': 'test'
         })
     self.assertFalse(form.is_valid())
Exemplo n.º 9
0
 def test_UserForm_valid(self):
     form = RegistrationForm(
         data={
             'name': 'vaibhav',
             'email': '*****@*****.**',
             'branch': 'cse',
             'year': 2014,
             'github_url': 'https://github.com/vaibhavsingh97/'
         })
     self.assertTrue(form.is_valid())
Exemplo n.º 10
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/qwer')
    else:
        form = RegistrationForm()
        arg = {'form': form}
        return render(request, 'main/register.html', arg)
Exemplo n.º 11
0
def registration(request):
    edit_form = RegistrationForm()
    if request.method == 'POST':
        edit_form = RegistrationForm(data=request.POST)
        if edit_form.is_valid():
            user = edit_form.save(commit=False)
            user.username = str(uuid.uuid4().int)[:10]
            user.save()
            return redirect('login')

    return render(request, 'main/registration.html', {'edit_form': edit_form})
Exemplo n.º 12
0
def register(request):
    """Register and create a user if a valid form is submitted"""
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            return redirect('login')
    else:
        form = RegistrationForm()
    return render(request, 'main/register.html', {'form': form})
Exemplo n.º 13
0
def registration(request, template_name='main/registration.html'):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            hero = Hero(login=form.cleaned_data['login'],
                        password=form.cleaned_data['password1'],
                        email=form.cleaned_data['email'],
                        sex=form.cleaned_data['sex'])
            hero.save()
            request.session['hero_id'] = hero.id
            return HttpResponseRedirect(reverse('hero'))
    else:
        form = RegistrationForm()

    variables = RequestContext(request, {'form': form})

    return render_to_response(template_name, variables)
Exemplo n.º 14
0
def registration(request, template_name='main/registration.html'):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            hero = Hero(login=form.cleaned_data['login'],
                        password=form.cleaned_data['password1'],
                        email=form.cleaned_data['email'],
                        sex = form.cleaned_data['sex'])
            hero.save()
            request.session['hero_id'] = hero.id
            return HttpResponseRedirect(reverse('hero'))
    else:
        form = RegistrationForm()

    variables = RequestContext(request, {'form': form})

    return render_to_response(template_name, variables)
Exemplo n.º 15
0
def index_page(request):
    was_saved = False
    show_message = u''
    if request.method == 'POST':
        if 'new_register' in request.POST:
            form = RegistrationForm()
        else:
            form = RegistrationForm(request.POST)
            if form.is_valid():
                form.save()
                was_saved = True
                show_message = form.message
                form = RegistrationForm()
    else:
        form = RegistrationForm()
    ctx = {'show_message': show_message, 'was_saved': was_saved, 'form': form}
    return render(request, 'index.html', ctx)
Exemplo n.º 16
0
def register(request):
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = RegistrationForm(request.POST)
        # check whether it's valid:
        if form.is_valid():
            post = form.save(commit=False)
            post.save()
            # process the data in form.cleaned_data as required
            # ...
            # redirect to a new URL:
            messages.success(request, 'You successfully registered.')

    # if a GET (or any other method) we'll create a blank form
    else:
        form = RegistrationForm()

    return render(request, 'register.html', {'form': form})
Exemplo n.º 17
0
def signup(request):
    """ User signup page """
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            email = form.cleaned_data['email']
            if User.objects.filter(username=username):
                form = RegistrationForm()
                return render(request, 'signup.html', {'form':form})
            else:
                user = User.objects.create_user(username, email, password)
                user.save()
                user = authenticate(username=username, password=password)
                auth.login(request, user)
                return HttpResponseRedirect('profile')
    else:
        form = RegistrationForm()
    return render(request, 'signup.html', {'form':form})
Exemplo n.º 18
0
def index_page(request):
    was_saved = False
    show_message = u''
    if request.method == 'POST':
        if 'new_register' in request.POST:
            form = RegistrationForm()
        else:
            form = RegistrationForm(request.POST)
            if form.is_valid():
                form.save()
                was_saved = True
                show_message = form.message
                form = RegistrationForm()
    else:
        form = RegistrationForm()
    ctx = {
        'show_message': show_message,
        'was_saved': was_saved,
        'form': form
    }
    return render(request, 'index.html', ctx)
Exemplo n.º 19
0
 def post(self, request):
     form = RegistrationForm(request.POST)
     if not form.is_valid():
         return render(request, 'register.html', {"form": form})
     email = form.cleaned_data['email']
     first_name = form.cleaned_data['name']
     last_name = form.cleaned_data['surname']
     password = form.cleaned_data['password']
     password_2 = form.cleaned_data['password2']
     if password != password_2:
         messages.add_message(
             request, messages.WARNING,
             'Błędnie powtórzone hasło. Spróbuj jeszcze raz.')
         return render(request, 'register.html', {"form": form})
     if User.objects.filter(email=email).exists():
         messages.add_message(request, messages.WARNING,
                              'Profil o podanym emailu już istnieje.')
         return render(request, 'register.html', {"form": form})
     User.objects.create_user(username=email,
                              email=email,
                              password=password,
                              first_name=first_name,
                              last_name=last_name)
     return redirect('login')
Exemplo n.º 20
0
def User_Registration(request):
    if request.user.is_authenticated():
            return HttpResponseRedirect('/profile/')
    if request.method == 'POST':
            form = RegistrationForm(request.POST)
            if form.is_valid():
                    print "Formulario Valido"
                    user = User.objects.create_user(username=form.cleaned_data['username'], email=form.cleaned_data['email'], password=form.cleaned_data['password'])
                    user.save()
#                    users = user.get.profile()
#                    users.name = form.cleaned_data['name']
#                    users.birthday = form.cleaned_data['birthday']
#                    users.save()
#                    users = UserProfile(user=user, birthday=form.cleaned_data['birthday'])
#                   users.save()
                    return redirect('LoginRequest')
            else:
                print "Formulario Invalido"
                return render_to_response('RegisterUser.html', {'form': form}, context_instance=RequestContext(request))
    else:
            ''' user is not submitting the form, show them a blank registration form '''
            form = RegistrationForm()
            context = {'form': form}
            return render_to_response('RegisterUser.html', context, context_instance=RequestContext(request))
Exemplo n.º 21
0
 def test_registaration_in_valid(self):
     request_form = RegistrationForm()
     self.assertFalse(request_form.is_valid())