Esempio n. 1
0
 def logout(self) -> None:
     """Log out the user by removing the cookies and session object."""
     request = HttpRequest()
     engine: SessionStore = import_module(settings.SESSION_ENGINE)
     if self.session:
         request.session = self.session
         request.user = auth.get_user(request)
     else:
         request.session = engine.SessionStore()
     auth.logout(request)
     self.cookies = SimpleCookie()
Esempio n. 2
0
def disable_credit_card(**kwargs):
    '''冻结账户功能'''
    account = kwargs.get('account')
    choice = input('继续锁定该账号?\033[1;35m (y)\033[0m: ')
    if choice == 'y' or choice == 'yes':
        account['lock_status'] = 1
        card_id = account.get('card_id', '')
        with open(DATABASE.get('path') + '/%s.json' % card_id, 'w') as f:
            json.dump(account, f)
        log_generate(log_type='access', card_id=card_id, message='locked')
        logout(LOGIN_STATUS=0)
Esempio n. 3
0
def manage_auth():
    # the functions will need data from the request
    if request.method == 'GET':
        auth = check_auth(session)
        if auth:
            return auth
        else:
            xml_res = ET.fromstring("<response></response>")
            msg = ET.Element('message')
            msg.text = 'NULL - You are not authenticated.'
            xml_res.append(msg)
            return ET.tostring(xml_res)
    elif request.method == 'POST':
        return login(request, session)
    elif request.method == 'DELETE':
        return logout(session)
Esempio n. 4
0
def logout(request, format=None):
    """Déconnexion, destruction de la session"""
    return auth_view.logout(request, format)
Esempio n. 5
0
        # 查看用户信息
        view_account_info()

    elif int(choice) == 3:
        # 转账业务
        transfer()

    elif int(choice) == 4:
        # 提现业务
        with_draw()

    elif int(choice) == 5:
        # 还款功能
        pay_back()

    elif int(choice) == 8:
        # 冻结账户功能
        disable_credit_card()

    elif int(choice) == 6:
        # 购物
        shopping_api.go_shopping()

    elif int(choice) == 9:
        # 退出登录
        logout()

    elif int(choice) == 7:
        # 消费记录查询
        output_transaction_records()
Esempio n. 6
0
def dispatch(env):
    """ Админка """
    content = ''
    auth_status = auth.authorize(env)
    if auth_status == auth.SUCCESS:
        data = {
            "path": env.path.current(),
            "session": env.session.data,
            "error": {}
        }
        # авторизован
        if env.path.current() == "l":
            # если хочет выйти - выгнать :)
            content = auth.logout(env)
        elif env.path.current(
        ) == "u" and env.session.data['user']['priv'] == 1:
            # пользователи
            env.path.next()
            content = users.dispatch(env)
        elif env.path.current() == "t":
            # шаблоны
            env.path.next()
            content = tpl.dispatch(env)
        elif env.path.current() == "a":
            # архив
            env.path.next()
            content = arch.dispatch(env)
        elif env.path.current() == "images":
            # картинки архива
            env.path.next()
            img = '/arch/' + '/'.join(env.path.pathparts[env.path.pointer:])
            logging.debug("Image: %s" % img)
            env.iredirect(img)
        elif env.path.current(
        ) == "r" and env.session.data['user']['priv'] == 1:
            # города
            env.path.next()
            content = regions.dispatch(env)
        else:
            tmpl = env.jinja.get_template("admin/index.html")
            if env.req.has_key("save"):
                password = re.compile(r"[\n|\r|\t|\s]+", re.S | re.U).sub(
                    " ",
                    env.req.getvalue("password", None).decode('utf8').strip())
                password2 = re.compile(r"[\n|\r|\t|\s]+", re.S | re.U).sub(
                    " ",
                    env.req.getvalue("password2", None).decode('utf8').strip())
                if password and password == password2:
                    sql = """UPDATE `users` SET password=%s WHERE id=%s"""
                    env.db.equery(sql,
                                  (password, env.session.data["user"]["id"]))
                    data["error"]["password"] = "******"
                    content = tmpl.render(data)
                else:
                    data["error"]["password"] = "******"
                    content = tmpl.render(data)
            else:
                content = tmpl.render(data)
    else:
        # не авторизован
        if env.path.current() == "c":
            code = env.path.next()
            auth_status = auth.chkcode(env, code)
            if auth_status == auth.SUCCESS:
                # нарисовать форму смены пароля
                content = auth.chpswd(env)
        elif env.req.has_key("lost"):
            content = auth.renew(env)
        else:
            # нарисовать форму авторизации
            content = auth.form(env, auth_status)
    return content
Esempio n. 7
0
def logout(request, format=None):
    return auth_view.logout(request, format)