Ejemplo n.º 1
0
def login(request):
    if request.user['is_authenticated']:
	return HttpResponseRedirect('/')
    login_form = LoginForm()
    register_form = RegistrationForm()
    next = request.REQUEST.get('next')
    if 'kind' in request.POST:
        if request.POST['kind'] == 'login':
            login_form = LoginForm(request.POST)
            if login_form.is_valid():
                username = login_form.get_username()
                request.session['username'] = username
                if next:
                    return HttpResponseRedirect(next)
                return HttpResponseRedirect('/user')
        elif request.POST['kind'] == 'register':
            register_form = RegistrationForm(request.POST)
            if register_form.is_valid():
                username = register_form.save()
                request.session['username'] = username
                if next:
                    return HttpResponseRedirect(next)
                return HttpResponseRedirect('/user/welcome')
    context = {
        'login_form': login_form,
        'register_form': register_form,
        'next': next,
    }
    return render_to_response(
        'auth/login.html', context, context_instance=RequestContext(request))
Ejemplo n.º 2
0
def signup(request):
    if request.method == 'POST':
        user_form = RegistrationForm(request.POST)
        if user_form.is_valid():
            user_form.save()
            return render(request, 'accounts/signup_finish.html',
                          {'form': user_form})
    else:
        user_form = RegistrationForm()
    return render(request, 'accounts/signup.html', {'form': user_form})
Ejemplo n.º 3
0
def test_registration_form_is_valid():
    form = RegistrationForm({
        'email': '*****@*****.**',
        'first_name': 'Dan',
        'last_name': 'Sackett',
        'username': '******',
        'password': '******',
        'confirm_password': '******',
    })
    assert form.is_valid()
Ejemplo n.º 4
0
def test_registration_form_is_not_valid_due_to_confirm_password_missing():
    form = RegistrationForm({
        'email': '*****@*****.**',
        'first_name': 'Dan',
        'last_name': 'Sackett',
        'username': '******',
        'password': '******',
    })
    assert not form.is_valid()
    assert ['confirm_password'] == form.errors.keys()
Ejemplo n.º 5
0
def register(request, form_id, email, password,  **kwargs):
    dajax = Dajax()
    clear_form_errors(dajax, form_id)
    
    form = RegistrationForm(data={'email' : email, 'password' : password})
    if form.is_valid():
        form.save(request = request)
        dajax.script("$('#modal').load('%s')" % reverse('auth_confirmation_sent')) 
    else:
        set_form_errors(dajax, form_id, form.errors)
        
    return dajax.json()
Ejemplo n.º 6
0
def test_registration_form_creates_user():
    form = RegistrationForm({
        'email': '*****@*****.**',
        'first_name': 'Dan',
        'last_name': 'Sackett',
        'username': '******',
        'password': '******',
        'confirm_password': '******',
    })
    assert form.is_valid()
    form.save()
    assert len(User.objects.all()) == 1
Ejemplo n.º 7
0
Archivo: views.py Proyecto: chinspp/42
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("/"))
    else:
        args['form'] = RegistrationForm()
    return (render_to_response('signin.html', args, context_instance=RequestContext(request)))
Ejemplo n.º 8
0
def register(request):
    auth_form = AuthenticationForm() 
    if request.POST:
        form = RegistrationForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            d_login(request, new_user)
            return HttpResponseRedirect('/')
    else:
         form = RegistrationForm()
    return render_to_response('registration_form.html',
                              { 'form': form, 'auth_form': auth_form },
                              context_instance=RequestContext(request))
Ejemplo n.º 9
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/accounts/login/')
        else:
            return render(request, 'registration/reg_form.html',
                          {'form': form})
    else:
        form = RegistrationForm()

        return render(request, 'registration/reg_form.html', {'form': form})
Ejemplo n.º 10
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("/"))
    else:
        args['form'] = RegistrationForm()
    return (render_to_response('signin.html',
                               args,
                               context_instance=RequestContext(request)))
Ejemplo n.º 11
0
def signup(request):
    username = None

    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data['username']
            form = None
    else:
        form = RegistrationForm()

    context = {'form': form, 'username': username}

    return render(request, 'signup.html', context)
