Exemple #1
0
	def register_by_email(nickname, account, secret):
		with db.auto_commit():
			user = User()
			user.nickname = nickname
			user.email = account
			user.password = secret
			db.session.add(user)
Exemple #2
0
def redraw_from_wish(isbn):
    wish = Wish.query.filter_by(isbn=isbn, launched=False).first_or_404()

    with db.auto_commit():
        wish.delete()

    return redirect(url_for('web.my_wish'))
Exemple #3
0
def reject_drift(did):
    with db.auto_commit():
        drift = Drift.query.filter(Gift.uid == current_user.id,
                                   Drift.id == did).first_or_404()
        drift.pending = PendingStatus.Reject
        requester = User.query.get_or_404(drift.requester_id)
        requester.beans += 1
    return redirect(url_for('web.pending'))
Exemple #4
0
def redraw_drift(did):
    with db.auto_commit():
        # requester_id=current_user.id 防止超权现象
        drift = Drift.query.filter_by(
            id=did, requester_id=current_user.id).first_or_404()
        drift.pending = PendingStatus.Redraw
        current_user.beans += 1

    return redirect(url_for('web.pending'))
Exemple #5
0
def redraw_drift(did):
    # 超权
    # uid:1 did:1
    # uid:2 did:2
    # uid==1,修改did==2,就是超权
    with db.auto_commit():
        drift = Drift.query.filter_by(
            requester_id=current_user.id, id=did).first_or_404()
        drift.pending = PendingStatus.Redraw
        current_user.beans += 1
    return redirect(url_for('web.pending'))
Exemple #6
0
def register():
    # request.form
    form = RegisterForm(request.form)
    if request.method == 'POST' and form.validate():
        with db.auto_commit():
            user = User()
            user.set_attrs(form.data)
            db.session.add(user)
        # db.session.commit()
        return redirect(url_for('web.login'))
    return render_template('auth/register.html', form=form)
Exemple #7
0
 def reset_password(token, new_password):
     s = Serializer(current_app.config['SECRET_KEY'])
     try:
         data = s.loads(token.encode('utf-8'))
     except:
         return False
     uid = data.get('id')
     with db.auto_commit():
         user = User.query.get(uid)
         user.password = new_password
     return True
Exemple #8
0
def redraw_from_gifts(gid):
    gift = Gift.query.filter_by(id=gid, launched=False).first_or_404()
    drift = Drift.query.filter_by(
        gift_id=gid, pending=PendingStatus.Waiting).first()
    if drift:
        flash('这个礼物处于交易状态,请先前往鱼漂完成改交易的')
    else:
        with db.auto_commit():
            current_user.beans -= current_app.config['BEANS_UPLOAD_ONE_BOOK']
            gift.delete()
    return redirect(url_for('web.my_gifts'))
Exemple #9
0
def save_to_wish(isbn):
    if current_user.can_save_to_list(isbn):
        with db.auto_commit():
            wish = Wish()
            wish.isbn = isbn
            wish.uid = current_user.id

            db.session.add(wish)
    else:
        flash("这本书以添加进您的赠送清单或已经存在于您的心愿清单,请不要重复添加")
    return redirect(url_for('web.book_detail', isbn=isbn))
Exemple #10
0
	def save_address(self, address_info):
		with db.auto_commit():
			address = UserAddress.query.filter_by(user_id=self.id).first()
			if not address:
				address = UserAddress()
			address.user_id = self.id
			address.name = address_info.name
			address.mobile = address_info.mobile
			address.province = address_info.province
			address.city = address_info.city
			address.country = address_info.country
			address.detail = address_info.detail
			db.session.add(address)
Exemple #11
0
def save_to_gifts(isbn):
    if current_user.can_save_to_list(isbn):
        with db.auto_commit():
            gift = Gift()
            gift.isbn = isbn
            gift.uid = current_user.id

            current_user.beans += current_app.config['BEANS_UPLOAD_ONE_BOOK']

            db.session.add(gift)
    else:
        flash("这本书以添加进您的赠送清单或已经存在于您的心愿清单,请不要重复添加")
    return redirect(url_for('web.book_detail', isbn=isbn))
Exemple #12
0
def mailed_drift(did):
    with db.auto_commit():
        drift = Drift.query.filter_by(gifter_id=current_user.id, id=did).first_or_404()
        drift.pending = PendingStatus.Success
        current_user.beans += 1

        # 礼物是否赠送成功
        gift = Gift.query.filter_by(id=drift.gift_id).first_or_404()
        gift.launched = True

        # 心愿是否完成
        Wish.query.filter_by(isbn=drift.isbn, uid=drift.requester_id,
                             launched=False).update({Wish.launched: True})
        return redirect(url_for('web.pending'))
