示例#1
0
文件: callbacks.py 项目: iugov/s4lbot
def start(update: Update, context: CallbackContext):
    """Called on `/start`. Add/update user and introduce them to the bot."""
    user = update.message.from_user

    with db.connect() as connection:
        user = db.lookup_user(connection, update.message.from_user.id)
        if not user:
            db.add_user(
                connection,
                update.message.from_user,
                timestamp=update.effective_message.date,
            )
        elif user.first_name != update.message.from_user.first_name:
            db.update_user(connection, update.message.from_user, user.id)

    context.bot.send_photo(
        chat_id=update.message.chat_id,
        photo=
        "https://github.com/iugov/s4lbot/blob/develop/images/cover.jpg?raw=true",
    )

    context.bot.send_message(
        chat_id=update.message.chat_id,
        text="{}\n\n{}".format(PROMPTS["welcome"], PROMPTS["alpha"]),
        reply_markup=keyboards.home(),
        parse_mode=telegram.ParseMode.MARKDOWN,
    )
示例#2
0
def change_user():
    text = input("请输入修改用户ID:")
    if text.isdigit():
        mod = input("Please choice your mod [username|age|tel|address]:")
        message = input("Please input your message:")
        db.update_user("update user set %s='%s' where id = '%s'" % (mod, message, text))
    else:
        print("\033[1;31m 输入参数有误\033[0m")
示例#3
0
def change_password():
    if request.method == 'POST':
        form = request.form
        if form.get('password') != form.get('password_confirm'):
            flash(messages.PASSWORDS_NOT_MATCH, 'error')
            return redirect(url_for('accounts.change_password'))
        db.update_user(session.get('user').get('username'), \
            {'password': utils.hash_text(form.get('password'))})
        flash(messages.PASSWORD_UPDATED, 'success')
        return redirect(url_for('admin.index'))
    ctx = {}
    return render_template('accounts/change_password.html', **ctx)
示例#4
0
文件: views.py 项目: ehazlett/tekken
def change_password():
    if request.method == 'POST':
        form = request.form
        if form.get('password') != form.get('password_confirm'):
            flash(messages.PASSWORDS_NOT_MATCH, 'error')
            return redirect(url_for('accounts.change_password'))
        db.update_user(session.get('user').get('username'), \
            {'password': utils.hash_text(form.get('password'))})
        flash(messages.PASSWORD_UPDATED, 'success')
        return redirect(url_for('admin.index'))
    ctx = {}
    return render_template('accounts/change_password.html', **ctx)
示例#5
0
def change_password():
    if request.method == 'POST':
        form = request.form
        username = session.get('user').get('username')
        password = form.get('password')
        if form.get('password') != form.get('password_confirm'):
            flash(messages.PASSWORDS_NOT_MATCH, 'error')
            return redirect(url_for('accounts.change_password'))
        db.update_user(username, {'password': password})
        # reset session
        session['user'] = None
        flash(messages.PASSWORD_UPDATED, 'success')
        return redirect(url_for('index'))
    ctx = {}
    return render_template('accounts/change_password.html', **ctx)
def change_password():
    if request.method == 'POST':
        form = request.form
        username = session.get('user').get('username')
        password = form.get('password')
        if form.get('password') != form.get('password_confirm'):
            flash(messages.PASSWORDS_NOT_MATCH, 'error')
            return redirect(url_for('accounts.change_password'))
        db.update_user(username, {'password': password})
        # reset session
        session['user'] = None
        flash(messages.PASSWORD_UPDATED, 'success')
        return redirect(url_for('index'))
    ctx = {}
    return render_template('accounts/change_password.html', **ctx)
示例#7
0
    def test_update_user(self):
        with db.connect() as connection:
            uid = get_random_id(connection)
            user = User(id=uid, first_name="Augustus", is_bot=False)

            db.add_user(connection, user, datetime.utcnow())

            updated_user = User(id=uid, first_name="Filamentis", is_bot=False)

            db.update_user(connection, updated_user, user.id)

            result = db.lookup_user(connection, user.id)
            self.assertEqual(result.id, updated_user.id)
            self.assertEqual(result.first_name, updated_user.first_name)

            db.delete_user(connection, user.id)
示例#8
0
def newuser():
    """endpoint for setting up a new user"""
    if request.method == 'POST':
        uid = request.form.get('uid')
        name = request.form.get('fullname')
        email = request.form.get('email')
        profile_pic = request.form.get('profile_pic')
        usertype = request.form.get('usertype')
        user = User.get(uid)
        if not user:
            return "User has not given consent to Google Login", 400
        if len(name) > 50:
            return render_template("newuser.html", message="Full name too long", userid=uid, fullname=name,
                               email=email, profile_pic=profile_pic)
        db.update_user(uid, name, email, profile_pic, usertype)
        user = User.get(uid)
        login_user(user)
        return redirect(url_for("index"))
    else:
        return render_template("newuser.html")
示例#9
0
def change_password():
    if request.method == 'POST':
        form = request.form
        username = session.get('user').get('username')
        password = form.get('password')
        if form.get('password') != form.get('password_confirm'):
            flash(messages.PASSWORDS_NOT_MATCH, 'error')
            return redirect(url_for('accounts.change_password'))
        db.update_user(username, {'password': password})
        # update servers
        queue = get_queue()
        t = queue.enqueue(utils.reset_password, args=(username, password),
            result_ttl=30)
        # reset session
        session['user'] = None
        data = {
            'task_id': t.id,
            'task_uri': url_for('admin.view_task', task_id=t.id)
        }
        return generate_api_response(data)
    ctx = {}
    return render_template('accounts/change_password.html', **ctx)
示例#10
0
def change_password():
    if request.method == 'POST':
        form = request.form
        username = session.get('user').get('username')
        password = form.get('password')
        if form.get('password') != form.get('password_confirm'):
            flash(messages.PASSWORDS_NOT_MATCH, 'error')
            return redirect(url_for('accounts.change_password'))
        db.update_user(username, {'password': password})
        # update servers
        queue = get_queue()
        t = queue.enqueue(utils.reset_password,
                          args=(username, password),
                          result_ttl=30)
        # reset session
        session['user'] = None
        data = {
            'task_id': t.id,
            'task_uri': url_for('admin.view_task', task_id=t.id)
        }
        return generate_api_response(data)
    ctx = {}
    return render_template('accounts/change_password.html', **ctx)
示例#11
0
def change_user(users):
    text = int(input("请输入修改用户ID:"))
    mod = input("Please choice your mod [username|age|tel|address]:")
    message = input("Please input your message:")
    db.update_user("update user set %s='%s' where id = '%s'" %
                   (mod, message, text))
示例#12
0
 def update(self):
     db.update_user(self)