Exemplo 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': '注册成功'})
Exemplo n.º 2
0
def feed():
    if request.method == 'POST' and 'key' in request.form:
        record = FeedRecord(time=datetime.now(),
                            quant=int(request.form['key']))
        db_session.add(record)
        db_session.commit()
        return redirect(url_for('.feed'))

    feeds = FeedRecord.query.order_by(desc(FeedRecord.time)).all()
    return render_template('/feed/feed.html', feeds=feeds)
Exemplo n.º 3
0
def edit_feed(feed_id):
    record = FeedRecord.query.filter(FeedRecord.id == feed_id).first()
    feed_form = FeedForm(request.form, record)
    if request.method == 'POST':
        feed_form.populate_obj(record)
        if 'key' in request.form:
            record.quant = int(request.form['key'])
            db_session.add(record)
            db_session.commit()
            flash(u'记录编辑成功!')
        return redirect(url_for('.feed'))
    else:
        return render_template('feed/edit.html', feed_form=feed_form)
Exemplo 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': '上传成功'})
Exemplo 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': '注册成功'})
Exemplo n.º 6
0
def userregister():
    '''
        用户注册
    '''
    # 得到用户参数
    phone_number = request.values.get('phone_number')
    password = request.values.get('password')
    nickname = request.values.get('nickname')

    # 非空判断
    if not phone_number:
        return jsonify({'message': '请输入电话号码', 'code': 0})
    elif len(phone_number) != 11:
        return jsonify({'message': '电话位数不符合', 'code': 2})

        # 判断号码是否被使用
    user = User.query.filter_by(phone_number=phone_number).first()
    if user:
        return jsonify({'message': '该号码已被注册', 'code': 1})

    if not password:
        return jsonify({'message': '密码不允许为空', 'code': 0})
    if len(password) < 6:
        return jsonify({'message': '密码至少六位数', 'code': 2})

    if not nickname:
        nickname = 'zhangsan'

    s = hashlib.sha256()
    s.update(password.encode('utf-8'))
    s.update(phone_number[:3:2].encode('utf-8'))
    s.update('password'.encode('utf-8'))
    encryption_str = s.hexdigest()

    u1 = User()
    u1.password = encryption_str
    u1.phone_number = phone_number
    u1.nickname = nickname
    db_session.add(u1)
    db_session.flush()
    db_session.commit()
    return jsonify({'message': '注册成功', 'code': 200})
Exemplo n.º 7
0
def useralter():
    '''
        用户修改
    '''
    # 得到用户参数
    new_phone_number = request.values.get('new_phone_number')
    new_password = request.values.get('new_password')
    new_nickname = request.values.get('new_nickname')
    # 根据登陆的token 获得所登陆者的电话号码
    
    # 获得用户
    user = g.current_user
    # 修改电话号码
    if new_phone_number and len(new_phone_number) != 11:
        return jsonify({'message': '电话位数不符合', 'code': 2})

    # 修改密码
    if new_password and len(new_password) < 6 :
        return jsonify({'message': '密码至少六位数', 'code': 2})
    # import ipdb; ipdb.set_trace()
    # 判断输入的密码和电话是否有为空的 不为空则修改原始数据
    # 原始电话
    phone_number = user.phone_number

    if new_phone_number:
        user.phone_number = new_phone_number
    if new_password:
        user.password = new_password
    # 判断用户昵称是否修改了
    if new_nickname:
        user.nickname = new_nickname

    db_session.add(user)
    db_session.flush()
    db_session.commit()

    
    current_app.redis.delete('token:{0}'.format(g.token))
    current_app.redis.delete('user:{0}'.format(phone_number))

    return jsonify({'message': '修改成功,请重新登陆', 'code': 200})
Exemplo n.º 8
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': '上传成功'})
Exemplo n.º 9
0
def userregister():
    '''
        用户注册
    '''
    # 得到用户参数
    phone_number = request.values.get('phone_number')
    password = request.values.get('password')
    nickname = request.values.get('nickname')
    # 非空判断
    if not phone_number:
        return jsonify({'message': '请输入电话号码', 'code': 0})
    elif len(phone_number) != 11:
        return jsonify({'message': '电话位数不符合', 'code': 2})

    if not password:
        return jsonify({'message': '密码不允许为空', 'code': 0})
    if len(password) < 6:
        return jsonify({'message': '密码至少六位数', 'code': 2})
    
    if not nickname:
        nickname = 'zhangsan'
    
    # 判断号码是否被使用
    user = User.query.filter_by(phone_number=phone_number).first()
    # import ipdb; ipdb.set_trace()
    if user:
        return jsonify({'message': '该号码已被注册', 'code': 1})
    u1 = User()
    u1.password= password
    u1.phone_number= phone_number
    u1.nickname = nickname
    # import ipdb; ipdb.set_trace()
    db_session.add(u1)
    db_session.flush()
    db_session.commit()
    # import ipdb; ipdb.set_trace()    
    return jsonify({'message': '注册成功', 'code': 200})