예제 #1
0
def get_uid():
    g.uid = -1
    g.scope = ''
    try:
        user = Users.query.filter_by(username=request.json.get('username', ''),
                                     banned=0).first()
    except Exception as e:
        logger.error(e)
        raise
    if user:
        if sha256_crypt.verify(request.json.get('password', ''), user.password):
            g.uid = user.id
            g.scope = user.scope
            return str(g.uid)
    return request.remote_addr
예제 #2
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('mobiles',
                            type=list,
                            required=True,
                            help='A mobiles list field is require',
                            location='json')
        parser.add_argument('content',
                            type=unicode,
                            required=True,
                            help='A content field is require',
                            location='json')
        args = parser.parse_args()
        try:
            sms = SMS(mobiles=json.dumps(request.json['mobiles']),
                      content=request.json['content'],
                      returned_value=-99,
                      user_id=1)
            db.session.add(sms)
            db.session.commit()
            sms_ini = app.config['SMS_WSDL_PARAMS']
            sms_client = SMSClient(sms_ini['url'])
            sms_client.sms_init(sms_ini['db_ip'], sms_ini['db_name'],
                                sms_ini['db_port'], sms_ini['user'],
                                sms_ini['pwd'])
            r = sms_client.sms_send(sms_ini['user'], sms_ini['user'],
                                    sms_ini['pwd'], request.json['mobiles'],
                                    request.json['content'], sms.id)
            sms.returned_value = r
            db.session.commit()
            del sms_client
        except Exception as e:
            logger.error(e)
            raise
        result = {
            'id': sms.id,
            'mobiles': json.loads(sms.mobiles),
            'date_send': str(sms.date_send),
            'content': sms.content,
            'user_id': sms.user_id,
            'returned_value': sms.returned_value
        }
        if sms.returned_value == 0:
            result['succeed'] = True
        else:
            result['succeed'] = False

        return result, 201
예제 #3
0
def get_uid():
    g.uid = -1
    g.scope = ''
    try:
        user = Users.query.filter_by(username=request.json.get('username', ''),
                                     banned=0).first()
    except Exception as e:
        logger.error(e)
        raise
    if user:
        if sha256_crypt.verify(request.json.get('password', ''),
                               user.password):
            g.uid = user.id
            g.scope = user.scope
            return str(g.uid)
    return request.remote_addr
예제 #4
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('mobiles', type=list, required=True,
                            help='A mobiles list field is require',
                            location='json')
        parser.add_argument('content', type=unicode, required=True,
                            help='A content field is require', location='json')
        args = parser.parse_args()
        try:
            sms = SMS(mobiles=json.dumps(request.json['mobiles']),
                      content=request.json['content'],
                      returned_value=-99, user_id=1)
            db.session.add(sms)
            db.session.commit()
            sms_ini = app.config['SMS_WSDL_PARAMS']
            sms_client = SMSClient(sms_ini['url'])
            sms_client.sms_init(sms_ini['db_ip'], sms_ini['db_name'],
                                sms_ini['db_port'], sms_ini['user'],
                                sms_ini['pwd'])
            r = sms_client.sms_send(sms_ini['user'], sms_ini['user'],
                                    sms_ini['pwd'],request.json['mobiles'],
                                    request.json['content'], sms.id)
            sms.returned_value = r
            db.session.commit()
            del sms_client
        except Exception as e:
            logger.error(e)
            raise
        result = {
            'id': sms.id,
            'mobiles': json.loads(sms.mobiles),
            'date_send': str(sms.date_send),
            'content': sms.content,
            'user_id': sms.user_id,
            'returned_value': sms.returned_value
        }
        if sms.returned_value == 0:
            result['succeed'] = True
        else:
            result['succeed'] = False

        return result, 201