Exemple #1
0
    def pay(id):
        order = OrderBiz.get_order_by_id(id)
        if not order:
            return u"订单不存在"
        elif order.status != Order.STATUS.CREATED:
            return u"该订单已付款"

        cuser = UserBiz.get_user_by_id(order.user_id)
        if order.expect_order_price is None:
            return "DatabaseError:Price Format Error"

        if order.expect_order_price > cuser.account:
            return u"账户余额不足"
        else:
            try:
                # 从账户扣钱
                amount = order.expect_order_price
                print amount
                if UserBiz.pay(order.user_id, amount, Transaction.TYPE.PAY, u"用户对订单付款") == REFUND_SUCCESS:
                    order.status = Order.STATUS.PAID
                db_session.add(order)
                db_session.commit()
            except DaixieError as e:
                raise e.get_msg()
        return PAY_ORDER_SUCCESS
Exemple #2
0
def logout():
    '''
    注销
    '''
    try:
        UserBiz.user_logout()
    except DaixieError as e:
        fail(e)
    return redirect(url_for('.index'))
Exemple #3
0
def check_is_activated(id, flash_msg=False):
    try:
        user = UserBiz.get_user_by_id(id)
        ret = UserBiz.check_is_activated(user)
    except DaixieError as e:
        fail(e)
        UserBiz.user_logout()
        return redirect(url_for('.send_activate_email', id=user.id, email=user.email))
    if flash_msg:
        success(ret)
    return redirect(url_for('user.home'))
Exemple #4
0
	def refund(id):
		order = OrderBiz.get_order_by_id(id)
		if not order:
			raise DaixieError(u'订单不存在')
		elif order.status != Order.STATUS.CREATED:
			raise DaixieError(u'该订单已付款')
		try:
			#订单付款失败,偿还从账户中扣除的钱
			amount = int(order.expect_order_price)
			UserBiz.recharge(order.user_id, amount, Transaction.TYPE.REFUND, u'用户付款失败,返回付款金额')
			order.status = Order.STATUS.CREATED
			db_session.add(order)
			db_session.commit()
		except DaixieError as e:
			raise e
Exemple #5
0
def recharge():
    """
	充值
	"""
    stripe.api_key = "sk_test_xPY1IwP3MgiPkMlaV8Q76tgt"

    data_amount = session["data_amount"]
    amount = session["amount"]

    customer = stripe.Customer.create(email=current_user.email, card=request.form["stripeToken"])

    try:
        stripe.Charge.create(customer=customer.id, amount=int(data_amount), currency="usd", description=u"账户充值")
    except stripe.CardError as e:
        raise e
    else:
        try:
            ret = UserBiz.recharge(current_user.id, amount, type=Transaction.TYPE.RECHARGE, description=u"用户充值")
        except DaixieError as e:
            raise e

    success(ret)

    session.pop("data_amount", None)
    session.pop("amount", None)

    return redirect(url_for(".home"))
Exemple #6
0
def send_activate_email(id, email):
    '''
    发送验证邮件
    '''
    try:
        ret = UserBiz.send_activate_email(id, email)
        success(ret)
    except DaixieError as e:
        fail(e)    
    return render_template('general/wait_for_activate.html', id=id, email=email)
Exemple #7
0
	def pay(id):
		order = OrderBiz.get_order_by_id(id)
		if not order:
			raise DaixieError(u'订单不存在')
		elif order.status != Order.STATUS.CREATED:
			raise DaixieError(u'该订单已付款')
		elif order.expect_order_price > current_user.account:
			raise DaixieError(u'账户余额不足')

		try:
			#从账户扣钱
			amount = int(order.expect_order_price)
			UserBiz.refund(order.user_id, amount, Transaction.TYPE.PAY, u'用户对订单进行付款')
			order.status = Order.STATUS.PAID
			db_session.add(order)
			db_session.commit()
		except DaixieError as e:
			OrderBiz.refund(id)
			raise e
		return PAY_ORDER_SUCCESS
