コード例 #1
0
ファイル: staff.py プロジェクト: dequis/wakarimasen
def add_staff(username, pt_password, account, reign):
    if not username:
        raise WakaError('A username is necessary.')
    if not pt_password:
        raise WakaError('A password is necessary.')
    if len(pt_password) < 8:
        raise WakaError('Passwords should be eight characters minimum.')
    if len(reign) == 0 and account == MODERATOR:
        raise WakaError('Board reign not specified for moderator account.')

    # Check whether the user exists already.
    try:
        StaffMember.get(username)
    except LoginError:
        # User not found. Good.
        pass
    else:
        raise WakaError('Username exists.')

    session = model.Session()
    table = model.account
    password = misc.hide_critical_data(pt_password, config.SECRET)
    reign_str = ','.join(reign)

    sql = table.insert().values(username=username, password=password,
                                account=account, reign=reign_str,
                                disabled=0)
    session.execute(sql)
コード例 #2
0
ファイル: staff_interface.py プロジェクト: dequis/wakarimasen
def edit_staff_proxy(
    cookie, mpass, username, newpassword=None, newclass=None, originalpassword="", reign=None, disable=None
):

    user = staff.StaffMember.get_from_cookie(cookie)

    if user.username == username:
        if misc.hide_critical_data(originalpassword, config.SECRET) != user.password:
            raise WakaError(strings.WRONGPASS)
        newclass = None
        reign = None
    elif user.account == staff.ADMIN:
        edited_user = staff.StaffMember.get(username)
        if edited_user.account == staff.ADMIN and mpass != config.ADMIN_PASS:
            raise WakaError("Incorrect management password.")
    else:
        raise WakaError(strings.INSUFFICIENTPRIVILEGES)

    staff.edit_staff(username, clear_pass=newpassword, new_class=newclass, reign=reign, disable=disable)

    board = local.environ["waka.board"]

    forward_task = "admin" if user.username == username else "staff"

    return make_http_forward(misc.make_script_url(task=forward_task, board=board.name), config.ALTERNATE_REDIRECT)
コード例 #3
0
def edit_staff_proxy(admin, mpass, username, newpassword=None, newclass=None,
                     originalpassword='', reign=None, disable=None):

    user = staff.check_password(admin)

    if user.username == username:
        if misc.hide_critical_data(originalpassword, config.SECRET) \
           != user.password:
            raise WakaError(strings.WRONGPASS)
        newclass = None
        reign = None
    elif user.account == staff.ADMIN:
        edited_user = staff.StaffMember.get(username)
        if edited_user.account == staff.ADMIN and mpass != config.ADMIN_PASS:
            raise WakaError('Incorrect management password.')
    else:
        raise WakaError(strings.INUSUFFICENTPRIVLEDGES)

    staff.edit_staff(username, clear_pass=newpassword, new_class=newclass,
                     reign=reign, disable=disable)

    board = local.environ['waka.board']

    forward_task = 'admin' if user.username == username else 'staff'

    return make_http_forward(misc.make_script_url(task=forward_task,
        board=board.name), config.ALTERNATE_REDIRECT)
コード例 #4
0
def add_staff(username, pt_password, account, reign):
    if not username:
        raise WakaError('A username is necessary.')
    if not pt_password:
        raise WakaError('A password is necessary.')
    if len(pt_password) < 8:
        raise WakaError('Passwords should be eight characters minimum.')
    if len(reign) == 0 and account == MODERATOR:
        raise WakaError('Board reign not specified for moderator account.')

    # Check whether the user exists already.
    try:
        StaffMember.get(username)
    except LoginError:
        # User not found. Good.
        pass
    else:
        raise WakaError('Username exists.')

    session = model.Session()
    table = model.account
    password = misc.hide_critical_data(pt_password, config.SECRET)
    reign_str = ','.join(reign)

    sql = table.insert().values(username=username,
                                password=password,
                                account=account,
                                reign=reign_str,
                                disabled=0)
    session.execute(sql)
コード例 #5
0
ファイル: staff.py プロジェクト: dequis/wakarimasen
    def password(self, new):
        if len(new) < 8:
            raise WakaError('Passwords should be at least eight characters!')

        new = misc.hide_critical_data(new, config.SECRET)

        self._update_db(password=new)
        self._password = new
