Beispiel #1
0
def tradeAction(request, *args, **kwargs):
    """Query trade status."""
    initParam = {}
    user_id = string.atoi(kwargs.get('user_id'))
    app_id = kwargs.get('app_id')
    action = kwargs.get('action')
    if 'sell' == action and user_id == request.user.id:
        transaction = get_object_or_404(models.Transaction,
                                        app_id=app_id,
                                        seller_id=user_id,
                                        is_active=True)
    elif 'buy' == action and user_id == request.user.id:
        transaction = get_object_or_404(models.Transaction,
                                        app_id=app_id,
                                        buyer_id=user_id)
        if transaction.status == 2:
            token = common.getToken(key='token_length', default=30)
            initParam['pay_url'] = '/'.join([
                common.getHttpHeader(request), 'transaction/buyer-pay',
                str(app_id),
                str(transaction.id), token
            ])
    else:
        raise Http404

    support_user = common.getSystemParam(key='support_user',
                                         default='appswalk')
    support_users = models.User.objects.filter(username=support_user)
    if support_users:
        initParam['support_user'] = support_users[0]
    else:
        log.error(_('Support user account does not exist.'))

    initParam['transaction'] = transaction
    if transaction.status == 2 or transaction.status == 3:
        if transaction.end_time > datetime.datetime.now():
            initParam['time_remaining'] = time.mktime(
                time.strptime(
                    transaction.end_time.strftime('%Y-%m-%d %H:%M:%S'),
                    '%Y-%m-%d %H:%M:%S'))
        else:
            initParam['time_remaining'] = "Deal Closed"
            initParam['paid_expiry'] = True
        if tradeOperation(request,
                          transaction=transaction,
                          initParam=initParam):
            return redirect(request.path)
    elif transaction.status == 4:
        initParam['time_remaining'] = common.dateBefore(transaction.end_time)

        initParam['seller_txn'] = creditViews.getAppraisement(
            user_id=transaction.seller.id, txn_id=transaction.id)
        initParam['buyer_txn'] = creditViews.getAppraisement(
            user_id=transaction.buyer.id, txn_id=transaction.id)
        if creditViews.createAppraisement(request, initParam=initParam):
            return redirect(request.path)

    return render_to_response('transaction/trade_action.html',
                              initParam,
                              context_instance=RequestContext(request))
Beispiel #2
0
def sendSecurityVerificationEmail(request, *args, **kwargs):
    """After user update email in security setting, send the email verification link to the new email."""
    user = kwargs.get('user')
    templates = models.NotificationTemplate.objects.filter(name='email_security_verification')
    if user and templates:
        massEmailThread = email.MassEmailThread()
        link_header = common.getHttpHeader(request)
        token = common.getToken(key='token_length', default=30)
        active_link = '/'.join([link_header, 'usersetting', user.username, 'emails', str(user.id),
                                'email-security-verification', token])
        subject = templates[0].subject
        message = templates[0].template.replace('{param1}', user.username).replace('{param2}', active_link)
        massEmailThread.addEmailData(subject=subject, message=message, recipient_list=[user.email])
        massEmailThread.start()
    return None
Beispiel #3
0
def sendResetPasswordEmail(request, *args, **kwargs):
    """Send the email of reset password."""
    user = kwargs.get('user')
    type = kwargs.get('type')
    templates = models.NotificationTemplate.objects.filter(name='reset_password_email')
    if user and type and templates:
        massEmailThread = email.MassEmailThread()
        header = common.getHttpHeader(request)
        token = common.getToken(key='token_length', default=30)
        url = '/'.join([header, 'usersetting/reset-password', str(type), str(user.id), user.username, token])
        subject = templates[0].subject
        message = templates[0].template.replace('{param1}', user.username).replace('{param2}', url)
        massEmailThread.addEmailData(subject=subject, message=message, recipient_list=[user.email])
        massEmailThread.start()
    return None
Beispiel #4
0
def sendRegisterActiveEmail(request, *args, **kwargs):
    """After user register, send the account active link to his email."""
    user = kwargs.get('user')
    templates = models.NotificationTemplate.objects.filter(name='register_active')
    if user and templates:
        massEmailThread = email.MassEmailThread()
        link_header = common.getHttpHeader(request)
        token = common.getToken(key='token_length', default=30)
        active_link = '/'.join([link_header, 'usersetting', user.username, 'emails', str(user.id),
                                'register-confirm-verification', token])
        subject = templates[0].subject
        message = templates[0].template.replace('{param1}', user.username).replace('{param2}', active_link)
        massEmailThread.addEmailData(subject=subject, message=message, recipient_list=[user.email])
        massEmailThread.start()
    return None
