Example #1
0
def register(request):
    error = []
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            username = data['username']
            email = data['email']
            password = data['password']
            password2 = data['password2']
            if not User.objects.all().filter(username=username):
                if form.pwd_validate(password, password2):
                    user = User.objects.create_user(username, email, password)
                    user.save()
                    login_validate(request, username, password)
                    return render_to_response('welcome.html',
                                              {'user': username})
                else:
                    error.append('Please input the same password')
            else:
                error.append(
                    'The username has existed,please change your username')
    else:
        form = RegisterForm()
    return render_to_response('register.html', {'form': form, 'error': error})
Example #2
0
def register(request):
    error = ''
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            email = form.cleaned_data['email']
            password = form.cleaned_data['password']
            password2 = form.cleaned_data['password2']
            if not User.objects.all().filter(username=username):
                if form.pwd_validate(password, password2):
                    user = User.objects.create_user(username, email, password)
                    user.is_staff = True
                    user.save()

                    return render_to_response('login.html')
                else:
                    error = "Please input the same password"
            else:
                error = "The username has existed,please change you username"
        else:
            error = "The email is invalid,please change your email"
    return render_to_response('register.html', {'error': error})
Example #3
0
def register(request):
    error =[]
    if request.method =='POST':
        form=RegisterForm(request.POST)
        if form.is_valid():
            data=form.cleaned_data
            username=data['username']
            email=data['email']
            password=data['password']
            password2=data['password2']
            if not User.objects.all().filter(username=username):
                if form.pwd_validate(password,password2):
                    user=User.objects.create_user(username,email,password)
                    user.save()
                    login_validate(request,username,password)
                    return render_to_response('index.html',{'user':username},context_instance=RequestContext(request));
                else:
                    error.append('Please input the same password ')
            else:
                error.append('The username is existed,please type anthor  usrename')
    else:
        form=RegisterForm()
    return render_to_response('register.html',{'form':form,'error':error})