def change_status_vacancy(): user = check_auth(request.headers, __name__) if user != True: return user user = authorize.get(request.headers.get('UserToken')) try: database = Database() except TypeError: return jsonify({"messageError": "Нет подключения к БД"}) change_status_data = request.get_json(silent=True) if not change_status_data: return jsonify(text="JSON не найден"), 204 directories = [(None, "status_id"), (None, "vacancy_id")] check = check_fields(directories, change_status_data) if type(check) == list: return "В json отсутсвуют поля: {}".format(",".join(i for i in check)) result = database.insert_data( sql.SQL( "UPDATE vacancy SET status_id={status_id} WHERE id={vacancy_id}"). format(status_id=sql.Literal(change_status_data['status_id']), vacancy_id=sql.Literal(change_status_data['vacancy_id']))) database.close() return jsonify(result)
def authorization(): user_data = request.get_json(silent=True) if not user_data: return jsonify(text="JSON не найден"), 204 login = user_data.get("login") password = user_data.get("password") database = None try: database = Database() user_data = database.login(login) if type(user_data) == str: return jsonify({"messageError": user_data}), 500 if user_data: if check_password(user_data, password): if user_data["status_active"] == True: user = User(id=user_data["id"], username=user_data["username"], role=user_data["role"]) authorize[user.get_token()] = user database.insert_data("UPDATE users SET last_login=now() \ WHERE username='******'".format( username=user.get_username())) return jsonify({ "UserToken": user.get_token(), "role": user.get_role() }) return jsonify({'message': 'Пользователь заблокирован'}), 401 return jsonify({'message': 'Неправильный логин или пароль'}), 401 except TypeError: return jsonify({"messageError": "Нет подключения к БД"}), 500 finally: database.close() return jsonify(True)