Ejemplo n.º 1
0
def register_step_4():
    """
    基本资料提交
    """
    phone_number = request.get_json().get('phone_number')
    nickname = request.get_json().get('nickname')

    is_validate = current_app.redis.get('is_validate:%s' % phone_number)

    if is_validate != '1':
        return jsonify({'code': 0, 'message': '验证码没有通过'})

    password = current_app.redis.hget('register:%s' % phone_number, 'password')

    new_user = User(phone_number=phone_number, password=password, nickname=nickname)
    db_session.add(new_user)

    try:
        db_session.commit()
    except Exception as e:
        print e
        db_session.rollback()
        return jsonify({'code': 0, 'message': '注册失败'})
    finally:
        current_app.redis.delete('is_validate:%s' % phone_number)
        current_app.redis.delete('register:%s' % phone_number)

    return jsonify({'code': 1, 'message': '注册成功'})
Ejemplo n.º 2
0
def set_head_picture():
    '''
        图片名存储到数据库与七牛
    '''
    user = g.current_user
    # 获得图片的七牛云图片
    # import ipdb; ipdb.set_trace()
    head_picture = get_qiniu_token(user.phone_number).json
    code, key, token = get_qiniu_token(user.phone_number).json.values()
    # 用户提交的图片
    up_head_picture = request.values.get('head_picture')
    head_picture = 'http://pntn3xhqe.bkt.clouddn.com/{0}'.format(key)
    user.head_picture = head_picture
    # 图片上传
    localfile = r'{0}'.format(up_head_picture)
    ret, info = put_file(token, key, localfile)
    try:
        db_session.commit()
    except Exception as e:
        print(e)
        db_session.rollback()
        return jsonify({'code': 0, 'message': '未能成功上传'})
    current_app.redis.hset('user:{0}'.format(user.phone_number),
                           'head_picture', head_picture)
    return jsonify({'code': 1, 'message': '成功上传'})
Ejemplo n.º 3
0
def set_head_picture():
    head_picture = request.get_json().get('head_picture')
    user = g.current_user
    user.head_picture = head_picture
    try:
        db_session.commit()
    except Exception as e:
        print e
        db_session.rollback()
        return jsonify({'code': 0, 'message': '未能成功上传'})
    current_app.redis.hset('user:%s' % user.phone_number, 'head_picture', head_picture)
    return jsonify({'code': 1, 'message': '成功上传'})
Ejemplo n.º 4
0
def post_blog():
    user = g.current_user

    title = request.get_json().get('title')
    text_content = request.get_json().get('text_content')
    pictures = request.get_json().get('pictures')

    newblog = SmallBlog(title=title, text_content=text_content, post_user=user)

    newblog.pictures = pictures
    db_session.add(newblog)
    try:
        db_session.commit()
    except Exception as e:
        print e
        db_session.rollback()
        return jsonify({'code': 0, 'message': '上传不成功'})
    return jsonify({'code': 1, 'message': '上传成功'})
Ejemplo n.º 5
0
def userregister_2():
    '''
        用户注册
    '''
    phone_number = request.values.get('phone_number')
    nickname = request.values.get('nickname')
    # 非空判断
    if not phone_number:
        return jsonify({'message': '请输入电话号码', 'code': 0})
    elif len(phone_number) != 11:
        return jsonify({'message': '电话位数不符合', 'code': 2})
    import ipdb
    ipdb.set_trace()
    # 从redis中获取验证码是否验证成功
    is_validate = current_app.redis.get('is_validate:{0}'.format(phone_number))
    if is_validate:
        is_validate = is_validate.decode('utf-8')
    if is_validate != '1':
        return jsonify({'code': 0, 'message': '验证码没验证成功'})

    # 获取password
    password = current_app.redis.hget('register:{0}'.format(phone_number),
                                      'password')
    if password:
        password = password.decode('utf-8')
    if not nickname:
        nickname = '张三同学'
    new_user = User(phone_number=phone_number,
                    password=password,
                    nickname=nickname)
    db_session.add(new_user)

    try:
        db_session.commit()
    except Exception as e:
        print(e)
        db_session.rollback()
        return jsonify({'code': 1, 'message': '注册失败'})
    finally:
        current_app.redis.delete('is_validate:{0}'.format(phone_number))
        current_app.redis.delete('register:{0}'.format(phone_number))

    return jsonify({'code': 200, 'message': '注册成功'})
Ejemplo n.º 6
0
def post_blog():
    '''
        提交新的博文
    '''
    user = g.current_user
    # 接受参数
    title = request.values.get('title')
    text_content = request.values.get('text_content')
    pictures = request.values.get('pictures')
    # 实例化一个新的博文
    newblog = SmallBlog(title=title, text_content=text_content, post_user=user)
    # 博文图片
    newblog.pictures = pictures
    db_session.add(newblog)
    try:
        db_session.commit()
    except Exception as e:
        print(e)
        db_session.rollback()
        return jsonify({'code': 0, 'message': '上传不成功'})
    return jsonify({'code': 1, 'message': '上传成功'})
Ejemplo n.º 7
0
def shutdown_session(exception=None):
    """
    teardown request
    """
    db_session.rollback()
    db_session.close()