Exemple #1
0
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('username', required=True)
        parser.add_argument('password', required=True)
        args = parser.parse_args()

        merchant = DB.session.query(Merchant).filter(
            Merchant.username == args.username).first()
        if merchant is None:
            return CommonUtil.json_response(-1, "用户名不存在")

        if merchant.password == CommonUtil.create_user_password(
                args.username, args.password):
            # 生成新token
            merchant.token = CommonUtil.create_admin_token(args.username)
            DB.session.commit()

            merchant = DB.session.query(Merchant).filter(
                Merchant.username == args.username).first()
            dic = {'token': fields.String}

            return CommonUtil.json_response(0, "登录成功", marshal(merchant, dic))
        else:
            print(merchant.password)
            print(CommonUtil.create_user_password(args.username,
                                                  args.password))
            return CommonUtil.json_response(-1, "密码错误")
Exemple #2
0
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('username', required=True)
        parser.add_argument('password', required=True)
        parser.add_argument('validId', required=True)
        parser.add_argument('validValue', required=True)
        args = parser.parse_args()

        # 效验验证码
        result = CheckUtil.check_valid_image(args.validId, args.validValue)
        if result.code != 0:
            CommonUtil.json_response(result.code, result.message)

        admin = DB.session.query(Admin).filter(Admin.username == args.username).first()
        if admin is None:
            return CommonUtil.json_response(-1, "账号不存在")

        if admin.password == args.password:
            # 生成新token
            admin.token = CommonUtil.create_admin_token(args.username)
            DB.session.commit()

            admin = DB.session.query(Admin).filter(Admin.username == args.username).first()
            dic = {
                'token': fields.String
            }

            return CommonUtil.json_response(0, "登录成功", marshal(admin, dic))
        else:
            return CommonUtil.json_response(-1, "密码错误")