Exemple #1
0
def users(request):
    form = UsersForm(request.POST)
    s = request.session.get('users_id', None)
    if not s:
        return HttpResponseRedirect('/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('/users')
            else:
                return HttpResponseRedirect('/auth')
        except Users.DoesNotExist:
            return HttpResponseRedirect('/auth')
    else:
        form = UsersForm()
    list_item = Users.objects.all()
    data['id'] = None
    data['list_item'] = list_item
    data['form'] = form
    return render(request, 'home/users.html', data)
Exemple #2
0
def users(request):
	form = UsersForm(request.POST)
	s = request.session.get('users_id', None)
	if not s:
		return HttpResponseRedirect('/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('/users')
			else:
				return HttpResponseRedirect('/auth')
		except Users.DoesNotExist:
			return HttpResponseRedirect('/auth')
	else :
		form = UsersForm()
	list_item = Users.objects.all()
	data['id'] = None
	data['list_item'] = list_item
	data['form'] = form
	return render(
		request,
		'home/users.html',
		data
	)
Exemple #3
0
def signup(request):
    data = {}
    if request.method == 'POST':
        form = UsersForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/success')
    else:
        form = UsersForm()
    list_item = Users.objects.all()
    data['id'] = None
    data['list_item'] = list_item
    data['form'] = form
    return render(request, 'home/signup.html', data)
Exemple #4
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('/users')
    list_item = Users.objects.all()
    data['id'] = id
    data['list_item'] = list_item
    data['form'] = form
    return render(request, 'home/users.html', data)
Exemple #5
0
def signup(request):
	data = {}
	if request.method == 'POST':
		form = UsersForm(request.POST)
		if form.is_valid():
			form.save()
			return HttpResponseRedirect('/success')
	else:
		form = UsersForm()
	list_item = Users.objects.all()
	data['id'] = None
	data['list_item'] = list_item
	data['form'] = form
	return render(
		request,
		'home/signup.html',
		data
	)
Exemple #6
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('/users')
   list_item = Users.objects.all()
   data['id'] = id
   data['list_item'] = list_item
   data['form'] = form
   return render(
       request,
       'home/users.html',
       data
   )