Exemplo n.º 1
0
    def process_request(self, request):
        """

        :param request:
        :return:
        """
        # 方式一
        # request.context = {}
        # if 'session_user' in request.session.keys():
        #     session_user = request.context['session_user'] = request.session
        #     print(request.session['session_user']['account'])
        # if not session_user:
        #     if request.path.startswith('/video') or request.path.startswith('/user'):
        #         if request.path not in [reverse('user_login'), reverse('user_register')]:
        #             request.context['login_message'] = '请先登录'
        #             return course_views.index_handler(request)

        # 方式二
        request.context = dict(
            session_user=request.session['session_user'] if 'session_user' in
            request.session.keys() else None)
        if (not request.context['session_user']) \
                and (request.path.startswith('/video') or request.path.startswith('/user')) \
                and request.path not in [reverse('user_login'), reverse('user_register')]:
            request.context['login_message'] = '请先登录'
            return course_views.index_handler(request)
Exemplo n.º 2
0
def register_handler(request):
    """
    注册界面
    :param request:
    :return:课程首页
    """
    context = request.context
    if request.method != 'POST':
        return HttpResponse(status=403)
    account = request.POST.get('account')
    password = request.POST.get('password')
    try:
        user_exists = User.objects.filter(account=account).exists()
        if not user_exists:
            user = User(account=account, password=password)
            user.save()
            request.session['session_user'] = {
                'id': user.id,
                'account': user.account
            }
        else:
            context['register_message'] = '账号已存在'
    except:
        context['register_message'] = '服务器异常'
    finally:
        return course_views.index_handler(request)
Exemplo n.º 3
0
    def process_request(self, request):
        # request.context = {}
        # if 'session_user' in request.session.keys():
        #     request.context['session_user'] = request.session['session_user']
        request.context = dict(
            session_user=request.session['session_user'] if 'session_user' in
            request.session.keys() else None)

        if (not request.context['session_user'])\
                and (request.path.startwith('/video') or request.path.startwith('/user'))\
                and request.path not in [reverse('user_login'),reverse('user_register')]:
            request.context['login_message'] = '请先登录'
            return course_views.index_handler(request)
Exemplo n.º 4
0
 def process_request(self, request):
     request.context = {}
     session_user = None
     # if 'session_user' in request.session.keys():
     #     session_user = request.context['session_user'] = request.session['session_user']
     # if not session_user:
     #     if request.path.startswith('/video') or request.path.startswith('/user'):
     #         if request.path not in [reverse('user_login'),reverse('user_register')]: # 这里是把注册和登录接口让出来
     #             request.context['login_message'] = '请先登录'
     #             return course_views.index_handler(request)
     request.context = dict(
         session_user=request.session['session_user'] if 'session_user' in
         request.session.keys() else None)
     if (not request.context['session_user']) and \
             (request.path.startswith('/video') or request.path.startswith('/user')) and \
             request.path not in [reverse('user_login'), reverse('user_register')]:
         request.context['login_message'] = '请先登录'
         return course_views.index_handler(request)
Exemplo n.º 5
0
def login_handler(request):
    # 登录视图
    if request.method != 'POST':
        return HttpResponse(status=403)
    context = request.context
    account = request.POST.get('account')
    password = request.POST.get('password')
    user_s = User.objects.filter(account=account, password=password)
    if user_s:
        user = user_s[0]
        request.session['session_user'] = {
            'id': user.id,
            'account': user.account
        }
        return redirect(reverse('course_index'))
    else:
        context['login_message'] = '账号或密码错误'
    return course_views.index_handler(request)