Esempio n. 1
0
def user_login(request):
    """
    用户登录
    :param request:
    :return:
    """
    result = {}
    receive_data = trans_user_login(request)
    username = receive_data.get('username')
    password = receive_data.get('password')
    UOP = UserOperation()
    user_info = UOP.login_check_user(username, password)
    # user = auth.authenticate(username=username, password=password)
    if request.META.has_key('HTTP_X_FORWARDED_FOR'):
        ip = request.META['HTTP_X_FORWARDED_FOR']
    else:
        ip = request.META['REMOTE_ADDR']
    session_info = {}
    session_info['session_username'] = username
    session_info['session_ip'] = ip
    if user_info.get('flag'):
        verify = True
        # auth.login(request, user)
        SSP = SSOSessionOperation()
        SSP.add_session(session_info)
    else:
        verify = False
    result['result'] = verify
    return JsonResponse(result)
Esempio n. 2
0
def check_session_expire(request):
    """
    校验登录的session是否过期
    :param request:
    :return:
    """
    result = {}
    SSP = SSOSessionOperation()
    SSP.check_session_expire_time()
    return JsonResponse(result)
Esempio n. 3
0
 def inner(request, *args, **kwargs):
     if request.META.has_key('HTTP_X_FORWARDED_FOR'):
         ip = request.META['HTTP_X_FORWARDED_FOR']
     else:
         ip = request.META['REMOTE_ADDR']
     SSP = SSOSessionOperation()
     username = SSP.check_login_by_ip(ip)
     if username:
         res = func(request, *args, **kwargs)
         return res
     else:
         return HttpResponseRedirect('/back_login')
Esempio n. 4
0
 def check_login(ctx, token, ip):
     # token = 'MRLVNNUQAG'
     # ip = '127.0.0.1'
     username = ''
     SOP = ServerOperation()
     SSP = SSOSessionOperation()
     print token, ip
     check_result = SOP.check_login_by_token(token)
     if check_result.get('flag'):
         find_result = SSP.check_login_by_ip(ip)
         print find_result
         if find_result:
             username = find_result
     return username
Esempio n. 5
0
def user_logout(request):
    """
    用户注销
    :param request:
    :return:
    """
    result = {}
    auth.logout(request)
    if request.META.has_key('HTTP_X_FORWARDED_FOR'):
        ip = request.META['HTTP_X_FORWARDED_FOR']
    else:
        ip = request.META['REMOTE_ADDR']
    SSP = SSOSessionOperation()
    SSP.delete_session(ip)
    username = SSP.check_login_by_ip(ip)
    if username:
        result['logout'] = False
    else:
        result['logout'] = True
    return JsonResponse(result)
Esempio n. 6
0
def get_current_login_info(request):
    """
    获取当前登录用户信息
    :param request:
    :return:
    """
    result = {}
    if request.META.has_key('HTTP_X_FORWARDED_FOR'):
        ip = request.META['HTTP_X_FORWARDED_FOR']
    else:
        ip = request.META['REMOTE_ADDR']
    SSP = SSOSessionOperation()
    username = SSP.check_login_by_ip(ip)
    if username == '':
        result['code'] = 400
        result['message'] = '已注销'
        return JsonResponse(result)
    else:
        result['code'] = 200
        result['username'] = username
        result['message'] = '用户信息'
        return JsonResponse(result)