Ejemplo n.º 1
0
def login(request):
    if request.method == 'GET':
        form = LoginForm()
        return render(request, 'newblog/login.html', {'form': form})
    else:
        form = LoginForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            username = cd['username']
            password = cd['password']
            user = auth.authenticate(username=username, password=password)
            if user is not None and user.is_active:
                auth.login(request, user)
                # return HttpResponseRedirect("newblog/")
                return HttpResponseRedirect("/newblog/myblog")
            else:
                return render(
                    request, 'newblog/login.html', {
                        'form':
                        form,
                        'error':
                        'Password is wrong or the username is not existed.'
                    })
        else:
            return render(request, 'newblog/login.html', {
                'form': form,
                'error': 'Username and Password is required.'
            })
Ejemplo n.º 2
0
def signup(request):
	if request.method == 'POST':
		form = LoginForm(request.POST)  
		if form.is_valid():
			cd = form.cleaned_data
			username = cd['username']
			password = cd['password']
			try:
				new_user = User.objects.create_user(username=username, password=password)
			except IntegrityError:
				error = "Username aleary existed, please choose another one"
				return render(request, 'newblog/signup.html', {'form': form, 'error':error})
			else:
				user= auth.authenticate(username=username, password=password)
				auth.login(request, user)
				return HttpResponseRedirect("/newblog")
	else:
		form = LoginForm()
		return render(request, 'newblog/signup.html', {'form': form})
Ejemplo n.º 3
0
def login(request):
	if request.method == 'GET':  
		form = LoginForm()  
		return render(request, 'newblog/login.html', {'form': form})
	else:
		form = LoginForm(request.POST)  
		if form.is_valid():  
			cd = form.cleaned_data
			username = cd['username']
			password = cd['password']
			user = auth.authenticate(username=username, password=password)
			if user is not None and user.is_active:
				auth.login(request, user)
				# return HttpResponseRedirect("newblog/")
				return HttpResponseRedirect("/newblog/myblog")
			else:
				return render(request, 'newblog/login.html', {'form': form, 'error': 'Password is wrong or the username is not existed.'})
		else:  
			return render(request, 'newblog/login.html', {'form': form, 'error': 'Username and Password is required.'})
Ejemplo n.º 4
0
def signup(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            username = cd['username']
            password = cd['password']
            try:
                new_user = User.objects.create_user(username=username,
                                                    password=password)
            except IntegrityError:
                error = "Username aleary existed, please choose another one"
                return render(request, 'newblog/signup.html', {
                    'form': form,
                    'error': error
                })
            else:
                user = auth.authenticate(username=username, password=password)
                auth.login(request, user)
                return HttpResponseRedirect("/newblog")
    else:
        form = LoginForm()
        return render(request, 'newblog/signup.html', {'form': form})