def lti(): if check_request(request): temporary_user_params = request.form username = temporary_user_params.get('ext_user_username') person_name = utils.get_person_name(temporary_user_params) user_id = f"{username}_{temporary_user_params.get('tool_consumer_instance_guid', '')}" lms_user_id = temporary_user_params.get('user_id', '') params_for_passback = utils.extract_passback_params(temporary_user_params) custom_params = utils.get_custom_params(temporary_user_params) custom_criteria = utils.get_criteria_from_launch(temporary_user_params) role = utils.get_role(temporary_user_params) logout_user() user = bd_helper.add_user(user_id, is_LTI = True) if user: user.name = person_name user.is_admin = role else: user = bd_helper.get_user(user_id) user.params_for_passback = params_for_passback user.lms_user_id = lms_user_id bd_helper.edit_user(user) login_user(user) update_criteria(custom_criteria) return redirect(url_for('upload')) else: abort(403)
def profile(username): if current_user.is_admin: if username == '': return redirect(url_for("profile", username=current_user.username)) u = bd_helper.get_user(username) me = True if username == current_user.username else False if u is not None: return render_template("./profile.html", navi_upload=True, name=current_user.name, user=u, me=me) else: logger.info("Запрошенный пользователь не найден: " + username) return render_template("./404.html") else: abort(403)
def grade_passback(self, check): user = check.get('user') passback_params = get_user(user).params_for_passback if not passback_params: return consumer_secret = ConsumersDBManager.get_secret( passback_params['oauth_consumer_key']) response = ToolProvider.from_unpacked_request( secret=consumer_secret, params=passback_params, headers=None, url=None).post_replace_result(score=check.get('score')) if response.code_major == 'success' and response.severity == 'status': logger.info( 'Score was successfully passed back: score = {}, check_id = {}' .format(check.get('score'), check.get('_id'))) set_passbacked_flag(check.get('_id'), True) else: logger.warning('Passback failed for check_id = {}'.format( check.get('_id')))
def init(app, debug): try: get_client().admin.command('ismaster') logger.info("MongoDB работает!") except ConnectionFailure: logger.error("MongoDB не доступна!") return False cred_id = "admin" cred_pass = app.config['ADMIN_PASSWORD'] user = get_user(cred_id) if user is None: user = add_user(cred_id, get_hash(cred_pass)) user.name = cred_id user.is_admin = True edit_user(user) logger.info( f"Создан администратор по умолчанию: логин: {user.username}, пароль уточняйте у разработчика" ) return True
def load_user(user_id): return bd_helper.get_user(user_id)