Checks if the username matches the request user, and if so replaces
    username with the actual user object.
    Returns 404 if the username does not exist, and 403 if it doesn't match.
329337
def username_matches_request_user(view_fn):
    
    @wraps(view_fn)
    def wrapper(request, username, *args, **kwargs):
        User = get_user_model()

        user = get_object_or_404(User, username=username)
        if user != request.user:
            return HttpResponseForbidden()
        else:
            return view_fn(request, user, *args, **kwargs)

    return wrapper
723673
def create_user(self, username, first_name=None, last_name=None):
		
		
		url = api_url+'users/'
		payload = {
			'username':username
		}
		if first_name:
			payload['first_name'] = first_name
		if last_name:
			payload['last_name'] = last_name
		r = requests.post(url, data=json.dumps(payload), headers=self.headers)
		print(request_status(r))
		r.raise_for_status()
		return User(r.json())
250592
def modify_url_for_impersonation(cls, url, impersonate_user, username):
        
        if impersonate_user is not None and username is not None:
            url.username = username
721623
def get_by_username(cls, username):
        
        return cls.query().filter(cls.username == username).first()
465587
def get(self, username):
        
        if not self.remember:
            raise NotSaving

        if username not in self.token_storage:
            raise UserNotFound

        if self.token_storage[username]['expiration'] < time.time():
            new_token = self.refresh(self.token_storage[username]['refresh'])
            self.token_storage[username]['token'] = new_token[0]
            self.token_storage[username]['expiration'] = new_token[1]
            return new_token[0]
        else:
            return self.token_storage[username]['token']
957388
function(name) {
                console.log('oauthInterface.user.username');

                var params = corbel.utils.extend(this.params, {});
                params.url = this._buildUri('username/' + name);
                params.method = corbel.request.method.GET;

                return this.request(params);
            }
624666
def check_request(request, login_unsuccessful,
                  get_username=get_username_from_request,
                  username=None):
    
    ip_address = get_ip(request)
    username = username or get_username(request)

    if not login_unsuccessful:
        # user logged in -- forget the failed attempts
        reset_failed_attempts(ip_address=ip_address, username=username)
        return True
    else:
        # add a failed attempt for this user
        return record_failed_attempt(ip_address, username)
42343
def userhref(uri, username)
      response = rest_get(uri)
      items = response_handler(response)['Items']
      items.each do |it|
        return it['links']['self']['href'] if it['UserName'] == username
      end
    end
338395
private static String checkUsername(String username) {
        if (username.length() < 3) {
            return "too short (minimum: 3 characters)";
        } else if (username.length() > 64) {
            return "too long (maximum: 64 characters)";
        }

        for (int i = 0; i < username.length(); i++) {
            char c = username.charAt(i);
            if (c >= 'A' && c <= 'Z') continue;
            if (c >= 'a' && c <= 'z') continue;
            if (c >= '0' && c <= '9') continue;
            if (c == '_') continue;
            return "invalid character at position " + (i+1) + ": " + jq(""+c);
        }

        return null;
    }
490802
def delete_user(self, username):
        
        path = Client.urls['users_by_name'] % username
        return self._call(path, 'DELETE')
152949
def get_by_username(cls, username):
        
        return cls.query.filter(
            UserProfile._username == username.lower()
        ).one()
625675
def get_user_by_username(self, username):
        
        results = self.get_users(filter='username eq "%s"' % (username))
        if results['totalResults'] == 0:
            logging.warning("Found no matches for given username.")
            return
        elif results['totalResults'] > 1:
            logging.warning("Found %s matches for username %s" %
                (results['totalResults'], username))

        return results['resources'][0]
244018
def User(self, Username=''):
        
        if not Username:
            Username = self.CurrentUserHandle
        o = User(self, Username)
        o.OnlineStatus # Test if such a user exists.
        return o
1048207
def get_user(self, username="", ext_collections=False, ext_galleries=False):

        

        if not username and self.standard_grant_type == "authorization_code":
            response = self._req('/user/whoami')
            u = User()
            u.from_dict(response)
        else:
            if not username:
                raise DeviantartError("No username defined.")
            else:
                response = self._req('/user/profile/{}'.format(username), {
                    'ext_collections' : ext_collections,
                    'ext_galleries' : ext_galleries
                })
                u = User()
                u.from_dict(response['user'])

        return u
1348057
def _get_user(self, username):
        """"""
        data = self.client.get(self._key(username))
        if data is None:
            return None
        return json.loads(data.decode())
795714
def validate_username_for_new_person(username):
    

    # is the username valid?

    validate_username(username)

    # Check for existing people

    count = Person.objects.filter(username__exact=username).count()
    if count >= 1:
        raise UsernameTaken(six.u(
            'The username is already taken. Please choose another. '
            'If this was the name of your old account please email %s')
            % settings.ACCOUNTS_EMAIL)

    # Check for existing accounts

    count = Account.objects.filter(username__exact=username).count()
    if count >= 1:
        raise UsernameTaken(six.u(
            'The username is already taken. Please choose another. '
            'If this was the name of your old account please email %s')
            % settings.ACCOUNTS_EMAIL)

    # Check account datastore, in case username created outside Karaage.

    if account_exists(username):
        raise UsernameTaken(
            six.u('Username is already in external account datastore.'))

    return username
141806
def user_exists(username,
                token_manager=None,
                app_url=defaults.APP_URL):
    
    headers = token_manager.get_access_token_headers()
    auth_url = environment.get_auth_url(app_url=app_url)
    url = "%s/api/v1/accounts?username=%s" % (auth_url, username)
    response = requests.get(url, headers=headers)

    if response.status_code == 404:
        return False
    elif response.status_code == 200:
        return True
    else:
        raise JutException('Error %s: %s' % (response.status_code, response.text))