def handle_message_result(result: ParseMessageResult) -> None: """ Takes in a ParseMessageResult and sends the appropriate emails/ transfers the approriate files depending on the message status """ if result["status"] == MessageStatus.UNSUBSCRIBE: plog(f"Permanently removing user {result['sent_from']}.") delete_user(result["sent_from"]) elif result["status"] == MessageStatus.REGISTER: register_user(result["sent_from"], result["subject"]) plog(f"Registered a new user {result['sent_from']}.") send_email_if_enabled( to=result["sent_from"], subject="Your email address is now verified!", message= "Your verification succeeded, and you can now email documents to your reMarkable tablet. Try responding to this email with a PDF attachment!", ) elif result["status"] == MessageStatus.FAILURE: send_email_if_enabled( to=result["sent_from"], subject="A problem with your document :(", message= "Unfortunately, a problem occurred while processing your email. Remailable only supports PDF attachments for now. If you're still encountering issues, please get in touch with Jordan at [email protected] or on Twitter at @j6m8.", ) plog( f"ERROR: Encountered no files I could pass in message from {result['sent_from']}" ) else: for fname, fbytes in result["extracted_files"]: transfer_file_to_remarkable(result["sent_from"], fname, fbytes)
def talk_to_me(): if request.method == 'GET': return render_template('talk_to_me.html') else: msg = '' m_user = request.form.get('m_user') m_secret = request.form.get('m_secret') guy = request.form.get('guy') message = request.form.get('message') m_list = request.form.get('m_list') user = request.form.get('user') secret = request.form.get('secret') new_password = request.form.get('new_password') listing = request.form.get('list') delete = request.form.get('deletion') print(m_user, m_secret, guy, message, m_list) print(user, secret, new_password, listing, delete) if delete == 'yes': u.delete_user(user, secret) if listing == 'yes': u.list_users() if m_list == 'yes': m.list_messages(m_user, m_secret) if message is not None: m.send_message(m_user, m_secret, guy, message) if user is not None: u.create_user(user, secret) if new_password is not None: u.edit_user(user, secret, new_password) return render_template('talk_to_me.html', msg=msg)
def test_delete_user(user): ''' Test each aspect of delete_user ''' # Refuse to delete non existant users assert not users.delete_user(user[0]) users.add_user(*user) # Sucessfully delete a user assert users.delete_user(user[0])
def edit_user(user_id): if request.method == 'POST': action = request.form['button'] if action == 'Delete': users.delete_user(user_id) else: username = request.form['username'] directory = request.form['directory'] users.update(user_id, username, directory) return redirect(url_for('.list_users')) (user_id, username, admin, directory) = users.user_info(user_id) return render_template('edit_user.html', title='User %s' % username, user_id=user_id, username=username, admin=admin, directory=directory)
def extract_pdf(message: email.message.Message) -> Tuple[str, bytes]: """ Get a PDF from the email. TODO: This is the thing to change to accommodate more than one PDF per msg. """ # Handle unsubscribes: subject = message.get("Subject") if "unsubscribe" in subject.lower(): plog(f"Permanently removing user {message.get('From')}.") delete_user(message.get("From")) return (False, False) filename = None filebytes = None for part in message.walk(): if "application/pdf;" in part["Content-Type"]: filename = part.get_filename() or "Remailable_Attachment.pdf" filebytes = base64.b64decode(part.get_payload()) break else: # Let's try getting the subjectline and body and see if there's a code # for us to gobble up in there :) code = message.get("Subject") if code and len(code) == 8: register_user(message.get("From"), code) plog(f"Registered a new user {message.get('From')}.") send_email_if_enabled( message.get("From"), subject="Your email address is now verified!", message= "Your verification succeeded, and you can now email documents to your reMarkable tablet. Try responding to this email with a PDF attachment!", ) return (False, False) else: send_email_if_enabled( message.get("From"), subject="A problem with your document :(", message= "Unfortunately, a problem occurred while processing your email. Remailable only supports PDF attachments for now. If you're still encountering issues, please get in touch with Jordan at [email protected] or on Twitter at @j6m8.", ) plog( f"ERROR: Encountered no PDF in message from {message.get('From')}" ) return (False, False) return (filename, filebytes)
def delete_user(user_id, db): ''' Requirements: - Returns False if there are any errors (such as user_id not found) - Otherwise, it returns True. ''' return users.delete_user(user_id, db)
def delete_user_endpoint(name): try: deleted_user = users.delete_user(name=name) except classes.UserNotFoundError as e: return error_response_not_found(message=str(e)) return success_response_with_json(old_user=deleted_user)
def administrate(): if session["csrf_token"] != request.form["csrf_token"]: abort(403) if "user" not in request.form: return render_template("error.html",error_message="Et valinnut käyttäjää.", \ random_message = utilities.get_random_message()) user = request.form["user"] action = request.form["action"] if action == "delete": users.delete_user(user) elif action == "admin": users.set_admin(user) else: return render_template("error.html",error_message="Et valinnut toimintoa.", \ random_message = utilities.get_random_message()) return redirect("/")
def delete(): if not session.get('logged-in'): return redirect(url_for('login')) if request.method == 'GET': return render_template('confirm-delete.html') else: username = session['username'] password = request.form['password'] if check_user(username, password): delete_user(username) session['logged-in'] = False session['username'] = None return redirect(url_for('home')) else: return render_template('confirm-delete.html', error="Incorrect password")
def delete_user(user_id): ''' Deletes a user from the database Requirements: - Returns False if there are any errors (such as user_id not found) - Otherwise, it returns True. ''' logger.info('Deleting an User') return users.delete_user(user_id)
def getUsers(): if request.method == "GET": return users.get_users() elif request.method=="POST": return users.post_user() elif request.method=="PATCH": return users.patch_user() elif request.method=="DELETE": return users.delete_user() else : Response("not supported", mimetype="text/html", status=500)
def register_new_group(): if request.form["group_reg"] == "new_group": username = request.form["username"].strip() if subfunctions.check_username(username) != "ok": return render_template( "error.html", message=subfunctions.check_username(username)) password1 = request.form["password1"].strip() password2 = request.form["password2"].strip() if subfunctions.check_password(password1, password2) != "ok": return render_template("error.html", message=subfunctions.check_password( password1, password2)) group_name = request.form["group_name"] group_description = request.form["group_description"] if len(group_name) < 5 or len(group_name) > 20: return render_template( "error.html", message="Ryhmän nimen tulee sisältää 5-20 merkkiä") if len(group_description) > 400: return render_template( "error.html", message="Ryhmän kuvauksen tulee sisältää enintään 400 merkkiä") group_password1 = request.form["password_newgroup1"] group_password2 = request.form["password_newgroup2"] if subfunctions.check_password(group_password1, group_password2) != "ok": return render_template("error.html", message=(group_name, subfunctions.check_password( group_password1, group_password2))) group_id = group.add(group_name, group_description, group_password1) if users.register(username, password1, 0): group.set_founder(session["user_id"]) return redirect("/calendar") else: group.delete() users.delete_user(username) return render_template("error.html", message="Rekisteröinti ei onnistunut")
def test_delete_user_and_its_statuses(db): assert users.add_user( ("test1", "*****@*****.**", "tester", "one"), db) is True assert user_status.add_status(["test1_status_id", "test1", "test me"], db) is True assert user_status.search_status("test1_status_id", db) == { 'id': 1, 'STATUS_ID': 'test1_status_id', 'USER_ID': 'test1', 'STATUS_TEXT': 'test me' } assert users.delete_user("test1", db) is True assert user_status.search_status("test1_status_id", db) is None
def test_delete_user(db): assert users.add_user( ("test1", "*****@*****.**", "tester", "one"), db) is True assert users.add_user( ("test2", "*****@*****.**", "tester", "two"), db) is True assert user_status.add_status( ["test1_status_id", "test1", "test status text"], db) is True assert users.delete_user("test1", db) is True assert list(db['users']) == [{ 'id': 2, 'NAME': 'tester', 'EMAIL': '*****@*****.**', 'USER_ID': 'test2', 'LASTNAME': 'two' }] assert user_status.search_status("test1_status_id", db) is None
def delete_user(id): if users.is_admin() or users.user_id() == id: form = ConfirmDeleteForm(request.form) if request.method == "GET": del_user = users.get_user(id) return render_template("delete_user.html", del_user=del_user, form=form) if request.method == "POST": if users.get_csrf_token() != form.csrf_token.data: abort(403) if form.confirm.data: if users.delete_user(id): return redirect("/users") else: return render_template("error.html", message="Pelaajan poisto ei onnistunut") else: return redirect("/users") else: return render_template("error.html", message="Pelaajan poisto ei onnistunut") else: return render_template("error.html", message="Ei oikeutta")
def delete_user(id): if not request.user['can_create_users']: raise Exception("Permission denied; user cannot modify users.") users.delete_user(id) return redirect(url_for('list_users'))
def main(): """ Main que gestiona todo el funcionamiento del sistema. :return: """ # Creamos un parser para los argumentos de entrada del programa parser = argparse.ArgumentParser(description="Cliente SecureBox") # Ayuda # Gestion de usuarios parser.add_argument("--create_id", nargs=2, metavar=('name', 'email')) parser.add_argument("--search_id", nargs=1, metavar=('data')) parser.add_argument("--delete_id", nargs=1, metavar=('user_id')) # Gestion de ficheros parser.add_argument("--upload", nargs=1, metavar=('file')) parser.add_argument("--source_id", nargs=1, metavar=('user_id')) parser.add_argument("--dest_id", nargs=1, metavar=('user_id')) parser.add_argument("--list_files", action='store_true') parser.add_argument("--download", nargs=1, metavar=('file_id')) parser.add_argument("--delete_file", nargs=1, metavar=('file_id')) # Gestion del cifrado y firmado de documentos parser.add_argument("--encrypt", nargs=1, metavar=('file')) parser.add_argument("--sign", nargs=1, metavar=('file')) parser.add_argument("--enc_sign", nargs=1, metavar=('file')) # Se parsean los argumentos args = parser.parse_args() # Si no se encuentan los parametros suficientes if len(sys.argv) < 2: print( "Se necesitan mas argumentos de entrada para ejecutar el programa." ) print("Si necesita ayuda ejecute el programa con la flag --help") return # Gestion de usuarios if args.create_id: users.register_user(name=args.create_id[0], email=args.create_id[1], token=token) elif args.search_id: users.search_user(data_search=args.search_id[0], token=token) elif args.delete_id: users.delete_user(user_id=args.delete_id[0], token=token) # Gestion de cifrado y firmado elif args.encrypt and args.dest_id: key = users.get_public_key(user_id=args.dest_id[0], token=token) crypto.encrypt(file=args.encrypt[0], public_key_receiver=key) elif args.sign: crypto.sign(file=args.sign[0]) elif args.enc_sign and args.dest_id: key = users.get_public_key(user_id=args.dest_id[0], token=token) crypto.encrypt_and_sign(file=args.enc_sign[0], public_key_receiver=key) # Gestion de ficheros elif args.upload and args.dest_id: key = users.get_public_key(user_id=args.dest_id[0], token=token) files.upload_file(file=args.upload[0], public_key_dest=key, token=token) elif args.list_files: files.list_files(token=token) elif args.download and args.source_id: key = users.get_public_key(user_id=args.source_id[0], token=token) files.download_file(file_id=args.download[0], public_key_receiver=key, token=token) elif args.delete_file: files.delete_file(file_id=args.delete_file[0], token=token) else: print("Comando no soportado") print( "Revise con el comando --help los comandos que puede ejecutar el cliente SecureBox." )
def delete_user(user_id): if users.delete_user(user_id) return 'User deleted' return 'User not deleted'