예제 #1
0
파일: user.py 프로젝트: CodeBall/Eorzea
def profile(username):
    user = UserService.get_user_by_username(username)
    if not user:
        abort(404)
    categories = CategoryService.get_categories()
    user = UserService.get_user_by_id(user.id)

    active_items = ItemService.get_active_items(user.id)
    active_item_count = len(active_items) if active_items else 0

    success_trade_items = ItemService.get_success_trade_items(user.id)
    success_trade_count = len(
        success_trade_items) if success_trade_items else 0

    trade_item_list = TradeService.get_trades_by_user_is(user.id)
    trade_item_count = len(trade_item_list) if trade_item_list else 0

    if current_user.id == user.id:
        collect_item_list = CollectionService.get_item_list_by_user_id(user.id)
        collect_item_count = len(collect_item_list) if collect_item_list else 0
    else:
        collect_item_count = 0

    return render_template('user/profile.html',
                           user=user,
                           categories=categories,
                           active_item_count=active_item_count,
                           success_trade_count=success_trade_count,
                           trade_item_count=trade_item_count,
                           collect_item_count=collect_item_count)
예제 #2
0
파일: user.py 프로젝트: CodeBall/Eorzea
def report(plaintiff_id, accused_id):
    plaintiff = UserService.get_user_by_id(plaintiff_id)
    if not plaintiff:
        abort(404)
    accused = UserService.get_user_by_id(accused_id)
    if not accused:
        abort(404)

    form = ReportForm()

    report = ReportService.add(plaintiff_id, accused_id, form.reasion.data,
                               form.description.data)

    return redirect(request.referrer)
예제 #3
0
파일: auth.py 프로젝트: CodeBall/Eorzea
def password_reset():
    form = PasswordResetForm()
    if form.validate_on_submit():
        user = UserService.set_password(form.user.id, form.password.data)
        login_user(user)
        return redirect(url_for('index.index'))
    return render_template('auth/password_reset.html', form=form)
예제 #4
0
def item_filter_by_trade(user_id):
    categories = CategoryService.get_categories()
    user = UserService.get_user_by_id(user_id)
    if not user:
        abort(404)
    trade_item_list = TradeService.get_trades_by_user_is(user_id)
    trade_item_ids = [trade_item.item_id for trade_item in trade_item_list]
    items = ItemService.get_items_by_user_id_list(trade_item_ids)
    items = _format_items(items)
    return render_template('index.html', categories=categories, items=items)
예제 #5
0
def item_filter_by_active(active, user_id):
    categories = CategoryService.get_categories()
    user = UserService.get_user_by_id(user_id)
    if not user:
        abort(404)

    if active:
        items = ItemService.get_active_items(user_id)
    else:
        items = ItemService.get_success_trade_items(user_id)

    items = _format_items(items)
    return render_template('index.html', categories=categories, items=items)
예제 #6
0
파일: auth.py 프로젝트: CodeBall/Eorzea
def register():
    categories = CategoryService.get_categories()
    form = RegisterForm()
    if form.validate_on_submit():
        filename = f"images/{uuid.uuid4()}.{form.avatar.data.filename.split('.')[-1]}"
        qiniu.upload_stream(form.avatar.data, filename)
        user = UserService.create_user(form.username.data, form.email.data,
                                       form.password.data, form.telephone.data,
                                       form.sex.data, filename,
                                       form.real_name.data)
        login_user(user)
        return redirect(url_for('index.index'))
    return render_template('auth/register.html',
                           form=form,
                           categories=categories)
예제 #7
0
def _format_items(items):
    for item in items:
        user = UserService.get_user_by_id(item.user_id)
        if user:
            item.user = user

        if item.category_id:
            category = CategoryService.get_category_by_id(item.category_id)
            if category:
                item.category_name = category.name

        trades = TradeService.get_trades_by_item_id(item.id)
        item.trade_count = len(trades) if trades else 0

        collections = CollectionService.get_user_list_by_item_id(item.id)
        item.collection_count = len(collections) if collections else 0

        comments = ItemCommentService.get_comments_by_item_id(item.id)
        item.comment_count = len(comments) if comments else 0

    return items
예제 #8
0
def index():
    categories = CategoryService.get_categories()
    items = ItemService.get_items(limit=10)

    for item in items:
        user = UserService.get_user_by_id(item.user_id)
        if user:
            item.user = user

        if item.category_id:
            category = CategoryService.get_category_by_id(item.category_id)
            if category:
                item.category_name = category.name

        trades = TradeService.get_trades_by_item_id(item.id)
        item.trade_count = len(trades) if trades else 0

        collections = CollectionService.get_user_list_by_item_id(item.id)
        item.collection_count = len(collections) if collections else 0

        comments = ItemCommentService.get_comments_by_item_id(item.id)
        item.comment_count = len(comments) if comments else 0

    return render_template('index.html', categories=categories, items=items)
예제 #9
0
 def validate_username(self, field):
     user = UserService.get_user_by_username(field.data)
     if user:
         raise ValidationError("Username has been used")
예제 #10
0
 def validate_email(self, field):
     user = UserService.get_user_by_email(field.data)
     if user:
         raise ValidationError("Email has been used")
예제 #11
0
 def validate_email(self, field):
     user = UserService.get_user_by_email(field.data)
     if not user:
         raise ValidationError("The mail without registration")
     else:
         self.user = user
예제 #12
0
 def validate_password(self, field):
     user = UserService.verify_password(self.username.data, field.data)
     if user is not None:
         self.user = user
     else:
         raise ValidationError('Username or password is invalid')
예제 #13
0
파일: user.py 프로젝트: CodeBall/Eorzea
def profile_id(user_id):
    user = UserService.get_user_by_id(user_id)
    if not user:
        abort(404)
    return redirect(url_for('user.profile', username=user.username))