Exemple #1
0
    def check_auth(self, all_credentials):
        """Update this socket's authentication.

        Log in or out to bring this socket's credentials up to date with
        those provided. Can raise ConnectionFailure or OperationFailure.

        :Parameters:
          - `all_credentials`: dict, maps auth source to MongoCredential.
        """
        if all_credentials or self.authset:
            cached = set(itervalues(all_credentials))
            authset = self.authset.copy()

            # Logout any credentials that no longer exist in the cache.
            for credentials in authset - cached:
                auth.logout(credentials.source, self)
                self.authset.discard(credentials)

            for credentials in cached - authset:
                auth.authenticate(credentials, self)
                self.authset.add(credentials)

        # CMAP spec says to publish the ready event only after authenticating
        # the connection.
        if not self.ready:
            self.ready = True
            if self.enabled_for_cmap:
                self.listeners.publish_connection_ready(self.address, self.id)
Exemple #2
0
    def authenticate(self, credentials):
        """Log in to the server and store these credentials in `authset`.

        Can raise ConnectionFailure or OperationFailure.

        :Parameters:
          - `credentials`: A MongoCredential.
        """
        auth.authenticate(credentials, self)
        self.authset.add(credentials)
Exemple #3
0
    def authenticate(self, credentials):
        """Log in to the server and store these credentials in `authset`.

        Can raise ConnectionFailure or OperationFailure.

        :Parameters:
          - `credentials`: A MongoCredential.
        """
        auth.authenticate(credentials, self)
        self.authset.add(credentials)
Exemple #4
0
    def post(self, request):
        #实例化
        login_form = LoginForm(request.POST)
        if login_form.is_valid():
            user_name = request.POST.get('username', '')
            pass_word = request.POST.get('password', '')
            print('user_name', user_name)
            print('pass_word', pass_word)

            user = authenticate(username=user_name, password=pass_word)
            print(user)
            if user is not None:
                if user.is_active:
                    print('邮箱已激活,并且登录成功')
                    login(request, user)
                    return render(request, 'index.html', {'name': user_name})
                else:
                    print('邮箱未激活,登录失败')
                    return render(request, 'login.html', {
                        'msg': '邮箱未激活,登录失败',
                        'login_form': login_form
                    })
            else:
                print('登录失败')
                return render(request, 'login.html', {
                    'msg': '用户名或者密码错误',
                    'login_form': login_form
                })
        else:
            return render(request, 'login.html', {'login_form': login_form})
    def __check_auth(self, sock_info):
        """Authenticate using cached database credentials.
        """
        if self.__auth_credentials or sock_info.authset:
            cached = set(self.__auth_credentials.itervalues())

            authset = sock_info.authset.copy()

            # Logout any credentials that no longer exist in the cache.
            for credentials in authset - cached:
                self.__simple_command(sock_info, credentials[0], {"logout": 1})
                sock_info.authset.discard(credentials)

            for credentials in cached - authset:
                auth.authenticate(credentials, sock_info, self.__simple_command)
                sock_info.authset.add(credentials)
Exemple #6
0
    def __check_auth(self, sock_info):
        """Authenticate using cached database credentials.
        """
        if self.__auth_credentials or sock_info.authset:
            cached = set(self.__auth_credentials.itervalues())

            authset = sock_info.authset.copy()

            # Logout any credentials that no longer exist in the cache.
            for credentials in authset - cached:
                self.__simple_command(sock_info, credentials[0], {'logout': 1})
                sock_info.authset.discard(credentials)

            for credentials in cached - authset:
                auth.authenticate(credentials, sock_info,
                                  self.__simple_command)
                sock_info.authset.add(credentials)
    def _cache_credentials(self, source, credentials):
        """Add credentials to the database authentication cache
        for automatic login when a socket is created.
        """
        if source in self.__auth_credentials:
            # Nothing to do if we already have these credentials.
            if credentials == self.__auth_credentials[source]:
                return
            raise OperationFailure('Another user is already authenticated '
                                   'to this database. You must logout first.')

        sock_info = self.__socket()
        # Logout any previous user for this source database
        self.__check_auth(sock_info)
        auth.authenticate(credentials, sock_info, self.__simple_command)
        sock_info.authset.add(credentials)
        self.__pool.maybe_return_socket(sock_info)

        self.__auth_credentials[source] = credentials
Exemple #8
0
    def check_auth(self, all_credentials):
        """Update this socket's authentication.

        Log in or out to bring this socket's credentials up to date with
        those provided. Can raise ConnectionFailure or OperationFailure.

        :Parameters:
          - `all_credentials`: dict, maps auth source to MongoCredential.
        """
        if all_credentials or self.authset:
            cached = set(itervalues(all_credentials))
            authset = self.authset.copy()

            # Logout any credentials that no longer exist in the cache.
            for credentials in authset - cached:
                auth.logout(credentials.source, self)
                self.authset.discard(credentials)

            for credentials in cached - authset:
                auth.authenticate(credentials, self)
                self.authset.add(credentials)
Exemple #9
0
    def check_auth(self, all_credentials):
        """Update this socket's authentication.

        Log in or out to bring this socket's credentials up to date with
        those provided. Can raise ConnectionFailure or OperationFailure.

        :Parameters:
          - `all_credentials`: dict, maps auth source to MongoCredential.
        """
        if all_credentials or self.authset:
            cached = set(itervalues(all_credentials))
            authset = self.authset.copy()

            # Logout any credentials that no longer exist in the cache.
            for credentials in authset - cached:
                auth.logout(credentials.source, self)
                self.authset.discard(credentials)

            for credentials in cached - authset:
                auth.authenticate(credentials, self)
                self.authset.add(credentials)
Exemple #10
0
    def _cache_credentials(self, source, credentials):
        """Add credentials to the database authentication cache
        for automatic login when a socket is created.
        """
        if source in self.__auth_credentials:
            # Nothing to do if we already have these credentials.
            if credentials == self.__auth_credentials[source]:
                return
            raise OperationFailure('Another user is already authenticated '
                                   'to this database. You must logout first.')

        sock_info = self.__socket()
        try:
            # Since __check_auth was called in __socket
            # there is no need to call it here.
            auth.authenticate(credentials, sock_info, self.__simple_command)
            sock_info.authset.add(credentials)
        finally:
            self.__pool.maybe_return_socket(sock_info)

        self.__auth_credentials[source] = credentials
    def _cache_credentials(self, source, credentials):
        """Add credentials to the database authentication cache
        for automatic login when a socket is created.
        """
        if source in self.__auth_credentials:
            # Nothing to do if we already have these credentials.
            if credentials == self.__auth_credentials[source]:
                return
            raise OperationFailure('Another user is already authenticated '
                                   'to this database. You must logout first.')

        sock_info = self.__socket()
        try:
            # Since __check_auth was called in __socket
            # there is no need to call it here.
            auth.authenticate(credentials, sock_info, self.__simple_command)
            sock_info.authset.add(credentials)
        finally:
            self.__pool.maybe_return_socket(sock_info)

        self.__auth_credentials[source] = credentials
Exemple #12
0
def signup(request):
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            print(username)
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('ticket:index')
    else:
        form = UserCreationForm()
    return render(request, 'ticketbooking/register.html', {'form': form})