Ejemplo n.º 1
0
def upload_avatar():
    try:
        assert 'avatar' in request.files, 'please select an avatar'
        UserHelper.modify_avatar(request.files['avatar'])
    except AssertionError, e:
        flash(e.message)
        return redirect(url_for('home.home'))
Ejemplo n.º 2
0
def home():
    rec_categorys = CategoryHelper.get_hot_categorys()
    rec_row1 = rec_categorys[:3]
    rec_row2 = rec_categorys[3:6]
    stat = dict()
    stat['unfinished'] = UserHelper.get_stat(False)
    stat['finished'] = UserHelper.get_stat(True)
    avatar = current_user.avatar.read()
    return render_template('index-after-login.html', rec_row1=rec_row1, rec_row2=rec_row2, stat=stat, avatar=avatar)
Ejemplo n.º 3
0
def login():
    try:
        check_form_para(['email', 'password'])
    except AssertionError:
        flash(u'请输入邮箱和密码')
        return redirect(url_for('home.intro', login_error=1))

    user_to_login = UserHelper.get_by_email(request.form['email'])
    if user_to_login == None or not UserHelper.verify_password(user_to_login, request.form['password']):
        flash(u'无效的邮箱或密码')
        return redirect(url_for('home.intro', login_error=1))
    
    is_remember = False if 'remember_me' not in request.form else True

    login_user(user_to_login, remember=is_remember)
    return redirect(url_for('home.home'))
Ejemplo n.º 4
0
    def join(route_id):
        """Join the Route"""
        assert isinstance(route_id, ObjectId)
        route = RouteHelper.get(route_id)
        assert route
        assert not EnteredRoute.objects(Q(user=current_user.id) & Q(route=route.id))
        assert route.finished

        new_entered_route = EnteredRoute()
        new_entered_route.user = current_user.id
        new_entered_route.route = route_id
        new_entered_route.save()

        user = UserHelper.get(current_user.id)
        if route_id not in user.entered_routes:
            user.entered_routes.append(route_id)
        user.save()
Ejemplo n.º 5
0
    def delete_route(route_id):
        assert isinstance(route_id, ObjectId)
        route = RouteHelper.get(route_id)
        assert route

        for attach_id in route.attached:
            AttachmentHelper.delete(attach_id)

        f_cate = Category.objects(id=route.father).first()
        f_cate.routes.remove(route.id)
        f_cate.save()

        enters = EnteredRoute.objects(route=route.id)
        for entered_route in enters:
            user = UserHelper.get(entered_route.user)
            user.entered_routes.remove(route.id)
            user.save()
        enters.delete()

        RateInfo.objects(route=route.id).delete()

        route.delete()
Ejemplo n.º 6
0
def route_page(route_id):
    try:
        route_id = ObjectId(route_id)
    except :
        flash('invalid route_id')
        return redirect(url_for('home.home'))
    
    route = RouteHelper.get(route_id)

    route.author = UserHelper.get(route.author)
    route.formatted_time = get_formatted_time(route.create_ts)
    route.stat = RouteHelper.get_route_stat(route.id)
    route.cleaned_content = route.content.read().decode('utf-8')  # TODO: use bleach to sanitise html
    route.my_rate = RouteHelper.get_user_rate(route.id)
    attachs = RouteHelper.get_attachs(route.id)
    joined = route.id in current_user.entered_routes
    finished = RouteHelper.is_route_finished(route.id)

    if not route.finished:
        return redirect(url_for('route.add_attach_page', route_id=route.id))

    return render_template('route-detail.html', route=route, attachs=attachs, joined=joined, finished=finished)
Ejemplo n.º 7
0
def modify_password():
    try:
        assert check_form_para(['old_password', 'new_password', 'new_password_conf'])
        assert UserHelper.verify_password(current_user, request.form['old_password'])
    except AssertionError, e:
        flash(e.message)
Ejemplo n.º 8
0
    return redirect(url_for('home.intro'))


@user_blueprint.route('/register/', methods=['POST'])
def register():
    try:
        check_form_para(['nickname', 'email', 'password', 'password_conf', 'gender'])
        assert request.form['password'] == request.form['password_conf'], u'两次密码输入不一致,请重新输入'
    except AssertionError, e:
        if e.message:
            flash(e.message)
        else :
            flash(u'请输入所有信息')
        return redirect(url_for('home.intro', regis_error=1))

    if UserHelper.get_by_email(request.form['email']) != None:
        flash(u'此邮箱已经被注册,请尝试登录')
        return redirect(url_for('home.intro', login_error=1))

    if len(request.form['nickname']) < 1:
        flash(u'昵称过短,至少需要 1 个字符')
        return redirect(url_for('home.intro', regis_error=1))

    gender = 0 if request.form['gender'] == 'male' else 1

    new_user = UserHelper.create_user(request.form['nickname'], request.form['email'], request.form['password'], gender)

    login_user(new_user)

    return redirect(url_for('home.home'))