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)
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)
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')
def load_user(user_id): user = data_manager.get_user(user_id) if user: User = data_manager.User(user) return User else: return None
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)
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
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
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))
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)
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)
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'))
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')
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)
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")
def check_permission(user_id): user = data_manager.get_user(user_id) return user and user[3] == 1