Exemplo n.º 1
0
def login(request):
	form = UsersForm(request.POST)
	s = request.session.get('users_id', None)
	if not s:
		return HttpResponseRedirect('/login/auth')
	data = {}
	data['error_massage']=""
	if request.method == 'POST':
		if form.is_valid():
			form.save()
		email = request.POST.get('email', None)
		password = request.POST.get('password', None)
		password_password =  make_password(password)
		try:
			users = Users.objects.get(email=email)
			if users.email == email and check_password("password", password_password):	
				request.session['users_id'] = users.id
				return HttpResponseRedirect('/login/')
			else:
				return HttpResponseRedirect('/login/auth')
		except Users.DoesNotExist:
			return HttpResponseRedirect('/login/auth')
	else :
		form = UsersForm()
	list_item = Users.objects.all()
	data['id'] = None
	data['list_item'] = list_item
	data['form'] = form
	return render(
		request,
		'users/login.html',
		data
	)
Exemplo n.º 2
0
def login(request):
    form = UsersForm(request.POST)
    s = request.session.get('users_id', None)
    if not s:
        return HttpResponseRedirect('/login/auth')
    data = {}
    data['error_massage'] = ""
    if request.method == 'POST':
        if form.is_valid():
            form.save()
        email = request.POST.get('email', None)
        password = request.POST.get('password', None)
        password_password = make_password(password)
        try:
            users = Users.objects.get(email=email)
            if users.email == email and check_password("password",
                                                       password_password):
                request.session['users_id'] = users.id
                return HttpResponseRedirect('/login/')
            else:
                return HttpResponseRedirect('/login/auth')
        except Users.DoesNotExist:
            return HttpResponseRedirect('/login/auth')
    else:
        form = UsersForm()
    list_item = Users.objects.all()
    data['id'] = None
    data['list_item'] = list_item
    data['form'] = form
    return render(request, 'users/login.html', data)
Exemplo n.º 3
0
def update_item(request, id):
	data = {}
	try:
		selected_item = Users.objects.get(pk=id)
		form = UsersForm(instance=selected_item)
	except Users.DoesNotExist:
		raise Http404("This item not exist.")
	if request.method == 'POST':
		form = UsersForm(request.POST or None, instance=selected_item)
		if form.is_valid():
			form.save()
			return HttpResponseRedirect('/login/admin')
	list_item = Users.objects.all()
	data['id'] = id
	data['list_item'] = list_item
	data['form'] = form
	return render(
		request,
		'users/login.html',
		data
	)
Exemplo n.º 4
0
def remove_item(request, id):
    data = {}
    try:
        selected_item = Users.objects.get(pk=id)
        selected_item.delete()
        form = UsersForm()
    except Users.DoesNotExist:
        raise Http404("This item not exist.")
    list_item = Users.objects.all()
    data['id'] = None
    data['list_item'] = list_item
    data['form'] = form
    return HttpResponseRedirect('/login', data)
Exemplo n.º 5
0
def update_item(request, id):
    data = {}
    try:
        selected_item = Users.objects.get(pk=id)
        form = UsersForm(instance=selected_item)
    except Users.DoesNotExist:
        raise Http404("This item not exist.")
    if request.method == 'POST':
        form = UsersForm(request.POST or None, instance=selected_item)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/login/admin')
    list_item = Users.objects.all()
    data['id'] = id
    data['list_item'] = list_item
    data['form'] = form
    return render(request, 'users/login.html', data)