Exemple #1
0
 def login():
     username = request.form.get('username')
     password = request.form.get('password')
     if not all([username, password]):
         return jsonify(common.falseReturn('', '不能为空'))
     else:
         return Auth.authenticate(Auth, username, password)
Exemple #2
0
    def post(self):
        """
        bee_app:   token if check userid,password else false_response
        not bee_app:  token if td_login_status else false_response
        :return:
        """
        info = dict(request.values)
        authorization = info.pop('authorization', None)
        if not authorization or not G.check_authorization(authorization):
            return false_response(msg='授权码错误')
        userid = info.get('userid')
        password = info.get('password')
        # bee_current_app存在
        if bee_current_app and \
                bee_current_app.trader and \
                bee_current_app.td_login_status:
            if userid == bee_current_app.trader.userid and password == bee_current_app.trader.password:
                token = Auth.authenticate(info)
                return true_response(data=token, msg='登录成功')
            return false_response(msg='Refuse!')

        else:  # bee_current_app 不不存在
            bee_app = CtpBee(name=info.get("username"),
                             import_name=__name__,
                             refresh=True,
                             logger_class=VLog)
            login_info = {
                "CONNECT_INFO": info,
                "INTERFACE": info.get('interface'),
                "TD_FUNC": True,
                "MD_FUNC": True,
            }
            bee_app.config.from_mapping(login_info)
            default = DefaultSettings("default_settings", bee_app, io)
            load_strategy(bee_app)  # 加载策略
            bee_app.start()
            sleep(1)

            if bee_current_app and \
                    bee_current_app.trader and \
                    bee_current_app.td_login_status:
                token = Auth.authenticate(info)

                return true_response(data=token, msg='重新登录成功')
            else:
                del_app(__name__)
                return false_response(msg="重新登录出现错误")