Ejemplo n.º 12
0
def register(request):
    """ Registers a member """
    form = RegistrationForm()

    if request.method == 'POST':
        data = request.POST
        form = RegistrationForm(data)

        if form.is_valid():
            user = form.save(request) #profile_callback=Member.objects.profile_callback)
            return HttpResponseRedirect(reverse('register_success'))

    return render_to_response('auth/register.html', {
        'form': form,
    }, RequestContext(request))
Ejemplo n.º 13
0
Archivo: views.py Proyecto: chinspp/42
def signin(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect("/", {"user": request.user})
    args = {}
    args.update(csrf(request))
    args["title"] = "Sign In"
    if request.method == "POST":
        form = RegistrationForm(request.POST)
        args["form"] = form
        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/")
    else:
        args["form"] = RegistrationForm()
    return render_to_response("form.html", args, context_instance=RequestContext(request))
Ejemplo n.º 14
0
Archivo: views.py Proyecto: anmic/Blog
def register(request):
    if request.method == "POST":
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(form.cleaned_data['username'],
                                            form.cleaned_data['email'],
                                            form.cleaned_data['password'])
            user.first_name = form.cleaned_data['first_name']
            user.last_name = form.cleaned_data['last_name']
            user.save()
            messages.success(request, "Success register. Let,s login.")
            return HttpResponseRedirec("/tauth/login/")
    else:
        form = RegistrationForm()
    return render_to_response("auth/register.html", {"form": form},
                              context_instance=RequestContext(request))
Ejemplo n.º 15
0
Archivo: views.py Proyecto: ryanrdk/42
def signin(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect('/', {"user": request.user})
    args = {}
    args.update(csrf(request))
    args['title'] = "Sign In"
    if (request.method == 'POST'):
        form = RegistrationForm(request.POST)
        args['form'] = form
        if form.is_valid():
            form.save()
            return (HttpResponseRedirect("/"))
    else:
        args['form'] = RegistrationForm()
    return (render_to_response('form.html',
                               args,
                               context_instance=RequestContext(request)))
Ejemplo n.º 16
0
def register(request):
    c = {}
    c.update(csrf(request))
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            newuser = User.objects.create_user(username=username, email='', password=password)
            if form.cleaned_data.get('email'):
                newuser.email = form.cleaned_data.get('email')
                EmailValidation.objects.add(user=newuser, email=newuser.email)
            newuser.save()
            return HttpResponseRedirect('%scomplete/' % request.path_info)
    else:
        form = RegistrationForm()
    template = "userprofile/account/registration.html"
    data = { 'form': form }
    return render_to_response(template, data, context_instance=RequestContext(request))
Ejemplo n.º 17
0
def register(request):
    """Allow a user to register for the site"""
    form = RegistrationForm(request.POST or None)

    if request.method == 'POST' and form.is_valid():
        form.save()
        username = form.cleaned_data.get('username')
        password = form.cleaned_data.get('password')
        user = auth.authenticate(username=username, password=password)

        if user:
            auth.login(request, user)
            return redirect('user-home')

        return redirect('login')

    context = {
        'form': form,
    }
    return render(request, 'auth/register.html', context)
Ejemplo n.º 18
0
    def post(self, request, user, feed):
        register_form = None
        register_user = None
        subscribe_form = PaymentForm(request.POST)

        if self.request.user.is_anonymous():
            register_form = RegistrationForm(request.POST)

        if ((register_form and register_form.is_valid()) or register_form == None) and subscribe_form.is_valid():
            if register_form:
                register_user = register_form.save(request)
                register_user.profile.status = 'REG'
                register_user.profile.save()

                registed_user = authenticate(
                    username=request.POST.get('username'),
                    password=request.POST.get('password')
                )

            FeedSubscriber.objects.get_or_create(feed=feed, user=register_user or request.user)


        if request.is_ajax():
            response = {
                'error': subscribe_form.errors,
                'success_url': reverse('feed_detail', args=[
                    feed.publisher.username,
                    feed.slug
                ])
            }

            if register_form:
                response['error'].update(register_form.errors)

            status = 200
            if response['error']:
                status = 400

            return HttpResponse(json.dumps(response), status=status, mimetype="application/json")

        return self.render(user, feed, register_form, subscribe_form)
Ejemplo n.º 19
0
def register(request):
    if request.method == 'GET':
        form = RegistrationForm()
    elif request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = get_user_model()
            user = user()
            user.username = form.cleaned_data.get('username')
            user.email = form.cleaned_data.get('email')
            user.password = make_password(form.cleaned_data.get('password'))
            user.is_active = False
            user.reset_activation_token()
            user.generate_verification_token()
            user.save()

            return redirect("%s?message=%s" %
                            (reverse('message'), REG_SUCCESSFUL))
    else:
        return HttpResponseNotAllowed(permitted_methods=['POST', 'GET'])
    return render(request, 'registration/register.html', {'form': form})
Ejemplo n.º 20
0
def register(request):
    if request.method == 'GET':
        form = RegistrationForm()
    elif request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = get_user_model()
            user = user()
            user.username = form.cleaned_data.get('username')
            user.email = form.cleaned_data.get('email')
            user.password = make_password(form.cleaned_data.get('password'))
            user.is_active = False
            user.reset_activation_token()
            user.generate_verification_token()
            user.save()
            
            return redirect("%s?message=%s" %
                (reverse('message'), REG_SUCCESSFUL))
    else:
        return HttpResponseNotAllowed(permitted_methods=['POST', 'GET'])
    return render(request, 'registration/register.html', {'form':form})
Ejemplo n.º 21
0
def register_user(request):
    state = "Please fill in all of the blanks below..."

    if request.method == "POST":
        form = RegistrationForm(request.POST)
        if form.is_valid():  # add user existing check, password same check
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            email = form.cleaned_data["email"]

            new_user = User.objects.create_user(username, email, password)
            new_s_user = SherlockUser.objects.create_SherlockUser(new_user)
            new_user.save()
            new_s_user.save()

            user = authenticate(username=username, password=password)
            login(request, user)
            return HttpResponseRedirect("/home/")
    else:
        form = RegistrationForm()

    return render(request, "register.html", {"form": form})
Ejemplo n.º 22
0
def register(request):
    c = {}
    c.update(csrf(request))
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            newuser = User.objects.create_user(username=username,
                                               email='',
                                               password=password)
            if form.cleaned_data.get('email'):
                newuser.email = form.cleaned_data.get('email')
                EmailValidation.objects.add(user=newuser, email=newuser.email)
            newuser.save()
            return HttpResponseRedirect('%scomplete/' % request.path_info)
    else:
        form = RegistrationForm()
    template = "userprofile/account/registration.html"
    data = {'form': form}
    return render_to_response(template,
                              data,
                              context_instance=RequestContext(request))
Ejemplo n.º 23
0
def test_registration_form_is_not_valid_due_to_username_being_taken():
    # setup user
    user = User(
        username='******',
        first_name='First Name',
        last_name='Last Name',
        email='*****@*****.**',
        is_active=True,
        is_staff=False,
        date_joined=datetime.datetime.now(),
    )
    user.set_password('P@ssw0rd!')
    user.save()

    form = RegistrationForm({
        'email': '*****@*****.**',
        'first_name': 'Dan',
        'last_name': 'Sackett',
        'username': '******',
        'password': '******',
        'confirm_password': '******',
    })
    assert not form.is_valid()
    assert ['username'] == form.errors.keys()
Ejemplo n.º 24
0
def register_user(request):
    state = "Please fill in all of the blanks below..."
    
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():#add user existing check, password same check
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            email = form.cleaned_data['email']

            new_user = User.objects.create_user(username, email, password)
            new_s_user = DDAUser.objects.create_DDAUser(new_user) 
            new_user.save()
            new_s_user.save()

            user = authenticate(username=username, password=password)
            login(request, user)            
            return HttpResponseRedirect('/home/')
    else:
        form = RegistrationForm()

    return render(request, 'register.html', {
        'form': form,
    })