예제 #1
0
def searchUser(data, user):
	url = 'https://vega.ii.uam.es:8080/api/users/search'

	args = {
		'data_search': data
	}

	bearer = "Bearer " + user.token

	headers = {
		"Content-Type" : "application/json",
		"Authorization" : bearer
	}

	r = requests.post(url, json=args, headers=headers)

	status = r.status_code

	if status == 200:
		ret = []
		for user in r.json():
			userID = user['userID']
			name = user['nombre']
			email = user['email']
			public_key = user['publicKey']
			timestamp = user['ts']

			usr = user_database.User(userID, name, email, public_key, timestamp)
			ret.append(usr)
		return ret
	else:
		print("Error:", status)
예제 #2
0
def main_operation():
	todays_date = get_todays_date()[0]
	day = get_todays_date()[1]

	while True:
		if (Mail.total_user() == 0):
			print("No user found on database. You have to add at least one user to continue.")
			user_mail = input("Mail: ").lower()
			link = input('Link: ')
			link = "['" + str(link) + "']"

			user_info = user_database.User(user_mail, True, link)
			Mail.add_mail(user_info)

		try:
			mail_list = Mail.get_mails()
			for i in mail_list:

				links = eval(i[2])
				
				for j in links:
					house_details = get_house_details(j)

					for k in range(3):

						if (not House.check_if_house_exists(house_details[0][k] + ':' + i[0]) and house_details[4][k] == todays_date):

							New_House = house_database.House(house_details[0][k] + ':' + i[0],house_details[1][k],house_details[2][k],house_details[3][k],house_details[4][k],house_details[5][k],house_details[6][k],house_details[7][k])
							House.add_house(New_House)
							House.add_house(New_House,True)

							text_mail = text_of_mail.html_text(house_details[0][k],house_details[1][k],house_details[2][k],house_details[3][k],house_details[4][k],house_details[5][k],house_details[6][k],house_details[7][k])

							inform_user.send_mail(i[0], text_mail)

			
			todays_day = get_todays_date()[1]

			if (todays_day != day):
				House.clear_posts(str(day))
				todays_date = get_todays_date()[0]
				day = get_todays_date()[1]

			print('Process finished. Waiting for 3 min.')
			time.sleep(180)

		except:
			print('Something unexpected happened. Waiting for 3 min.')
			print(traceback.format_exc())
			time.sleep(180)
예제 #3
0
from flask import Flask, render_template, request, redirect, url_for, flash, session, logging
from wtforms import Form, StringField, TextAreaField, PasswordField, validators
from functools import wraps
import user_database, theater_database, movie_database

# init Flask App
app = Flask(__name__)

# init database classes
user = user_database.User()
theatre = theater_database.Theater()
movie = movie_database.Movie()


@app.route('/')
def index():
    return render_template('home.html')


# --------------------- RegisterForm Class -------------------->
class RegisterForm(Form):
    name = StringField(
        'Name', [validators.DataRequired(),
                 validators.Length(min=1, max=50)])
    username = StringField(
        'Username',
        [validators.DataRequired(),
         validators.Length(min=4, max=25)])
    email = StringField(
        'Email', [validators.DataRequired(),
                  validators.Length(min=6, max=50)])
예제 #4
0
                   nargs='+',
                   help='creates a new user, needs: name, email, [alias]')
group.add_argument('--change_user',
                   nargs=2,
                   help='changes the user, needs: userID, token')
# Aniadimos elementos fuera del grupo excluyente
parser.add_argument('--dest_id',
                    metavar='id',
                    help='specify the receiver for the file')
parser.add_argument('--source_id',
                    metavar='id',
                    help='specify the sender of the file')
# Parsear
args = parser.parse_args()

current_user = user_database.User(None, None, None, None, None)

client = secure_client(current_user, args.dest_id, args.source_id)

# Comprobacion de flags y llamada a funciones
if args.encrypt is not None:
    client.encrypt(args.encrypt)
elif args.decrypt is not None:
    client.decrypt(args.decrypt)
elif args.sign is not None:
    client.sign(args.sign)
elif args.check_sign is not None:
    client.check_sign(args.check_sign)
elif args.enc_sign is not None:
    client.enc_sign(args.enc_sign)
elif args.dec_csign is not None:
예제 #5
0
import securebox
import user_database
from Crypto.PublicKey import RSA

user = user_database.User('e340546', "Jose Ignacio", "*****@*****.**",
                          None, 0)

key = open("e340546.pem", "r").read()
user.public_key = key

key = open("e340546.bin", "r").read()
user.private_key = key

# #___Test de registerUser___
name, ts = securebox.registerUser(user)
print("\nUsuario registrado con exito: ")
# print("Nombre: " + name)
# print("Timestamp: " + str(ts) + "\n")

# #___Test de getPublicKey___
# key = securebox.getPublicKey(user, user.id)
# if key is None:
# 	print("\nEl usuario no ha sido registrado.\n")
# print("\nClave publica obtenida:\n")
# print(key + "\n")