Exemple #13
0
def save_to_gifts(isbn):
    if current_user.can_save_to_list(isbn):
        # 事务,保证user和gift的一致性,rollback
        # try:
        with db.auto_commit():
            gift = Gift()
            gift.isbn = isbn
            gift.uid = current_user.id
            #################################################
            current_user.beans += current_app.config['BEANS_UPLOAD_ONE_BOOK']
            db.session.add(gift)
            # db.session.commit()
        # except Exception as e:
        #     db.session.rollback()
        #     raise e
    else:
        flash('这本书已经添加至你的赠送清单或者一存在于你的心愿清单,请不要重复添加')
    return redirect('web.book_detail', isbn=isbn)
Exemple #14
0
def mailed_drift(did):
    with db.auto_commit():
        # 更改鱼漂状态位成功
        drift = Drift.query.filter_by(
            id=did, gifter_id=current_user.id).first_or_404()
        drift.pending = PendingStatus.Success

        # 赠送一个鱼豆
        current_user.beans += 1

        # 完成赠送
        gift = Gift.query.get_or_404(drift.gift_id)
        gift.launched = True

        # 完成心愿
        Wish.query.filter_by(
            isbn=drift.isbn, uid=drift.requester_id, launched=False)\
            .update({Wish.launched: True})
    return redirect(url_for('web.pending'))
Exemple #15
0
def save_drift(drift_form, current_gift):
    with db.auto_commit():
        drift = Drift()
        # drift.message = drift_form.message.data
        drift_form.populate_obj(drift)

        drift.gift_id = current_gift.id
        drift.requester_id = current_user.id
        drift.requester_nickname = current_user.nickname
        drift.gifter_id = current_gift.user.id
        drift.gifter_nickname = current_gift.user.nickname

        book = BookViewModel(current_gift.book)
        drift.isbn = book.isbn
        drift.book_title = book.title
        drift.book_author = book.author
        drift.book_img = book.image

        current_user.beans -= 1

        db.session.add(drift)
Exemple #16
0
def save_drift(drift_form, current_gift):
    if current_user.beans < 1:
        # TODO 自定义异常
        raise Exception()

    with db.auto_commit():
        drift = Drift()
        drift_form.populate_obj(drift)

        drift.gift_id = current_gift.id
        drift.requester_id = current_user.id
        drift.requester_nickname = current_user.nickname
        drift.gifter_nickname = current_gift.user.nickname
        drift.gifter_id = current_gift.user.id

        book = BookViewModel(current_gift.book)
        drift.book_title = book.title
        drift.book_author = book.author
        drift.book_img = book.image
        drift.isbn = book.isbn

        db.session.add(drift)

        current_user.beans -= 1
Exemple #17
0
 def get_one_order(oid):
     with db.auto_commit():
         return Order.query.filter_by(order_no=oid).first_or_404()
Exemple #18
0
def dispose_order():
    order_id = request.args.get('order_id')
    with db.auto_commit():
        order = Order.query.filter_by(order_id=order_id).first()
        db.session.delete(order)
    return redirect(url_for('admin.manage_order'))
Exemple #19
0
 def register_by_wx(account):
     with db.auto_commit():
         user = User()
         user.openid = account
         db.session.add(user)
     return User.query.filter_by(openid=account).first()
Exemple #20
0
 def save_likes(post_id):
     with db.auto_commit():
         likes = Likes()
         likes.user_id = g.user.uid
         likes.post_id = post_id
         db.session.add(likes)
Exemple #21
0
def redraw_from_wish(isbn):
    wish = Wish.query.filter_by(isbn=isbn, launched=False).first_or_404()
    with db.auto_commit():
        wish.delete()
    return redirect(url_for('web.my_wish'))
 def create_user(user_id):
     with db.auto_commit():
         new_user = User(user_id=user_id)
         db.session.add(new_user)
     return 'create user success'
Exemple #23
0
 def set_is_new_false(cls,task_id):
     cases = Case.query.filter_by(task_id=task_id,is_new=True).all()
     for c in cases:
         c.is_new = False
         with db.auto_commit():
             db.session.add(c)
Exemple #24
0
 def register(openid):
     user = User()
     with db.auto_commit():
         user.openid = openid
         db.session.add(user)
     return user
Exemple #25
0
 def pause_job(self):
     scheduler.pause_job(self.scheduler_id)
     with db.auto_commit():
         self.running_state = 0
Exemple #26
0
def delete_seek_help(id):
    """删除 id=id 的 SeekHelp"""
    obj_seek_help = SeekHelp.query.filter_by(id=id).first_or_404()
    with db.auto_commit():
        obj_seek_help.delete()
    return DeleteSuccess()
Exemple #27
0
def delete_assignment(aid):
    assignment = Assignment.query.get_or_404(aid)
    with db.auto_commit():
        delete_file(assignment)
        db.session.delete(assignment)
    return DeleteSuccess()
Exemple #28
0
 def update_votelist_status(vl_id):
     with db.auto_commit():
         vote = Votelist.query.filter(Votelist.vl_id == vl_id).first()
         vote.votestatus = 1
