Example #1
0
    def server_auth(self, *args, **kwargs):
        '''
        认证函数
        :param args:
        :param kwargs:
        :return:
        '''
        # print('from server_auth')
        data = args[0]

        if data.get('username') is None or data.get('passwd') is None:
            send_response(self.request, 252)

        user = authenticate(data.get('username'), data.get('passwd'),
                            self.request)
        if user is None:
            send_response(self.request, 253)
        else:
            print('通过验证!', user)

            #Windows下
            # self.home_dir = '%s\\%s'%(settings.HOME_DIR, data.get('username'))

            self.home_dir = '%s/%s' % (settings.HOME_DIR, data.get('username'))
            self.current_dir = self.home_dir
            self.username = user
            send_response(self.request, 254)
Example #2
0
    def post(self):
        next_url = self.request.arguments.get('next', [None])[0]
        username = self.request.arguments.get('username', [None])[0]
        password = self.request.arguments.get('password', [None])[0]

        if self.current_user:
            return self.redirect(next_url or '/')

        if not username or not password:
            return self.render("login.html", page_title="Login", next_url=next_url,
                errors="Please enter both a username and a password.")
        if not authenticate(username, password):
            return self.render("login.html", page_title="Login", next_url=next_url,
                errors="Invalid username or password specified.")

        self.set_secure_cookie("user", username)
        return self.redirect(next_url or "/")
Example #3
0
    def interaction(self):
        '''
        交互函数
        :return:
        '''

        self.user = authenticate(self.sock)
        if self.user:
            print("---Begin to interact with u...")
            self.terminal_display = "[%s]$: " % self.user
            while True:
                choice = input(self.terminal_display).strip()
                if len(choice) == 0: continue
                cmd_list = choice.split()
                if hasattr(self, 'client_%s' % cmd_list[0]):
                    func = getattr(self, 'client_%s' % cmd_list[0])
                    func(cmd_list)
                else:
                    print('输入有误,请重新输入或输入"help"查看帮助')
Example #4
0
    def post(self):
        next_url = self.request.arguments.get('next', [None])[0]
        username = self.request.arguments.get('username', [None])[0]
        password = self.request.arguments.get('password', [None])[0]

        if self.current_user:
            return self.redirect(next_url or '/')

        if not username or not password:
            return self.render(
                "login.html",
                page_title="Login",
                next_url=next_url,
                errors="Please enter both a username and a password.")
        if not authenticate(username, password):
            return self.render(
                "login.html",
                page_title="Login",
                next_url=next_url,
                errors="Invalid username or password specified.")

        self.set_secure_cookie("user", username)
        return self.redirect(next_url or "/")
Example #5
0
 def test_authenticate(self):
     with mock.patch.object(logging, "exception"):
         T.assert_equal(auth.authenticate("fake_user", "fake_password"),
                        False)
Example #6
0
 def test_authenticate(self):
     with mock.patch.object(logging, "exception"):
         T.assert_equal(auth.authenticate("fake_user", "fake_password"), False)