示例#1
0
文件: bot.py 项目: nickmi11er/sclbot
def choose_gp(bt, update):
    private = private_chat(update.message.chat)
    # keyboard = kb.groups_kb(groups, private)

    institutes = scl_manager.institutes()
    inst_kb = kb.inst_kb(institutes, private)

    if private:
        user = data_manager.get_user(update.message.from_user.id)
    else:
        user = data_manager.get_user(update.message.chat.id)
    bot.reply(
        update, u'Ваша текущая группа: {}\nВыберите учебную группу'.format(
            user['group_name']), inst_kb)
示例#2
0
文件: bot.py 项目: nickmi11er/sclbot
def start(bt, update):
    log_bot_request(update.message, 'Start')
    private = private_chat(update.message.chat)
    if private:
        user = data_manager.get_user(update.message.from_user.id)
    else:
        user = data_manager.get_user(update.message.chat.id)

    if user:
        keyboard = kb.menu_kb()
        bt.send_message(chat_id=update.message.chat_id,
                        text='Выберите команду',
                        reply_markup=keyboard)
    else:
        _welcome(bt, update, private)
示例#3
0
def login():
    login_value = request.form
    user_data = data_manager.get_user(login_value.get(LOGIN))
    if bcrypt.checkpw(login_value.get(PASSWORD).encode('utf-8'), user_data[PASSWORD].encode('utf-8')):
        session[USER_ID] = user_data[USER_ID]
        return redirect(url_for(MAIN_PAGE))
    return render_template('login.html')
示例#4
0
def load_user(user_id):
    user = data_manager.get_user(user_id)
    if user:
        User = data_manager.User(user)
        return User
    else:
        return None
示例#5
0
def user_page(user_id):
    if 'id' not in session:
        return redirect(url_for('route_main'))
    user = data_manager.get_user(user_id)
    questions = data_manager.get_data_by_user_id('question', user_id)
    answers = data_manager.get_data_by_user_id('answer', user_id)
    comments = data_manager.get_data_by_user_id('comment', user_id)
    return render_template('user_page.html', user=user[0], questions=questions, answers=answers, comments=comments)
示例#6
0
文件: user.py 项目: nickmi11er/sclbot
 def _fetch_by_id(tg_user_id):
     user = User()
     user_entity = dm.get_user(tg_user_id)
     if user_entity:
         user._map(user_entity)
         cache.set(user.tg_user_id, user)
         return user
     else:
         return None
示例#7
0
def login_user(username, password):
    if username == "" or password == "":
        return False

    user_data = data_manager.get_user(username)
    if user_data:
        if pass_service.verify_password(password, user_data['password']):
            return user_data
    else:
        return False
示例#8
0
def register():
    login = request.form.get(LOGIN)
    password = request.form.get(PASSWORD)
    confirmation = request.form.get(CONF_PASSWORD)
    if confirmation != password or data_manager.get_user(login) != None:
        return redirect(url_for(MAIN_PAGE))
    else:
        hashed_pass = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt(8))
        data_manager.add_to_database(login, hashed_pass.decode('utf-8'))
        return redirect(url_for(MAIN_PAGE))
示例#9
0
def login():
    if request.method == "GET":
        return render_template('register_login.html', type="login")
    elif request.method == "POST":
        username = request.form["username"]
        password = request.form["password"]
        if data_manager.get_user(username, password):
            session["username"] = username
            return redirect('/')
        message = "Invalid username or password"
        return render_template('register_login.html', type="login", message=message)
示例#10
0
文件: bot.py 项目: nickmi11er/sclbot
def echo(bt, upd):
    log_bot_request(upd.message, 'Echo')
    usr = data_manager.get_user(upd.message.from_user.id)
    if usr and usr['role'] == 1 or usr[
            'role'] == 3:  # 1 - admin, 3 - group master
        msg = bt.send_message(
            chat_id=upd.message.chat_id,
            text=
            'Хорошо! Для того чтобы отправить сообщение моим пользователям, отправь его мне в ответном сообщении.'
        )
        bot.listen_for_message(upd.message.chat_id, msg.message_id)
示例#11
0
def registration():
    if request.method == 'GET':
        return render_template('register.html')
    if request.form.get('password') != request.form.get('confirm-password'):
        return render_template(
            'register.html',
            error="Password and Confirm password doesn't match!")
    password = util.hash_password(request.form.get('password'))
    username = request.form.get('username')
    if data_manager.get_user(username):
        return render_template('register.html',
                               error='This username already exists!')
    user = data_manager.create_user(username, password)
    if user is False:
        return render_template('register.html',
                               error='This username already exists!')
    return redirect(url_for('login'))
示例#12
0
文件: server.py 项目: Conalau/AskMate
def login():
    if request.method == "POST":
        result = data_manager.get_user(request.form['username'])
        if result == None:
            return render_template('login.html', status='not_ok')
        elif len(result) > 0:
            password = result['password']
            username = result['user_name']
            check = ph.verify_password(request.form['password'], password)
            if check == True:
                session['logged_in'] = True
                session['username'] = username
                temp_dict = data_manager.get_user_id_from_username(username)
                session['user_id'] = temp_dict['id']
                return redirect(url_for('display_q'))
            elif check == False:
                return render_template('login.html', status='not_ok')

    return render_template('login.html')
示例#13
0
def index():
    if request.method == "POST":
        username = request.form.get('username')
        player_score = int(request.form.get('score'))
        if not data_manager.get_user(username):
            data_manager.create_user(username, player_score)
        else:
            current_highscore = data_manager.get_user_highscore(username)
            if player_score > current_highscore['high_score']:
                data_manager.write_new_highscore(username, player_score)

        all_high_scores = data_manager.get_highscores()
        return render_template('user-death.html',
                               users=all_high_scores,
                               username=username,
                               new_highscore=player_score)

    all_high_scores = data_manager.get_highscores()
    return render_template('index.html', users=all_high_scores)
示例#14
0
def login():
    if request.method == 'POST':
        user_data = request.form.to_dict()
        username = user_data['username']
        if username in data_manager.get_users_list():
            user = data_manager.get_user(username)
            if bcrypt.checkpw(
                    user_data['password'].encode('utf-8'),
                    data_manager.get_hashed_password(username).encode(
                        'utf-8')):
                session_id = bcrypt.gensalt().decode('utf-8')
                session['session_id'] = session_id
                session['user_id'] = user['id']
                session['role'] = user['role']
                data_manager.save_session(username, session_id)
                return redirect(url_for('index'))
            else:
                render_template("login.html")
        else:
            render_template("login.html")
    else:
        return render_template("login.html")
示例#15
0
文件: bot.py 项目: nickmi11er/sclbot
def check_permission(user_id):
    user = data_manager.get_user(user_id)
    return user and user[3] == 1