コード例 #6
0
    def password(self, new):
        if len(new) < 8:
            raise WakaError('Passwords should be at least eight characters!')

        new = misc.hide_critical_data(new, config.SECRET)

        self._update_db(password=new)
        self._password = new
コード例 #7
0
def do_login(username=None,
             password=None,
             save_login=False,
             admin=None,
             board=None,
             nexttask=HOME_PANEL):

    bad_pass = False
    staff_entry = None

    if not staff.staff_exists():
        return make_first_time_setup_gateway()
    elif username and password:
        # Login via login form entry.
        try:
            staff_entry = staff.StaffMember.get(username)
        except staff.LoginError:
            # Bad username.
            bad_pass = True
        else:
            crypt_pass = misc.hide_critical_data(password, config.SECRET)
            if crypt_pass == staff_entry.password:
                remote = local.environ['REMOTE_ADDR']
                staff_entry.login_host(remote)
            else:
                bad_pass = True
    elif admin:
        # Attempt automatic login.
        try:
            staff_entry = staff.check_password(admin)
        except staff.LoginError:
            clear_login_cookies()
            bad_pass = True
    else:
        # No login credentials given.
        bad_pass = True

    if bad_pass:
        return Template('admin_login_template')
    else:
        login = staff_entry.login_data
        login.make_cookie(save_login=save_login)
        return StaffInterface(login.cookie, dest=nexttask, board=board)
コード例 #8
0
def do_login(username=None, password=None, save_login=False,
             admin=None, board=None, nexttask=HOME_PANEL):

    bad_pass = False
    staff_entry = None

    if not staff.staff_exists():
        return make_first_time_setup_gateway()
    elif username and password:
        # Login via login form entry.
        try:
            staff_entry = staff.StaffMember.get(username)
        except staff.LoginError:
            # Bad username.
            bad_pass = True
        else:
            crypt_pass = misc.hide_critical_data(password, config.SECRET)
            if crypt_pass == staff_entry.password:
                remote = local.environ['REMOTE_ADDR']
                staff_entry.login_host(remote)
            else:
                bad_pass = True
    elif admin:
        # Attempt automatic login.
        try:
            staff_entry = staff.check_password(admin)
        except staff.LoginError:
            clear_login_cookies()
            bad_pass = True
    else:
        # No login credentials given.
        bad_pass = True

    if bad_pass:
        return Template('admin_login_template')
    else:
        login = staff_entry.login_data
        login.make_cookie(save_login=save_login)
        return StaffInterface(login.cookie, dest=nexttask, board=board)
コード例 #9
0
def edit_staff_proxy(admin,
                     mpass,
                     username,
                     newpassword=None,
                     newclass=None,
                     originalpassword='',
                     reign=None,
                     disable=None):

    user = staff.check_password(admin)

    if user.username == username:
        if misc.hide_critical_data(originalpassword, config.SECRET) \
           != user.password:
            raise WakaError(strings.WRONGPASS)
        newclass = None
        reign = None
    elif user.account == staff.ADMIN:
        edited_user = staff.StaffMember.get(username)
        if edited_user.account == staff.ADMIN and mpass != config.ADMIN_PASS:
            raise WakaError('Incorrect management password.')
    else:
        raise WakaError(strings.INSUFFICIENTPRIVILEGES)

    staff.edit_staff(username,
                     clear_pass=newpassword,
                     new_class=newclass,
                     reign=reign,
                     disable=disable)

    board = local.environ['waka.board']

    forward_task = 'admin' if user.username == username else 'staff'

    return make_http_forward(
        misc.make_script_url(task=forward_task, board=board.name),
        config.ALTERNATE_REDIRECT)
コード例 #10
0
ファイル: staff.py プロジェクト: dequis/wakarimasen
def crypt_pass(cleartext, remote):
    return misc.hide_critical_data(','.join((cleartext, remote)),
                                            config.SECRET)
コード例 #11
0
def crypt_pass(cleartext, remote):
    return misc.hide_critical_data(','.join((cleartext, remote)),
                                   config.SECRET)