예제 #1
0
def adminPoolAddPlayer():
    if getUserName() == None:
        return redirect(url_for('login'))

    form = PoolAddPlayer(request.form)
    if form.validate() is False:
        return redirect(url_for('do_error', messages="player does not exists"))

    current_admin_pool = getCurrentAdminPool()

    if 'current_admin_pool_id' in session:
        newPassword = None
        player = Player.query.filter_by(email=form.email.data.lower()).first()
        if player is None:
            newPassword = str(uuid.uuid4().get_hex().upper()[0:6])
            player = Player(
                email=form.email.data.lower(),
                password=bcrypt.generate_password_hash(newPassword))
            db.session.add(player)
            db.session.commit()
            db.session.flush

        poolPlayer = PoolPlayer(pool_id=session['current_admin_pool_id'],
                                nickName=form.nickName.data,
                                player_id=player.id)
        if poolPlayer.id is not None:
            flash('Playe with email=%s alread exists in pool' % player.email)
        else:
            db.session.add(poolPlayer)
        db.session.commit()

        #send email
        if newPassword:
            send_email(subject='FootBall Pool Invitation',
                       sender='*****@*****.**',
                       recipients=player.email,
                       text_body=render_template(
                           'email-pool-invite.txt',
                           commissioner_name=current_user.name(),
                           player_name=player.name(),
                           pool_name=current_admin_pool['name'],
                           password=newPassword),
                       html_body='')
        else:
            send_email(subject='FootBall Pool Invitation',
                       sender='*****@*****.**',
                       recipients=player.email,
                       text_body=render_template(
                           'email-pool-invite.txt',
                           commissioner_name=current_user.name(),
                           player_name=player.name(),
                           pool_name=current_admin_pool['name'],
                           password=None),
                       html_body='')

        return redirect(url_for('adminPool'))

    else:
        return redirect(url_for('do_error', messages='No curent pool id'))
예제 #2
0
def connect():
    current_user.set_sid(request.sid)
    print(current_user.name(), "connected")
    latest_room = current_user.latest_room()
    if latest_room:
        current_user.join_room(latest_room)
    else:
        current_user.join_room(current_user.token().room())
예제 #3
0
def porbill():
    if request.method == 'POST':
        loop1 = [1]
        buydict = request.cookies.get('buydict')
        allmoney = 0
        if buydict is None:
            buyinfo = []
        else:
            buydict = ast.literal_eval(str(buydict))
            buyinfo = []
            for x in buydict:
                title = Product.getdata(
                    str(x).rsplit('-', 1)[0]).get('orderdict')[int(
                        str(x).rsplit('-', 1)[1])].get('name')
                price = Product.getdata(
                    str(x).rsplit('-', 1)[0]).get('orderdict')[int(
                        str(x).rsplit('-', 1)[1])].get('cost')
                url = Product.getdata(str(x).rsplit('-', 1)[0]).get('url')
                tid = Product.getdata(str(x).rsplit(
                    '-',
                    1)[0]).get('orderdict')[int(str(x).rsplit('-',
                                                              1)[1])].get('id')
                much = int(buydict.get(x))
                price = int(price)
                tempinfo = [title, price, much]
                buyinfo.append(tempinfo)
                allmoney = allmoney + (price * much)
                if Product.ticupdate(url, tid, much) == 'NoTic':
                    return render_template('err_tic.html', **locals())

                Product.ticadd(tid, url, title, current_user.name(),
                               current_user.info().get('phone'),
                               current_user.email(), much, int(price * much))
            loginform = loginForm()
            pform = productForm()
        response = make_response(
            render_template('proinfo-shop03.html', **locals()))
        response.set_cookie('num', '', expires=0)
        response.set_cookie('buydict', '', expires=0)
        return response
예제 #4
0
def submitpro():
    loginform = loginForm()
    form = submitclassinfo()
    if request.method == 'GET':
        return render_template('lesson.html', **locals())
    elif request.method == 'POST' and form.validate_on_submit() and len(
            list(filter(None, request.form.getlist('ticket[]')))) >= 3:
        address = form.address.data
        link = form.link.data
        flavor = form.organize.data
        organize = current_user.name()
        daterange = form.daterange.data
        labout = form.labout.data
        cover = url_for('serve_picture',
                        sha1=uploadcover(base64.b64decode(
                            form.cover.data[23:])))
        name = form.name.data
        name_pinyin = p.get_pinyin(str(name)).replace('-',
                                                      '').replace(' ',
                                                                  '')[0:14]
        url = str(
            datetime.datetime.now().strftime('%y%m%d%H%M')) + '-' + name_pinyin
        content = form.content.data
        ticket = request.form.getlist('ticket[]')
        count = 0
        dticket = []
        for x, y, z in zip(ticket[0::3], ticket[1::3], ticket[2::3]):
            dtickettemp = {"id": count, "name": x, "cost": y, "much": z}
            count = count + 1
            dticket.append(dtickettemp)
        Product.init(False, current_user.email(), url, False, name, labout,
                     cover, daterange, address, link, flavor, organize,
                     content, "noproddata", dticket)
        return redirect(url_for('classrom.showverinfo'))

    else:
        """偷懶debug區"""
        """不要送任何可以測資讓認證可過即可直接測試"""
        return render_template('reg_err.html', **locals())
예제 #5
0
def disconnect():
    for room in current_user.rooms():
        current_user.leave_room(room)
    print(current_user.name(), "disconnected")
    logout_user()