Exemple #8
0
def activate():
    '''
    激活账号
    '''

    email = request.args.get('email')
    timestamp = request.args.get('timestamp')
    token = request.args.get('token')
    id = request.args.get('id')

    try:
        UserBiz.check_link(email, timestamp, token)
    except DaixieError as e:
        return render_template('error.html', message=e.message)

    #以下需要根据id从数据库中取出相应的user,并更新activate字段
    user = UserBiz.get_user_by_id(id)
    ret = UserBiz.activate_user(user)

    url = url_for("user.home")
    success(ret)
    return render_template("general/activate_ok.html", url=url)
Exemple #9
0
def profile():
    """
	个人信息
	"""
    form = ProfileForm(obj=current_user)
    if not form.validate_on_submit():
        return render_template("user/setting.html", form=form, nav_profile="active")
    user = current_user
    form.populate_obj(user)
    # 修改个人信息
    try:
        ret = UserBiz.edit_user_profile(user)
        success(ret)
    except DaixieError as e:
        fail(e)
    return redirect(url_for(".profile"))
Exemple #10
0
def register():
    '''
    注册成为普通用户
    '''
    form = RegisterForm()
    if not form.validate_on_submit():
        print form.errors
        return render_template('general/register.html', form=form, nav_register='active')
    user = User(form.email.data, form.passwd.data)

    try:
    	ret = UserBiz.register(user)
    except DaixieError as e:
        fail(e)
    	return render_template('general/register.html', form=form, nav_register='active')        
    success(ret)
    return redirect(url_for('user.profile'))
Exemple #11
0
def profile():
	'''
	个人信息
	'''

	form = ProfileForm(obj=current_user)
	if not form.validate_on_submit():
		return render_template('user/setting.html', cuser= current_user, form=form, nav_profile='active')
	
	user = current_user
	form.populate_obj(user)
	#修改个人信息
	try:
		ret = UserBiz.edit_user_profile(user)
		success(ret)
	except DaixieError as e:
		fail(e)
	return redirect(url_for('.profile'))
Exemple #12
0
def login():
    '''
    登录
    '''
    form = LoginForm()
    if not form.validate_on_submit():
        return render_template('general/login.html', form=form, nav_login='active')
    email = form.email.data
    passwd = form.passwd.data
    #auto = form.auto.data
    auto = True

    user = User(email, passwd)

    try:
        ret = UserBiz.user_login(user, auto)
    except DaixieError as e:
        fail(e)
        return render_template('general/login.html', form=form, nav_login='active')
    success(ret)
    return redirect(url_for('.check_is_activated', id=user.id))
Exemple #13
0
def recharge():
	'''
	Create charge using token.id and return result.
	'''
	amount = float(request.form['amount'])
	data_amount = int(amount*100)
	print data_amount

	customer = stripe.Customer.create(
		email=current_user.email,
		card=request.form['stripeToken']
	)

	try:
		stripe.Charge.create(
			customer=customer.id,
			amount= data_amount,
			currency='usd',
			description=u'账户充值'
			)
	except stripe.CardError as e:
		return render_template('user/recharge_result.html', cuser=current_user, result=e.message)
	except stripe.InvalidRequestError as e:
		print e.message
		return render_template('user/recharge_result.html', cuser=current_user, result=e.message)		
	else:
		try:
			ret = UserBiz.recharge(current_user.id, amount, type=Transaction.TYPE.RECHARGE, description=u'用户充值')
		except DaixieError as e:
			return render_template('user/recharge_result.html', cuser=current_user, result=e)

	success(ret)

	session.pop('data_amount', None)
	session.pop('amount', None)

	return render_template('user/recharge_result.html', cuser=current_user, result=ret)
Exemple #14
0
def load_user(user_id):
    return UserBiz.get_user_by_id(user_id)