# #___Test de search_user___
# found = securebox.searchUser('*****@*****.**', user)
# print("\nUsuarios coincidentes encontrados:\n")
# print(found)
# print("\n")
예제 #6
0
def user_operations():
	print("""
		Enter '1' to see all users.
		Enter '2' to add a new user.
		Enter '3' to delete a user.
		Enter '4' to update a user.
		Enter '5' to see total number of users.
		Enter '6' to go back to main menu.
		Enter 'q' to exit the program.
		""")

	while True:

		command = input("\nCommand for mail: ")

		if (command == "1"):
			Mail.show_mails()

		elif (command == "2"):
			print("Enter a new mail address:")
			new_mail = input().lower()

			if (Mail.check_if_mail_exists(new_mail)):
				print("\n" + new_mail, "already exists on database. Please try again.\n")
				continue

			print("Would you want to receive mails? (Y/N):")
			user_stat = input().upper()

			link = input('Link: ')
			link = "['" + link + "']"

			if (user_stat == "Y"):
				user_stat = True
				text = new_mail + " successfully added to database."

			elif (user_stat == "N"):
				user_stat = False
				text = new_mail + " successfully added to database. Be aware that you wont receive any mails."

			else:
				print("\nInvalid command. Try again.\n")
				continue

			new_user = user_database.User(new_mail, user_stat,link)
			Mail.add_mail(new_user)

			print(text)


		elif (command == "3"):

			if (Mail.total_user() == 0):
				print("\nNo user found on database.\n")
				continue

			print("Enter the mail address you want to delete:")
			del_mail = input("Mail: ")

			if (Mail.check_if_mail_exists(del_mail) == 0):
				print("There is not such mail address as " + del_mail + ". Please try again")
				continue

			print("Are you sure you want to delete " + del_mail + "? (Y/N):")
			yes_no = input().upper()

			if (yes_no == "Y"):
				Mail.delete_mail(del_mail)
				print(del_mail, " successfully deleted from database.")

			elif (yes_no == "N"):
				print("Process canceled.")
				continue
			else:
				print("\nInvalid command. Please try again.")


		elif (command == "4"):

			if (Mail.total_user() == 0):
				print("\nNo user found on database.\n")
				continue

			print("Enter the mail address you want to update: ")
			update_mail = input()

			if (Mail.check_if_mail_exists(update_mail) == 0):
				print("There is not such mail address as " + update_mail + ". Please try again")
				continue

			print("What would you want to change? "
				"To go back, enter 'q' , to change mail "
				"enter M, to change status enter S, to change link enter L (you will be asked to enter index number the link you want to delete):")

			change_what = input().upper()

			# Updating User Mail
			if (change_what == "M"):
				new_mail = input("Enter a new mail address: ")
				Mail.update_mail(update_mail, new_mail)
				print(update_mail, "changed to", new_mail + ".")

			# Updating Status (if 0, wont receive mails, else will)
			elif (change_what == "S"):
				print("Would you want to get mails or not? (Y/N)")
				yes_no = input().upper()
				if (yes_no == "Y"):
					Mail.update_stat(update_mail, True)
					print(update_mail, "will now receive mails.")
				elif (yes_no == "N"):
					Mail.update_stat(update_mail, False)
					print(update_mail, "will not receive mails anymore.")
				else:
					print("Wrong command. Please try again.")
					continue
			elif (change_what == 'L'):

				link = str(Mail.get_link(update_mail))
				link = eval(link.replace('(',"").replace('"',"").replace(')',"")[1:len(link)-6])

				print('Add/delete/update? ')
				process = input().upper()

				if (process == 'ADD'):
					new_link = input('Enter link: ')
					link.append(new_link)
					Mail.update_link(str(link),update_mail)
					print('Link added successfully.')

				elif (process == 'DELETE'):
					print(str(link))
					print('Enter index number: ')
					index = int(input('Index: '))
					link.pop(index)
					Mail.update_link(str(link),update_mail)
					print('Link deleted successfully.')

				elif (process == 'UPDATE'):
					print(str(link))
					print('Enter index number: ')
					index = int(input('Index: '))
					new_link = input('Enter link: ')
					link[index] = new_link
					Mail.update_link(str(link),update_mail)
					print('Link updated successfully.')

				else:
					print("Wrong command. Please try again.")
					continue


			elif (change_what == "Q"):
				print("You are back to menu.")

			else:
				print("\nInvalid comamnd. Try again.\n")


		elif (command == "5"):

			total = Mail.total_user()

			if (total != 0):
				print("Total number of users: ", total)
			else:
				print("No user found on database.")

		elif (command == "6"):
			# Going Back to Main Menu
			print("\nYou are on main menu right now.\n")
			break

		elif (command == "q"):
			exit()

		else:
			print("Invalid command. Try again.")