Exemple #29
0
Fichier : user.py Projet : GoldL/ji
def super_delete_user():
    with db.auto_commit():
        form = UserIdForm().validate_for_api()
        user = User.query.filter_by(id=form.user_id.data).first_or_404()
        user.delete()
    return DeleteSuccess()
Exemple #30
0
	def register_by_wx(account):
		with db.auto_commit():
			user = User()
			user.openid = account
			db.session.add(user)
		return User.query.filter_by(openid=account).first()
Exemple #31
0
 def add_scheduler(self):
     with db.auto_commit():
         db.session.add(self)
     with db.auto_commit():
         self.create_scheduler_id()
Exemple #32
0
 def __add_log(self):
     self.ip = request.remote_addr
     self.user_id = current_user.id
     with db.auto_commit():
         db.session.add(self)
Exemple #33
0
 def __add_log(self,id):
     self.admin_id=id
     self.ip=request.remote_addr
     with db.auto_commit():
         db.session.add(self)
Exemple #34
0
def delete_user():
    uid = g.voter.uid
    with db.auto_commit():
        user = Voter.query.filter_by(id=uid).first_or_404(msg='mei zhao dao')
        user.delete()
    return DeleteSuccess()
Exemple #35
0
from app import create_app
from app.models.base import db
from app.models.user import User
'''离线造数据脚本'''
app = create_app()
with app.app_context():
    with db.auto_commit():
        # 创建一个超级管理员
        user = User()
        user.nickname = 'Super'
        user.password = '******'
        user.email = '*****@*****.**'
        user.auth = 2
        db.session.add(user)
Exemple #36
0
 def del_cart(uid, cart_ids):
     for cart_id in cart_ids:
         with db.auto_commit():
             cart = Cart.query.filter(
                 and_(Cart.uid == uid, Cart.id == cart_id)).first()
             db.session.delete(cart)
Exemple #37
0
def super_delete_user():
    uid = g.user.uid
    with db.auto_commit():
        user = User.query.filter_by(id=uid).first_or_404()
        user.delete()
    return DeleteSuccess()
Exemple #38
0
 def register_by_email(nickname, account, secret):
     """手机号注册"""
     with db.auto_commit():
         user = User(nickname=nickname, mobile=account, password=secret)
         db.session.add(user)
     return user
Exemple #39
0
def super_delete_user(uid):
    with db.auto_commit():
        # 取代user = User.query.get_or_404(uid),即使删除了还是能查到
        user = User.query.filter_by(id=uid).first_or_404()
        user.delete()
    return DeleteSuccess()
Exemple #40
0
 def register_by_wx_mina(account):
     """小程序注册"""
     with db.auto_commit():
         user = User(openid=account)
         db.session.add(user)
     return user
Exemple #41
0
def redraw_from_wish(isbn):
    wish = Wish.query.filter_by(isbn=isbn).first_or_404()
    with db.auto_commit():
        current_user.beans -= current_app.config['BEANS_UPLOAD_ONE_BOOK']
        wish.delete()
    return redirect(url_for('web.my_gifts'))
Exemple #42
0
def food_cat_data():
    with app.app_context():
        with db.auto_commit():
            food_cat = FoodCat()
            food_cat.name = ''
Exemple #43
0
def modify_password(username, password):
    user = get_user_by_username(username)
    with db.auto_commit():
        user.password = password
Exemple #44
0
 def change_password(self, newPassword):
     with db.auto_commit():
         # 数据库的改操作,可以直接改了提交. 插入才需要add进会话
         self.password = newPassword
     return True
Exemple #45
0
Fichier : user.py Projet : GoldL/ji
def super_active_user():
    form = UserIdForm().validate_for_api()
    with db.auto_commit():
        User.query.filter_original(id=form.user_id.data).update(
            {User.status: 1})
    return Success(msg='用户已恢复!')
Exemple #46
0
def redraw_drift(did):
    with db.auto_commit():
        drift = Drift.query.filter_by(requester_id == current_user.id,id = did).first_or_404()
        deft.pending = PendingStatus.Redraw
        current_user.coins += 1
    return redirect(url_for('web.pending'))
Exemple #47
0
# _*_ coding: utf-8 _*_
"""
  Created by Alimazing on 2018/5/12.
"""
from app import create_app

__author__ = 'Alimazing'
from app.models.base import db
from app.models.user import User

app = create_app()
with app.app_context():
    with db.auto_commit():
        # 创建一个超级管理员
        user = User()
        user.email = '*****@*****.**'
        user.nickname = 'Super'
        user.auth = 2
        user.password = '******'
        db.session.add(user)
Exemple #48
0
 def delete_scheduler(self):
     scheduler = Scheduler.query.filter_by(
         scheduler_id=self.scheduler_id).first_or_404()
     with db.auto_commit():
         scheduler.delete()