Ejemplo n.º 1
0
def get_repo_dirpath(owner: str, reponame: str) -> str:
    if not check_reponame_validity(reponame) or not check_username_validity(
            owner):
        raise ValueError('invalid reponame or username')
    dirpath = os.path.join(settings['repository_path'],
                           '{}/{}'.format(owner, reponame))
    return dirpath
Ejemplo n.º 2
0
async def create_new_user(username: str, mail_address: str, password: str):
    if not check_username_validity(username):
        return False
    if not check_mail_validity(mail_address):
        return False
    if not check_password_validity(password):
        return False
    flag = await check_user_existing(username)
    if flag:
        raise NameError('Username already existing')

    salt = username[random.randint(
        0,
        len(username) - 1)] + username[random.randint(
            0,
            len(username) - 1)] + username[random.randint(
                0,
                len(username) - 1)]
    sha512 = hashlib.sha512()
    temp = password + salt
    temp = temp.encode('utf-8')
    sha512.update(temp)
    encrypted_password = sha512.hexdigest()
    await execute(
        '''
    INSERT INTO users_info(username, mail_address, password, salt) VALUES($1, $2, $3, $4)''',
        username, mail_address, encrypted_password, salt)
    return True
Ejemplo n.º 3
0
async def verify_user(username: str, password: str):
    if not check_username_validity(username):
        return False
    if not check_password_validity(password):
        return False
    if not check_password_validity(password):
        return False
    flag = await check_user_existing(username)
    if (flag == False):
        return False
    temp_salt = await fetchrow(
        '''
        SELECT salt FROM users_info
        WHERE username =$1
        ''', username)
    sha5122 = hashlib.sha512()
    temp = (password + temp_salt['salt']).strip()
    temp = temp.encode('utf-8')
    sha5122.update(temp)
    temp_encrypted_pw = sha5122.hexdigest()
    temp_password = await fetchrow(
        '''
        SELECT password FROM users_info
        WHERE username =$1
        ''', username)
    print(temp_encrypted_pw)
    if (temp_encrypted_pw == temp_password['password']):
        return True
    else:
        return False
Ejemplo n.º 4
0
async def alter_username(old_username: str, new_username: str):
    if (check_username_validity(new_username) == False
            or check_username_validity(old_username) == False):
        raise NameError()
    else:
        flag = check_user_existing(old_username)
        if not flag:
            raise NameError('User not existing')
        else:
            await execute(
                '''
                    UPDATE users_info
                    SET username = $1
                    WHERE username = $2
                ''', new_username, old_username)
            await execute(
                '''
                    UPDATE profiles
                    SET username = $1
                    WHERE username = $2
                ''', new_username, old_username)
            await execute(
                '''
                    UPDATE log_info
                    SET username = $1
                    WHERE username = $2
                ''', new_username, old_username)
            await execute(
                '''
                    UPDATE repos
                    SET username = $1
                    WHERE username = $2
                ''', new_username, old_username)
            await execute(
                '''
                    UPDATE read_permission
                    SET username = $1
                    WHERE username = $2
                ''', new_username, old_username)
            await execute(
                '''
                    UPDATE admin_permission
                    SET username = $1
                    WHERE username = $2
                ''', new_username, old_username)
            return True
Ejemplo n.º 5
0
def add_user_pending_verifying(username: str, mail_address: str,
                               password: str):
    if (check_username_validity(username) and check_mail_validity(mail_address)
            and check_password_validity(password)):
        pending_info = {}
        pending_info['username'] = username
        pending_info['email'] = mail_address
        pending_info['password'] = password
        pending_info['token'] = secrets.token_urlsafe(16)
        signup_token.append_token(pending_info)
        if not settings.settings['enable_email']:
            return pending_info['token']
        else:
            return None
    else:
        raise NameError()
Ejemplo n.º 6
0
async def set_profile(username: str,
                      firstname: str,
                      lastname: str,
                      icon_path: str = None,
                      introduction: str = None,
                      company: str = None,
                      location: str = None,
                      public_email: str = None,
                      website: str = None):
    if not check_username_validity(username):
        return False
    flag = await check_user_existing(username)
    if not flag:
        raise NameError('User does not exist')
    else:
        flag = await check_profile_existing(username)
        if not flag:
            await execute(
                '''
                INSERT INTO profiles(username, icon_url,firstname,lastname, introduction, company, location,public_email, website) VALUES($1, $2, $3, $4, $5, $6,$7,$8,$9)
                ''', username, icon_path, firstname, lastname, introduction,
                company, location, public_email, website)
        else:
            await execute(
                '''
                UPDATE profiles
                SET lastname=$1, firstname=$2
                WHERE usernmae=$3
                ''', lastname, firstname, username)
            if icon_path != None:
                await execute(
                    '''
                    UPDATE profiles
                    SET icon_url=$1
                    WHERE username=$2
                    ''', icon_path, username)
            if introduction != None:
                await execute(
                    '''
                    UPDATE profiles
                    SET introduction=$1
                    WHERE username=$2
                    ''', introduction, username)
            if company != None:
                await execute(
                    '''
                    UPDATE profiles
                    SET company=$1
                    WHERE username=$2
                    ''', company, username)
            if location != None:
                await execute(
                    '''
                    UPDATE profiles
                    SET location=$1
                    WHERE username=$2
                    ''', location, username)
            if public_email != None:
                await execute(
                    '''
                    UPDATE profiles
                    SET public_email=$1
                    WHERE username=$2
                    ''', public_email, username)
            if website != None:
                await execute(
                    '''
                    UPDATE profiles
                    SET website=$1
                    WHERE username=$2
                    ''', website, username)
        return True