예제 #1
0
파일: views.py 프로젝트: Nilima10/codegrip
 def post(self, request):
     serilizer = LoginSerializer(data=request.data)
     if serilizer.is_valid():
         user = serilizer.validated_data['user']
         token, create = Token.objects.get_or_create(user=user)
         loginuser(request, user)
         return Response({'status':'1', 'Message':'You are login successfully', 'Token':token.key},status=200)
예제 #2
0
def login(request):
    if not request.user.is_anonymous():
        return HttpResponseRedirect('/userscontrols')
    if request.method == 'POST':
        loginform = AuthenticationForm(request.POST)
        if loginform.is_valid:
            usuario = request.POST['username']
            clave = request.POST['password']
            access = authenticate(username=usuario, password=clave)
            if access is not None:
                if access.is_active:
                    loginuser(request, access)
                    return HttpResponseRedirect('/userscontrols')
                else:
                    return render_to_response(
                        'userscontrols/noactive.html',
                        context_instance=RequestContext(request))
            else:
                return render_to_response(
                    'userscontrols/nouser.html',
                    context_instance=RequestContext(request))
    else:
        loginform = AuthenticationForm()
        ctx = {'loginform': loginform}
    return render_to_response('userscontrols/login.html',
                              ctx,
                              context_instance=RequestContext(request))
예제 #3
0
def landing(request):
    if request.user.is_authenticated:
        return redirect("../index")
    if request.method == "POST":
        uname = request.POST['u4_input']
        pw = request.POST['u5_input']
        user = authenticate(username=uname, password=pw)
        if user is not None:
            loginuser(request, user)
            return redirect("../index")
    return render(request, "home/landing_page.html")
예제 #4
0
def login(request):
    if request.method == 'GET':
        return render(request, 'login.html')
    elif request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = authenticate(username=username, password=password)

        if user:
            loginuser(request, user)
            return redirect('webapp.index')
        else:
            return render(request, 'login.html',
                          {'failed': True, 'username': username})
예제 #5
0
파일: views.py 프로젝트: Ayoub9581/django3
def login(request):

    if request.method == "POST":
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = authenticate(request, username=username, password=password)
        if user is not None:
            print('this is user', user)
            loginuser(request, user)
            return redirect('/tasks')
        else:
            messages.info(request, 'username or password are incorrect')
            return render(request, 'auth/login.html', {})

    return render(request, 'auth/login.html', {})
예제 #6
0
def login(request):
    form = CreateLoginForm()
    if request.method == 'POST':
        form = CreateLoginForm(request.POST)
        if form.is_valid():
            user = authenticate(request,
                                username=form.cleaned_data['username'],
                                password=form.cleaned_data['password'])
            if user is not None:
                loginuser(request, user)
                return redirect('home')
            else:
                messages.error(request, "Incorrect Username Or Password")

    context = {'form': form}
    return render(request, 'app/auth/login.html', context)
예제 #7
0
def login(request):
    if request.method == 'GET':
        form = AuthenticationForm()
        context = {'form': form}
        return render(request, 'login.html', context)
    else:
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
            username = form.cleaned_data.get("username")
            password = form.cleaned_data.get("password")
            user = authenticate(username=username, password=password)
            if user is not None:
                loginuser(request, user)
                return redirect("home")
        else:
            context = {'form': form}
            return render(request, 'login.html', context)
예제 #8
0
def login(request):
    if request.method == 'POST':
        print("hi")
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')
            user = authenticate(username=username, password=password)
            print("done",user)
            if user is not None:
                loginuser(request,user)
                return redirect('home')
        else:
            return render(request, 'login.html', {'form': form})
    else:
        form = AuthenticationForm()
        return render(request, 'login.html', {'form': form})
예제 #9
0
    def post(self , request):
        add = request.session.get('plusItem')
        form = CustomerAuthForm(data=request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')
            user = authenticate(username=username, password=password)
            if user:
                loginuser(request, user)

                session_cart = request.session.get('cart')
                if session_cart is None:
                    session_cart = []
                else:
                    for c in session_cart:
                        size = c.get('size')
                        tshirt_id = c.get('tshirt')
            
                        quantity = c.get('quantity')+1
                        cart_obj = Cart()
                        cart_obj.sizeVariant = SizeVariant.objects.get(
                            size=size, tshirt=tshirt_id)
                        cart_obj.quantity = quantity
                        cart_obj.user = user
                        cart_obj.save()

                # { size , tshirt , quantiti }
                cart = Cart.objects.filter(user=user)
                session_cart = []
                for c in cart:
                    obj = {
                        'size': c.sizeVariant.size,
                        'tshirt': c.sizeVariant.tshirt.id,
                        'quantity': c.quantity
                    }
                    session_cart.append(obj)

                request.session['cart'] = session_cart
                next_page = request.session.get('next_page')
                if next_page is None:
                    next_page = 'homepage'
                return redirect(next_page)
        else:
            return render(request,
                          template_name='login.html',
                          context={'form': form})
예제 #10
0
def login(request):
    if not request.user.is_anonymous():
        return HttpResponseRedirect('/userscontrols')
    if request.method == 'POST':
        loginform = AuthenticationForm(request.POST)
        if loginform.is_valid:
            usuario = request.POST['username']
            clave = request.POST['password']
            access = authenticate(username=usuario, password=clave)
            if access is not None:
                if access.is_active:
                    loginuser(request, access)
                    return HttpResponseRedirect('/userscontrols')
                else:
                    return render_to_response('userscontrols/noactive.html', context_instance=RequestContext(request))
            else:
                return render_to_response('userscontrols/nouser.html', context_instance=RequestContext(request))
    else:
        loginform = AuthenticationForm()
        ctx = {'loginform':loginform}
    return render_to_response('userscontrols/login.html', ctx, context_instance=RequestContext(request))
예제 #11
0
def login(request):
    if request.method == 'POST':
        uf = UserForm(request.POST)
        if uf.is_valid():

            username = uf.cleaned_data['username']
            password = uf.cleaned_data['password']
            #print username, password, "[*******]"

            user1 = authenticate(username=username, password=password)
            is_add = True if user1.has_perm('Work.shenpi') else False
            #print 'user1--->', user1, user1.has_perm('Work.shenpi'), is_add
            if user1:
                loginuser(request, user1)
                return render_to_response(
                    'base.html',
                    locals(),
                    context_instance=RequestContext(request))
            else:
                return HttpResponseRedirect('/login/')
    else:
        uf = UserForm()
    return render_to_response('login.html', {'uf': uf})