Пример #1
0
def get_git_path_info(path):
    path_split = path.split("/")
    git_name = path_split[1]
    # raw path: project_id.git
    if git_name.endswith('.git'):
        project = Project.get_by_name(git_name[:-4])
        if project:
            path_split[1] = "%s.git" % project.id
            return '/'.join(path_split)
    else:
        owner_name, git_name = path_split[1:3]
        # user project: user/project.git
        user = User.get_by_name(owner_name)
        if user:
            project = Project.get_by_name_and_owner(git_name[:-4], user.id)
            if project:
                path_split[1] = ""
                path_split[2] = "%s.git" % project.id
                return '/'.join(path_split[1:])
            return
        # org project: org/project.git
        org = Organization.get_by_name(owner_name)
        if org:
            project = Project.get_by_name_and_owner(git_name[:-4], user.id)
            if project:
                path_split[1] = ""
                path_split[2] = "%s.git" % project.id
                return '/'.join(path_split[1:])
Пример #2
0
def get_git_path_info(path):
    path_split = path.split("/")
    git_name = path_split[1]
    # raw path: project_id.git
    if git_name.endswith('.git'):
        project = Project.get_by_name(git_name[:-4])
        if project:
            path_split[1] = "%s.git" % project.id
            return '/'.join(path_split)
    else:
        owner_name, git_name = path_split[1:3]
        # user project: user/project.git
        user = User.get_by_name(owner_name)
        if user:
            project = Project.get_by_name_and_owner(git_name[:-4], user.id)
            if project:
                path_split[1] = ""
                path_split[2] = "%s.git" % project.id
                return '/'.join(path_split[1:])
            return
        # org project: org/project.git
        org = Organization.get_by_name(owner_name)
        if org:
            project = Project.get_by_name_and_owner(git_name[:-4], user.id)
            if project:
                path_split[1] = ""
                path_split[2] = "%s.git" % project.id
                return '/'.join(path_split[1:])
Пример #3
0
def api_list_user(users):
    rs = []
    for username in users:
        user = User.get_by_name(username)
        rs.append({'username': user.username,
                   'avatar_url': user.avatar_url,
                   'email': user.email,
                   'url': user.url, })
    return rs
Пример #4
0
def __token_grant_by_password(apikey):
    username = __check_request_required_var('username')
    password = __check_request_required_var('password')
    user = User.get_by_name(username)
    if not DEVELOP_MODE and user and not user.validate_password(password):
        raise InvalidRequest(err.username_password_mismatch)

    token = ApiToken.add(apikey.client_id, username)
    return json.dumps(token.token_dict())
Пример #5
0
def __token_grant_by_password(apikey):
    username = __check_request_required_var('username')
    password = __check_request_required_var('password')
    user = User.get_by_name(username)
    if not DEVELOP_MODE and user and not user.validate_password(password):
        raise InvalidRequest(err.username_password_mismatch)

    token = ApiToken.add(apikey.client_id, username)
    return json.dumps(token.token_dict())
Пример #6
0
    def __init__(self, repo, commit):
        self.repo = repo
        self._commit = commit
        self.type = 'commit'
        self.repo_name = repo.name
        parent = commit['parent'][0] if commit['parent'] else None
        self.parent = parent
        self.parents = commit['parent']
        message = ("%s\n\n%s" % (
            commit['message'],
            remove_unknown_character(commit['body']))
        ).strip()
        self.message = message
        self.message_header = commit['message']
        self.message_body = commit['body']
        self.sha = commit['sha']
        self.tree = commit['tree']

        author_name = commit['author']['name']
        self.author_name = author_name
        author_email = email_normalizer(author_name, commit['author']['email'])
        self.author_email = author_email
        self.email = author_email
        # FIXME: user
        #author = User(name=author_name, email=author_email)
        author = User.get_by_name(author_name)
        self.author = author
        author_date = datetime.fromtimestamp(commit['author']['time'],
                                             FixedOffset(commit['author']['offset']))
        author_timestamp = str(commit['author']['time'])
        self.author_time = author_date
        self.author_timestamp = author_timestamp
        self.time = author_date

        committer_name = commit['committer']['name']
        committer_email = email_normalizer(
            committer_name, commit['committer']['email'])
        # FIXME: user
        #committer = User(name=committer_name, email=committer_email)
        committer = User.get_by_name(committer_name)
        self.committer = committer
        committer_date = datetime.fromtimestamp(commit['committer']['time'],
                                             FixedOffset(commit['committer']['offset']))
        self.committer_time = committer_date
