def loginHandler(request):
    usern=request.POST['name']
    pwd=request.POST['password']
    user= authenticate(username=usern, password=pwd)
    if user is not None:
        lgn(request,user)
        return redirect('/loginpage/')
    else:
        return render(request, 'home/login.html',{})
Esempio n. 2
0
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:
            lgn(request, user)
            return redirect('home')
        else:
            messages.info(request, 'Something get wrong')
    return render(request, 'login.html')
Esempio n. 3
0
def Login (request):
    args = {"type":1}
    if request.method == 'GET' and request.user.is_authenticated == False:
        return render(request, 'Home/login.html', args)
    elif request.method == 'GET' and request.user.is_authenticated:
        return redirect('/dashboard')
    elif request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        i = authenticate(request, username=username, password=password)
        if i:
            lgn(request, i)
            return redirect('/dashboard')
        return render(request, 'Home/login.html', args)
Esempio n. 4
0
def login_process(request):
    login = request.POST['login']
    password = request.POST['password']
    user = authenticate(request, username=login, password=password)
    if user is not None:
        lgn(request, user)
        h = HistoryNote(user=user,
                        date=timezone.now(),
                        text="Пользователь вошел в систему")
        h.save()
        if not hasattr(user, 'user_info'):
            u_info = User_info(user=user, money=10000)
            u_info.save()
        return redirect('index')
    else:
        return make_message(
            request, 'Неправильный логин или пароль')  #HttpResponse("FAIL")
Esempio n. 5
0
def login(request):
	if request.method=="POST":
		username=request.POST['username']
		password=request.POST['password']
		
		user=authenticate(username=username, password=password)
		if user:
			lgn(request,user)
			if request.user.is_superuser:
				return HttpResponseRedirect(reverse('home'))
			else:
				return HttpResponseRedirect(reverse('student'))
		else:
			context={'error':'invalid user'}
			return render(request,'hostel/login.html', context)
	else:
		return render(request,'hostel/login.html')
Esempio n. 6
0
def login(request):
    from accounts.forms import LoginForm
    form = LoginForm()
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            user = EmailAuthBackend.authenticate(
                email=form.cleaned_data['email'],
                password=form.cleaned_data['password'])
            if user is None:
                return render(request, 'registration/login_err.html')
            else:
                lgn(request,
                    user,
                    backend='django.contrib.auth.backends.ModelBackend')
                return HttpResponseRedirect('/prepare/')
        else:
            return HttpResponseRedirect('/account/login/')
    return render(request, 'registration/login.html', {"form": form})
Esempio n. 7
0
def login(request):
    if request.method == "GET":

        lf = LoginForm()
        rm = RegisterForm()
        return render(request, "polls/login.html", {"lf": lf, "rm": rm})
    elif request.method == "POST":
        #3.使用django自带的User
        # username = request.POST.get("username")
        # password = request.POST.get("password")
        # 利用django自带表单类创建表单,获取表单数据
        verifycode = request.POST.get("verify")
        if not verifycode == cache.get("verify"):
            return HttpResponse("验证码错误")

        lf = LoginForm(request.POST)
        if lf.is_valid():
            username = lf.cleaned_data.get("username")
            password = lf.cleaned_data.get("password")
            user = PollsUser.objects.filter(username=username).first()
            print(user)
            if user.check_password(password):
                # user=authenticate(request,username=username,password=password)
                if user:
                    if user.is_active:
                        lgn(request, user)
                        return redirect(reverse("polls:index"))
                    else:
                        return render(request, "polls/login.html",
                                      {"errors": "用户为激活"})
                else:
                    lf = LoginForm()
                    rm = RegisterForm()
                    return render(request, "polls/login.html", {
                        "errors": "登录失败",
                        "lf": lf,
                        "rm": rm
                    })
Esempio n. 8
0
def Login_View(request):
    try:
        key = request.session['member-id']
        return redirect('/home/')
    except:
        if request.method == "POST":
            form = Login_Form(request.POST)
            username = request.POST['username']
            password = request.POST['password']
            user = auth(username=username, password=password)
            if user is not None:
                lgn(request, user)
                request.session['member-id'] = user.id
                return redirect('/home/')
            else:
                return render(request, "Login/login.html", {
                    'form': form,
                    'error': 'True'
                })

        else:
            form = Login_Form()
            return render(request, "Login/login.html", {'form': form})
def login(request):
    # getting the list of all the attributes like username email etc
    registration_details=list(Registration.objects.all())
    username_list=[]
    email_list=[]
    # this dictionary will store the username with password
    login_dict={}
    social_username=[]
    social_email=[]
    l=list(User.objects.all())
    for i in l:
        social_username.append(i.username)
        social_email.append(i.email)
    for i in registration_details:
        username_list.append(i.username)
        email_list.append(i.email)
        login_dict[i.username]=i.password
    # this variable will store the nect attribute during the authentication part
    nt=""
    # getting the next value if its there
    if request.GET:
        nt=request.GET.get("next")
    # accessing the posted value from the frontend side
    if request.method=="POST":
        name=request.POST.get("name","default")
        email=request.POST.get("email","default")
        username=request.POST.get("username","default")
        password=request.POST.get("password","default")
        username_lgn=request.POST.get("username_lgn","default")
        password_lgn=request.POST.get("password_lgn","default")
        print(username)
        print(password)
        # registration part of the authentication
        if name!="default":
            if username in username_list:
                return render(request,"index.html",{'message':"Username Already Exist"})
            elif username in social_username:
                return render(request, "index.html", {'message': "Username Already Exist"})
            elif email in social_email:
                return render(request, "index.html", {"message": "Email Already registered"})
            elif email in email_list:
                return render(request,"index.hmtl",{"message":"Email Already registered"})
            else:
                Registration(name=name,email=email,username=username,password=password).save()
                u=User.objects.create_user(username,email,password)
                u.first_name=name
                u.save()
        # login part of the authentication
        if username_lgn!="default":
            try:
                if username_lgn in username_list:
                    if password_lgn==login_dict[username_lgn]:
                        # matching the credential and after that authenticating everything
                        user=authenticate(request,username=username_lgn,password=password_lgn)
                        # login with the help of login function
                        lgn(request,user)
                        # if theres a next then redirecting to the next value
                        if nt=="":
                            return HttpResponseRedirect("/")
                        else:
                            return HttpResponseRedirect(nt)
                    else:
                        return render(request,"index.html",{"message":"Password is incorrect"})
                else:
                    return render(request,"index.html",{"message":"Username doesnot Exist"})
            except:
                return HttpResponse("I think the username and email id you are using is already registered and using it twice")
    return render(request,"index.html",{"message":""})