def update_user(): user_uuid = request.form.get("uuid", None) name = str(request.form.get("name", None)) user_hash = Encryption.encrypt_password( str(request.form.get("password", None))) email = str(request.form.get("email", None)) birthdate = str(request.form.get("birthdate", None)) if not data_validation.validate_uuid(user_uuid): return return_json(success=False, error="Invalid user UUID") if user_db.get_user(uuid=user_uuid)[0] is False: return return_json(success=False, error="User not found") if not data_validation.validate_email(email): return return_json(success=False, error="Invalid email") if not data_validation.validate_birthdate(birthdate)[0]: return return_json( success=False, error=data_validation.validate_birthdate(birthdate)[1]) c_user = user_db.get_user(uuid=user_uuid)[1] c_user.name = name c_user.user_hash = user_hash if c_user.email != email: c_user.email = email c_user.is_verified = False c_user.birthdate = birthdate user_db.update_user(c_user) return return_json( success=True, data={"message": "User {0} updated".format(c_user.uuid)})
def register_user(): name = str(request.form.get("name", None)) user_hash = Encryption.encrypt_password( str(request.form.get("password", None))) email = str(request.form.get("email", None)) birthdate = str(request.form.get("birthdate", None)).replace( "-", "/") # IOS uses '-' instead of '/' if name is None or email is None or name is None: return return_json(success=False, error="Fields empty") if not data_validation.validate_email(email): return return_json(success=False, error="Invalid email") if not data_validation.validate_birthdate(birthdate)[0]: return return_json(success=False, error="Invalid birthdate:" + data_validation.validate_birthdate(birthdate)[1]) res = user_db.insert_user(name, user_hash, email, birthdate) if not res[0]: return return_json(success=False, error="User already exists") user_uuid = res[1] expenses_db.create_expenses(user_uuid) schedule_db.create_schedule(user_uuid) hygiene_db.create_hygiene(user_uuid) token = token_generator.generate_confirm_token(email) send_confirmation_mail(name, email, token) return return_json(success=True)
def login(): email = str(request.form.get("email", None)) password = str(request.form.get("password", None)) install_id = str(request.form.get("install_id", None)) # Unique app id if email is None or password is None: return return_json(success=False, error="Fields empty") if not data_validation.validate_email(email): return return_json(success=False, error="Invalid email") if install_id is None: return return_json(success=False, error="Invalid install_id") return user_db.verify_user(email, password, install_id)
def send_email_admin(): email = request.form.get("email", None) subject = request.form.get("subject", None) content = request.form.get("content", None) if not data_validation.validate_email(email): return render_template('email/email_main.html', error="Invalid email") res = user_db.get_user(email=email) if not res[0]: return return_message("Error", "User not found", 2, url_for('admin_blueprint.email_main')) c_user = res[1] mail.send_message_mail(c_user.name, c_user.email, subject, content) return return_message("Succes", f"Email has been sent to {c_user.name}", 2, url_for("admin_blueprint.users_main"))
def user_edit(uuid): c_user = user_db.get_user(uuid=uuid)[1] if request.method == "GET": c_arduino = arduino_db.get_arduino_by_user_uuid(uuid) if c_arduino: c_user.arduino = c_arduino.arduino_uuid else: c_user.arduino = None return render_template('users/user_edit.html', user_list=[c_user]) else: user_uuid = uuid name = str(request.form.get("name", None)) email = str(request.form.get("email", None)) birthdate = str(request.form.get("birthdate", None)) if not data_validation.validate_uuid(user_uuid): return render_template('users/user_edit.html', user_list=[c_user], error="Invalid user UUID") if user_db.get_user(uuid=user_uuid)[0] is False: return render_template('users/user_edit.html', user_list=[c_user], error="User not found") if not data_validation.validate_email(email): return render_template('users/user_edit.html', user_list=[c_user], error="Invalid email") if not data_validation.validate_birthdate(birthdate)[0]: return render_template('users/user_edit.html', user_list=[c_user], error=data_validation.validate_birthdate(birthdate)[1]) c_user = user_db.get_user(uuid=user_uuid)[1] c_user.name = name if c_user.email != email: c_user.email = email c_user.is_verified = False name = c_user.name token = generate_confirm_token(c_user.email) send_mail(c_user.name, c_user.email, token) c_user.birthdate = birthdate user_db.update_user(c_user) return return_message("User updated", f"{c_user.name} has been updated!", 2, url_for('admin_blueprint.get_users'))
def login(): if request.method == "GET": return render_template('auth/login.html') email = str(request.form.get("emailInput", None)) password = str(request.form.get("passwordInput", None)) if email is None or password is None: return return_json(success=False, error="Fields empty") if not data_validation.validate_email(email): return return_json(success=False, error="Invalid email") if not db.verify_admin(email, password): return return_json(success=False, error="Invalid credentials") admin_session = sessions.TtSession(session) admin_session.login_admin(email, password) admin_session.update_ses(session) return return_message("Loggin successfull", "Welcome Senpaii uWu <3 <3", 2, url_for('admin_blueprint.admin_home'))
def add_user(): if request.method == "GET": return render_template('users/user_add.html') name = str(request.form.get("name", None)) pw1 = request.form.get("password", None) pw2 = request.form.get("confirm_password", None) user_hash = Encryption.encrypt_password( str(request.form.get("password", None)) ) email = str(request.form.get("email", None)) birthdate = str(request.form.get("birthdate", None)).replace( "-", "/") # IOS uses '-' instead of '/' if name is None or email is None or name is None: return render_template('users/user_add.html', error="Fields empty") if pw1 != pw2: return render_template('users/user_add.html', error="Passwords don't match") if not data_validation.validate_email(email): return render_template('users/user_add.html', error="Invalid mail") if not data_validation.validate_birthdate(birthdate)[0]: return render_template('users/user_add.html', error="Invalid birthdate:" + data_validation.validate_birthdate(birthdate)[1]) res = user_db.insert_user(name, user_hash, email, birthdate) if not res[0]: return render_template('users/user_add.html', error="User already exists") user_uuid = res[1] expenses_db.create_expenses(user_uuid) schedule_db.create_schedule(user_uuid) hygiene_db.create_hygiene(user_uuid) token = generate_confirm_token(email) mail.send_confirmation_mail(name, email, token) return return_message("Succes", "User added!", 2, url_for('admin_blueprint.get_users'))
def resend_mail(): email = request.form.get("email", None) if not data_validation.validate_email(email): return return_json(success=False, error="Invalid email") res = user_db.get_user(email=email) if not res[0]: return return_json(success=False, error="User not found") c_user = res[1] if c_user.is_verified: return return_json(success=False, error="User is already verified") name = c_user.name token = token_generator.generate_confirm_token(email) send_mail(name, email, token) return return_json(success=True)