Пример #7
0
    def __init__(self, repo, commit):
        self.repo = repo
        self._commit = commit
        self.type = 'commit'
        self.repo_name = repo.name
        parent = commit['parent'][0] if commit['parent'] else None
        self.parent = parent
        self.parents = commit['parent']
        message = ("%s\n\n%s" %
                   (commit['message'], remove_unknown_character(
                       commit['body']))).strip()
        self.message = message
        self.message_header = commit['message']
        self.message_body = commit['body']
        self.sha = commit['sha']
        self.tree = commit['tree']

        author_name = commit['author']['name']
        self.author_name = author_name
        author_email = email_normalizer(author_name, commit['author']['email'])
        self.author_email = author_email
        self.email = author_email
        # FIXME: user
        #author = User(name=author_name, email=author_email)
        author = User.get_by_name(author_name)
        self.author = author
        author_date = datetime.fromtimestamp(
            commit['author']['time'], FixedOffset(commit['author']['offset']))
        author_timestamp = str(commit['author']['time'])
        self.author_time = author_date
        self.author_timestamp = author_timestamp
        self.time = author_date

        committer_name = commit['committer']['name']
        committer_email = email_normalizer(committer_name,
                                           commit['committer']['email'])
        # FIXME: user
        #committer = User(name=committer_name, email=committer_email)
        committer = User.get_by_name(committer_name)
        self.committer = committer
        committer_date = datetime.fromtimestamp(
            commit['committer']['time'],
            FixedOffset(commit['committer']['offset']))
        self.committer_time = committer_date
Пример #8
0
def _q_index(request):
    if request.method == 'POST':
        name = request.get_form_var('login')
        password = request.get_form_var('password')
        user = User.get_by_name(name)
        if user and user.validate_password(password):
            user.set_session(request)
            request.user = user
            return request.redirect('/')
    return st('login.html')
Пример #9
0
def api_list_user(users):
    rs = []
    for username in users:
        user = User.get_by_name(username)
        rs.append({
            'username': user.username,
            'avatar_url': user.avatar_url,
            'email': user.email,
            'url': user.url,
        })
    return rs
Пример #10
0
 def __init__(self, header):
     self.login = None
     self.passwd = None
     self.user = None
     try:
         auth_type, auth_string = header.split()
         login, passwd = b64decode(auth_string).split(':')
         self.login = login
         self.passwd = passwd
         self.user = User.get_by_name(login)
     except (ValueError, TypeError):
         pass
Пример #11
0
 def __init__(self, header):
     self.login = None
     self.passwd = None
     self.user = None
     try:
         auth_type, auth_string = header.split()
         login, passwd = b64decode(auth_string).split(':')
         self.login = login
         self.passwd = passwd
         self.user = User.get_by_name(login)
     except (ValueError, TypeError):
         pass
Пример #12
0
    def _q_lookup(self, request, name):
        from vilya.views.api.v1.users import UserUI
        from vilya.views.api.v1.organizations import OrganizationUI

        user = User.get_by_name(name)
        if user:
            return UserUI(user)

        org = Organization.get_by_name(name)
        if org:
            return OrganizationUI(org)

        raise TraversalError
Пример #13
0
def _q_lookup(request, name):
    if name in ['static', 'js', 'css']:
        return StaticUI(request, name)

    user = User.get_by_name(name)
    if user:
        return UserUI(user)

    org = Organization.get_by_name(name)
    if org:
        return OrganizationUI(org)

    raise TraversalError
Пример #14
0
def _q_lookup(request, name):
    if name in ['static', 'js', 'css']:
        return StaticUI(request, name)

    user = User.get_by_name(name)
    if user:
        return UserUI(user)

    org = Organization.get_by_name(name)
    if org:
        return OrganizationUI(org)

    raise TraversalError
Пример #15
0
def _q_index(request):
    if request.method == 'POST':
        name = request.get_form_var('username')
        password = request.get_form_var('password')
        user = User.get_by_name(name)
        if user and user.validate_password(password):
            continue_url = request.get_form_var(
                'continue', '') or request.get_form_var('Referer', '')
            request.user = user
            set_user(user.id)
            return json.dumps({"r": 0, "continue": continue_url or "/"})
        return json.dumps({"r": 1})
    return st('login.html')
Пример #16
0
def _q_index(request):
    if request.method == 'POST':
        name = request.get_form_var('username')
        password = request.get_form_var('password')
        user = User.get_by_name(name)
        if user and user.validate_password(password):
            continue_url = request.get_form_var(
                'continue', '') or request.get_form_var('Referer', '')
            request.user = user
            set_user(user.id)
            return json.dumps({"r": 0, "continue": continue_url or "/"})
        else:
            message = '用户名或密码错误!'
            return json.dumps({"r": 1, 'message': message})
    return st('login.html')
Пример #17
0
def authfunc(env, username, passwd):
    if DEVELOP_MODE or (env['REMOTE_ADDR'] == '127.0.0.1'
                        and env['HTTP_HOST'] == 'localhost:8080'):
        return True

    if not passwd:
        return

    if username == 'code' and passwd == 'code':
        return True

    user = User.get_by_name(username)
    if user and user.validate_password(passwd):
        return True

    is_push = 'service=git-receive-pack' in env['QUERY_STRING'] \
              or '/git-receive-pack' in env['PATH_INFO']
    if is_push:
        pass
        # FIXME: push permission
    return True
Пример #18
0
def authfunc(env, username, passwd):
    if DEVELOP_MODE or (env['REMOTE_ADDR'] == '127.0.0.1'
                        and env['HTTP_HOST'] == 'localhost:8080'):
        return True

    if not passwd:
        return

    if username == 'code' and passwd == 'code':
        return True

    user = User.get_by_name(username)
    if user and user.validate_password(passwd):
        return True

    is_push = 'service=git-receive-pack' in env['QUERY_STRING'] \
              or '/git-receive-pack' in env['PATH_INFO']
    if is_push:
        pass
        # FIXME: push permission
    return True