Beispiel #5
0
def tradeAction(request, *args, **kwargs):
    """Query trade status."""
    initParam = {}
    user_id = string.atoi(kwargs.get('user_id'))
    app_id = kwargs.get('app_id')
    action = kwargs.get('action')
    if 'sell' == action and user_id == request.user.id:
        transaction = get_object_or_404(models.Transaction, app_id=app_id, seller_id=user_id, is_active=True)
    elif 'buy' == action and user_id == request.user.id:
        transaction = get_object_or_404(models.Transaction, app_id=app_id, buyer_id=user_id)
        if transaction.status == 2:
            token = common.getToken(key='token_length', default=30)
            initParam['pay_url'] = '/'.join([common.getHttpHeader(request), 'transaction/buyer-pay', str(app_id), str(transaction.id), token])
    else:
        raise Http404

    support_user = common.getSystemParam(key='support_user', default='appswalk')
    support_users = models.User.objects.filter(username=support_user)
    if support_users:
        initParam['support_user'] = support_users[0]
    else:
        log.error(_('Support user account does not exist.'))

    initParam['transaction'] = transaction
    if transaction.status == 2 or transaction.status == 3:
        if transaction.end_time > datetime.datetime.now():
            initParam['time_remaining'] = time.mktime(time.strptime(transaction.end_time.strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S'))
        else:
            initParam['time_remaining'] = "Deal Closed"
            initParam['paid_expiry'] = True
        if tradeOperation(request, transaction=transaction, initParam=initParam):
            return redirect(request.path)
    elif transaction.status == 4:
        initParam['time_remaining'] = common.dateBefore(transaction.end_time)

        initParam['seller_txn'] = creditViews.getAppraisement(user_id=transaction.seller.id, txn_id=transaction.id)
        initParam['buyer_txn'] = creditViews.getAppraisement(user_id=transaction.buyer.id, txn_id=transaction.id)
        if creditViews.createAppraisement(request, initParam=initParam):
            return redirect(request.path)

    return render_to_response('transaction/trade_action.html', initParam, context_instance=RequestContext(request))
Beispiel #6
0
def sendSecurityVerificationEmail(request, *args, **kwargs):
    """After user update email in security setting, send the email verification link to the new email."""
    user = kwargs.get('user')
    templates = models.NotificationTemplate.objects.filter(
        name='email_security_verification')
    if user and templates:
        massEmailThread = email.MassEmailThread()
        link_header = common.getHttpHeader(request)
        token = common.getToken(key='token_length', default=30)
        active_link = '/'.join([
            link_header, 'usersetting', user.username, 'emails',
            str(user.id), 'email-security-verification', token
        ])
        subject = templates[0].subject
        message = templates[0].template.replace('{param1}',
                                                user.username).replace(
                                                    '{param2}', active_link)
        massEmailThread.addEmailData(subject=subject,
                                     message=message,
                                     recipient_list=[user.email])
        massEmailThread.start()
    return None
Beispiel #7
0
def sendRegisterActiveEmail(request, *args, **kwargs):
    """After user register, send the account active link to his email."""
    user = kwargs.get('user')
    templates = models.NotificationTemplate.objects.filter(
        name='register_active')
    if user and templates:
        massEmailThread = email.MassEmailThread()
        link_header = common.getHttpHeader(request)
        token = common.getToken(key='token_length', default=30)
        active_link = '/'.join([
            link_header, 'usersetting', user.username, 'emails',
            str(user.id), 'register-confirm-verification', token
        ])
        subject = templates[0].subject
        message = templates[0].template.replace('{param1}',
                                                user.username).replace(
                                                    '{param2}', active_link)
        massEmailThread.addEmailData(subject=subject,
                                     message=message,
                                     recipient_list=[user.email])
        massEmailThread.start()
    return None
Beispiel #8
0
def sendResetPasswordEmail(request, *args, **kwargs):
    """Send the email of reset password."""
    user = kwargs.get('user')
    type = kwargs.get('type')
    templates = models.NotificationTemplate.objects.filter(
        name='reset_password_email')
    if user and type and templates:
        massEmailThread = email.MassEmailThread()
        header = common.getHttpHeader(request)
        token = common.getToken(key='token_length', default=30)
        url = '/'.join([
            header, 'usersetting/reset-password',
            str(type),
            str(user.id), user.username, token
        ])
        subject = templates[0].subject
        message = templates[0].template.replace('{param1}',
                                                user.username).replace(
                                                    '{param2}', url)
        massEmailThread.addEmailData(subject=subject,
                                     message=message,
                                     recipient_list=[user.email])
        massEmailThread.start()
    return None