登陆接口
        :param user: 用户名
        :param password: 密码
        :param kwargs: 其他参数
        :return:
510156
def login(self, user=None, password=None, **kwargs):
        
        headers = self._generate_headers()
        self.s.headers.update(headers)

        # init cookie
        self.s.get(self.LOGIN_PAGE)

        # post for login
        params = self.create_login_params(user, password, **kwargs)
        rep = self.s.post(self.LOGIN_API, data=params)

        self.check_login_success(rep)
        log.info("登录成功")
84314
def authenticate_user(self, request, user):
        
        return user.check_password(request.data.get('password')) or \
               self.check_user_token(request, user)
1166751
def setCredentials(self, user, password):
        
        self._checkUserAndPass(user, password)
        self.user = user
        self.password = password
308684
def __pop_driver_auth_args(**kwargs):
        
        if 'username' in kwargs:
            return [kwargs.pop('username'), kwargs.pop('password')]
        elif 'access_token' in kwargs:
            return kwargs.pop('access token')
        elif 'access_id' in kwargs:
            return kwargs.pop('access_id'), kwargs.pop('secret_key')
        elif 'service_account_email' in kwargs:
            return [kwargs.pop('service_account_email'), kwargs.pop('pem_file')]
        elif 'client_id' in kwargs:
            return [kwargs.pop('client_id'), kwargs.pop('client_secret')]
        return None
574190
def update_user_password(new_pwd_user_id, new_password,**kwargs):
    
    #check_perm(kwargs.get('user_id'), 'edit_user')
    try:
        user_i = db.DBSession.query(User).filter(User.id==new_pwd_user_id).one()
        user_i.password = bcrypt.hashpw(str(new_password).encode('utf-8'), bcrypt.gensalt())
        return user_i
    except NoResultFound:
        raise ResourceNotFoundError("User (id=%s) not found"%(new_pwd_user_id))
971815
def admin_authenticate(self, password):
        
        auth_params = {
                'USERNAME': self.username,
                'PASSWORD': password
            }
        self._add_secret_hash(auth_params, 'SECRET_HASH')
        tokens = self.client.admin_initiate_auth(
            UserPoolId=self.user_pool_id,
            ClientId=self.client_id,
            # AuthFlow='USER_SRP_AUTH'|'REFRESH_TOKEN_AUTH'|'REFRESH_TOKEN'|'CUSTOM_AUTH'|'ADMIN_NO_SRP_AUTH',
            AuthFlow='ADMIN_NO_SRP_AUTH',
            AuthParameters=auth_params,
        )

        self.verify_token(tokens['AuthenticationResult']['IdToken'], 'id_token','id')
        self.refresh_token = tokens['AuthenticationResult']['RefreshToken']
        self.verify_token(tokens['AuthenticationResult']['AccessToken'], 'access_token','access')
        self.token_type = tokens['AuthenticationResult']['TokenType']
1328014
def get_users(self, **kwargs):
        
        return GetUsers(settings=self.settings, **kwargs).call(**kwargs)
384170
def auth(username, password):
    '''
    
    '''

    url = rest_auth_setup()

    data = {'username': username, 'password': password}

    # Post to the API endpoint. If 200 is returned then the result will be the ACLs
    # for this user
    result = salt.utils.http.query(url, method='POST', data=data, status=True,
                                   decode=True)
    if result['status'] == 200:
        log.debug('eauth REST call returned 200: %s', result)
        if result['dict'] is not None:
            return result['dict']
        return True
    else:
        log.debug('eauth REST call failed: %s', result)
        return False
209368
def require_user(self, *users, user=None):
        """"""

        # accept old-style single user keyword-argument as well
        if user:
            users = (*users, user)

        def _require_auth(view_func):
            @wraps(view_func)
            def wrapper(*args, **kwargs):
                """ Effective wrapper """
                username, out_token = self.authenticate()
                if username and out_token:
                    b64_token = base64.b64encode(out_token).decode('utf-8')
                    auth_data = 'Negotiate {0}'.format(b64_token)
                    if not users or username in users:
                        response = make_response(view_func(*args,
                                                           username=username,
                                                           **kwargs))
                    else:
                        response = Response(status=403)
                    response.headers['WWW-Authenticate'] = auth_data
                    return response
                return Response(
                    status=401,
                    headers={'WWW-Authenticate': 'Negotiate'},
                )

            return wrapper
        return _require_auth
815436
def get_user(self, username=None, params=None):
        
        return self.transport.perform_request(
            "GET", _make_path("_security", "user", username), params=params
        )
1035217
def get_or_create_user(self, provider, access, info):
        ""
        digest = hashlib.sha1(smart_bytes(access)).digest()
        # Base 64 encode to get below 30 characters
        # Removed padding characters
        username = force_text(base64.urlsafe_b64encode(digest)).replace('=', '')
        User = get_user_model()
        kwargs = {
            User.USERNAME_FIELD: username,
            'email': '',
            'password': None
        }
        return User.objects.create_user(**kwargs)
990722
def delete_user(self, user_id, **kwargs):
        
        return DeleteUser(settings=self.settings, **kwargs).call(user_id=user_id, **kwargs)
513804
def get_user(uid, **kwargs):
    
    user_id=kwargs.get('user_id')
    if uid is None:
        uid = user_id
    user_i = _get_user(uid)
    return user_i
1210749
def get_user_by_password(self, username, password):
        
        try:
            user = self.get(username=username)
        except User.DoesNotExist:
            return None
        
        if bcrypt.hashpw(password, user.pass_hash) == user.pass_hash:
            return user
        else:
            return None
806170
def login(self, password):
        

        method, url = get_URL('login')
        payload = {
            'apikey': self.config.get('apikey'),
            'username': self.username,
            'password': password,
            'source': 'Desktop'
            }

        res = getattr(self.session, method)(url, params=payload)

        if res.status_code == 200:
            return True

        hellraiser(res)
1092274
def auth(self, username, password):
        
        headers = {
            'Content-type': 'application/json'
        }
        payload = {
            'type': self.auth_type,
            'username': username,
            'password': password
        }
        try:
            full_url = utils.urljoin(self.host, '/api/v1/auth')
            response = requests.post(
                full_url,
                data=json.dumps(payload),
                headers=headers,
                verify=self.tls_verify
            )
        except RequestException:
            raise exceptions.TaigaRestException(
                full_url, 400,
                'NETWORK ERROR', 'POST'
            )
        if response.status_code != 200:
            raise exceptions.TaigaRestException(
                full_url,
                response.status_code,
                response.text,
                'POST'
            )
        self.token = response.json()['auth_token']
        self.raw_request = RequestMaker('/api/v1', self.host, self.token,
                                        'Bearer', self.tls_verify)
        self._init_resources()
195364
def _verify_authentication(self, handler, args, kwargs):
        
        if not self.user_manager.session_logged_in():
            raise APIForbidden()
        return handler(*args, **kwargs)