Exemplo n.º 1
0
def register_user(request):
    
    template_name = 'kitchen/crispy.html'

    if request.method == 'POST':
        user_form = UserCreateForm(request.POST)
        if user_form.is_valid():
            username = user_form.clean_username()
            password = user_form.clean_password2()
            user_form.save()
            
            user = authenticate(username=username,
                                password=password)
            if user:
                # save extra parameters - email
                user.email = user_form.data['email']
                user.save()
                #ASK - may be we should init it only in one place - on login?
                initUser(user)
                login(request, user)
                return redirect('account-list')
        return render(request,
                      template_name,
                      { 'form' : user_form })
    args = {}
    args.update(csrf(request))
    args['form'] = UserCreateForm()
    print args
    return render(request, template_name, args)
Exemplo n.º 2
0
def register_user(request):

    template_name = 'kitchen/crispy.html'

    if request.method == 'POST':
        user_form = UserCreateForm(request.POST)
        if user_form.is_valid():
            username = user_form.clean_username()
            password = user_form.clean_password2()
            user_form.save()

            user = authenticate(username=username, password=password)
            if user:
                # save extra parameters - email
                user.email = user_form.data['email']
                user.save()
                #ASK - may be we should init it only in one place - on login?
                initUser(user)
                login(request, user)
                return redirect('account-list')
        return render(request, template_name, {'form': user_form})
    args = {}
    args.update(csrf(request))
    args['form'] = UserCreateForm()
    print args
    return render(request, template_name, args)
Exemplo n.º 3
0
def signup(request):
    user_form = UserCreateForm(data=request.POST)
    if request.method == 'POST':
        if user_form.is_valid():
            username = user_form.clean_username()
            password = user_form.clean_password2()
            user_form.save()
            user = authenticate(username=username, password=password)
            login(request, user)
            return redirect('/')
        else:
            return index(request, user_form=user_form)
    return redirect('/')
Exemplo n.º 4
0
def create_user(request):
    if request.POST:
        user_form = UserCreateForm(request.POST)
        if user_form.is_valid():
            username = user_form.clean_username()
            password = user_form.clean_password2()
            user_form.save()
            user = authenticate(username=username, password=password)
            login(request, user)
            request.session["notice"] = "User successfully logged in"
            return HttpResponseRedirect("/")
    else:
        user_form = UserCreateForm()

    return render_to_response('users/create_user.html', {'user_form': user_form}, context_instance=RequestContext(request))
Exemplo n.º 5
0
def register(request):
	if request.method == 'GET':
		form = UserCreateForm()
		return render_to_response("register.html", RequestContext(request, {"form": form, }))
	else:
		form = UserCreateForm(request.POST)
		if form.is_valid():
			username = form.clean_username()
			password = form.clean_password2()
			
			form.save()
			user = authenticate(username=username, password=password)
			login(request, user)
			return HttpResponseRedirect("/")
		else:
			return render_to_response("register.html", RequestContext(request, {"form": form, "account_error": True }))
Exemplo n.º 6
0
def create_user(request):
    if request.POST:
        user_form = UserCreateForm(request.POST)
        if user_form.is_valid():
            username = user_form.clean_username()
            password = user_form.clean_password2()
            user_form.save()
            user = authenticate(username=username, password=password)
            login(request, user)
            request.session["notice"] = "User successfully logged in"
            return HttpResponseRedirect("/")
    else:
        user_form = UserCreateForm()

    return render_to_response('users/create_user.html',
                              {'user_form': user_form},
                              context_instance=RequestContext(request))
Exemplo n.º 7
0
def sign_up(request, user_form=None, incomplete_form=None):

    if request.method == 'POST' and incomplete_form is None:
        user_form = UserCreateForm(data=request.POST)
        if user_form.is_valid():
            max_username = User.objects.all().aggregate(Max('username'))['username__max']
            if(max_username!=None and max_username!='admin'):
                temp='ID00'+str(int(max_username[2:])+1)
            else:
                temp='ID001001'
            user_form.cleaned_data['card_no']=temp
            user_form.cleaned_data['username']=temp
            password = user_form.clean_password2()
            user_form.save()
            user = authenticate(username=temp, password=password)
            login(request, user)
            return redirect('/')
        else:
            messages.error(request, "Form invalid")
            return sign_up(request, user_form=user_form, incomplete_form=True)
    if incomplete_form is None or not incomplete_form:
        user_form = UserCreateForm()
    return render(request, 'sign_up.html', {'user_form': user_form})
Exemplo n.º 8
0
def sign_up(request, user_form=None, incomplete_form=None):

    if request.method == 'POST' and incomplete_form is None:
        user_form = UserCreateForm(data=request.POST)
        if user_form.is_valid():
            max_username = User.objects.all().aggregate(
                Max('username'))['username__max']
            if (max_username != None and max_username != 'admin'):
                temp = 'ID00' + str(int(max_username[2:]) + 1)
            else:
                temp = 'ID001001'
            user_form.cleaned_data['card_no'] = temp
            user_form.cleaned_data['username'] = temp
            password = user_form.clean_password2()
            user_form.save()
            user = authenticate(username=temp, password=password)
            login(request, user)
            return redirect('/')
        else:
            messages.error(request, "Form invalid")
            return sign_up(request, user_form=user_form, incomplete_form=True)
    if incomplete_form is None or not incomplete_form:
        user_form = UserCreateForm()
    return render(request, 'sign_up.html', {'user_form': user_form})