コード例 #1
0
def dglogout(request):
    if request.method == 'GET':
        auth.logout(request)
        response = HttpResponse('退出成功')
        response.delete_cookie('username')
        return response
    return HttpResponseRedirect('../templates/login/')
コード例 #2
0
    def post(self, request):
        '''登录校验'''
        #接收数据
        username = request.POST.get('username')
        password = request.POST.get('pwd')
        #校验数据
        if not all([username, password]):
            return render(request, 'login.html', {'errmsg': '数据不完整'})
        #业务处理:登录校验
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                #用户已激活时需要获取用户的登录状态
                login(request, user)
                print('用户已激活!')
                #判断是否需要记住用户名
                remember = request.POST.get('remember')
                #跳转到首页
                response = redirect(reverse('goods:index'))
                if remember == 'on':
                    #记住用户名
                    response.set_cookie('username',
                                        username,
                                        max_age=7 * 24 * 3600)
                else:
                    response.delete_cookie('username')
                #返回response
                return response

            else:
                return render(request, 'login.html', {'errmsg': '账户未激活'})
        else:
            #用户名密码错误
            return render(request, 'login.html', {'errmsg': '用户名或密码错误'})
コード例 #3
0
ファイル: views.py プロジェクト: huahua-github/dailyfresh
    def post(self,request):
        username = request.POST.get("username")
        password = request.POST.get("password")
        merusername = request.POST.get("merusername")

        # user = User.objects.get(username=username,password=password)
        user = authenticate(username=username,password=password)  # django认证机制内置
        print(user.username)
        if user!=None:
            if user.is_active:
                print("+++++++++++++++++++")
                login(request,user)
                print("+++++++++++++++++++")
                if merusername=="true":

                    response = JsonResponse({"message": "OK", "username": username})
                    response.set_cookie("username",username)
                else:

                    response = JsonResponse({"message": "OK", "username": username,})

                    response.delete_cookie("username")


                    print("==================")
                return response
            else:
                return JsonResponse({"message":"账号尚未激活不能登陆"})

        else:
            return JsonResponse({"message":"用户名或密码错误"})
コード例 #4
0
ファイル: views.py プロジェクト: savadom13/web
def logout(request):
    sessionid = request.COOKIES.get('sessionid')
    if sessionid is not None:
        do_logout(sessionid)
    response = redirect('/')
    response.delete_cookie('sessionid')
    return response
コード例 #5
0
ファイル: views.py プロジェクト: jin419111582/blog
 def get(self, request):
     # 1.session数据清除
     logout(request)
     # 2.删除部分cookie数据
     response = redirect(reverse('home:index'))
     response.delete_cookie('is_login')
     # 3.跳转到首页
     return response
コード例 #6
0
    def get(self, request):
        """实现退出登录逻辑"""
        # 清理session
        logout(request)
        # 退出登录,重定向到登录页
        response = redirect(reverse('contents:index'))
        # 退出登录时清除cookie中的username
        response.delete_cookie('username')

        return response
コード例 #7
0
def reset_user_authenticate(request, *args, **kwargs):

    key_list = list(kwargs.keys())
    try:
        if (('file_path' in key_list) and ('data' in key_list)):
            response = render(request, kwargs['file_path'], kwargs['data'])
            response.delete_cookie('user_name')
            response.delete_cookie('ucrypt')
        else:
            raise Exception('Check arguments passed !')
    except Exception as ex:
        print(f"RESET ADMIN EX : {ex}")
    else:
        return response
コード例 #8
0
def logout(request):

    if request.method == "POST":

        response = render(request, "login/login.html")
        response.delete_cookie('user')
        response.delete_cookie('username')
        response.delete_cookie('gender')
        response.delete_cookie('id_user')
        # print(user.password, user.id)
        return response
コード例 #9
0
    def post(self, request):

        old_password = request.POST.get('old_pwd')
        new_password = request.POST.get('new_pwd')
        newcp_password = request.POST.get('new_cpwd')

        user = request.user

        if not user.check_password(old_password):
            return render(request, 'user_center_pass.html')
        user.set_password(new_password)
        user.save()

        response = redirect(reverse('users:login'))

        logout(request, user)

        response.delete_cookie('username')

        return response
コード例 #10
0
ファイル: views.py プロジェクト: zhengdaoshen/mimizhang
    def post(self, request):
        user_name = request.POST.get('username')
        user_pwd = request.POST.get('pwd')

        user = authenticate(username=user_name, password=user_pwd)
        print(user)
        if user is not None:
            # the password verified for the user
            if user.is_active:
                print("用户是有效的、主动的和经过身份验证的")
                # 记住用户名的登录状态
                login(request, user)

                url_next = request.GET.get('next')

                if url_next:
                    response = redirect(url_next)
                else:
                    response = redirect(reverse('user:index'))

                # 判断是否记住用户名
                remermber = request.POST.get('remember')

                if remermber == 'on':
                    # 记住用户名
                    response.set_cookie('username',
                                        user_name,
                                        max_age=7 * 24 * 3600)
                else:
                    response.delete_cookie('username')
            else:
                print("密码是有效的,但是帐号已经被禁用了!")

            return response
        else:
            # the authentication system was unable to verify the username and password
            print("用户名和密码不正确。")

            return render(request, 'login.html', {'errmsg': '账户未激活'})
コード例 #11
0
ファイル: views.py プロジェクト: linyouwei/pycharm
def logout(request):
    response = HttpResponseRedirect('/index/')
    response.delete_cookie('cookie_username')
    return response
コード例 #12
0
def quit(request):
    logout(request)
    response = redirect('/mine/')
    response.delete_cookie('token')
    return response
コード例 #13
0
ファイル: views.py プロジェクト: Easonchar/leshangwang
def logout(request):
    response = redirect('leshangwang:index')
    response.delete_cookie('username')
    return response
コード例 #14
0
ファイル: views.py プロジェクト: lzl131070/mbaobao
def logout(request):
    response = redirect('mbb:index')
    response.delete_cookie('token')
    return response