def getUser(): global users user = User() for i in range(0, len(users)): if users[i][0] == request.remote_addr: return users[i][1] return user
def googleLogin(): json = request.get_json() # this is ripped directly from google lol idinfo = id_token.verify_oauth2_token(json['ID'], requests.Request(), googleID) if idinfo['iss'] not in [ 'accounts.google.com', 'https://accounts.google.com' ]: # not a valid issuer, murder them return render_template("login.html", retry=True, googleID=googleID) id_ = idinfo['sub'] user = getGUser(id_) if user == None: user = User(json['name'], json['email'], id_) addUser(user) flask_login.login_user(user) saveUsers() if user.hasInit: # account has been inintalized, it has a team number and account level asociated return redirect(url_for('home')) else: return redirect(url_for('initAccount', ))
def login(): if request.method == "POST": user = User(dbHost,dbPort) status = user.userLogin(request.form["username"],request.form["password"]) flash(status) return redirect("index.html") else: return render_template("login.html")
def newUser(): "Creates a new user from scrath" userName = input( "To start the contact list application please type your user name : ") password = input("Please insert a password consisting of only numbers : ") listName = input( f"Welcome {userName}!!!! now please type the name of your contact list : " ) myUser = User(userName, password) myUser.createContactList(listName) controller(myUser)
def retrieve_user_from_id(ID): if (ID[0] == 'U'): c.execute("SELECT * FROM user_table WHERE userid = ?", (str(ID), )) user = c.fetchone() else: return None if user != None: return User(user[1], user[2], user[3], user[4], user[0]) else: return None
def retrieve_users_by_points(): c.execute("SELECT * FROM user_table ORDER BY contribution_pt DESC") user_list = [] users = c.fetchall() for i in range(len(users)): user_list.append( User(users[i][1], users[i][2], users[i][3], users[i][4], users[i][0])) return user_list
def register(): print("Thank you for registering! Please enter the following information:") #Ask user for name, birthdate, and location name = input("Name: ") birthdate = input("Birthdate: ") location = input("Address: ") #Instantiate new object and store the information --> User(name, birthdate, location) current_user = User(name, birthdate, location) #Store user information in json/database --> store_data(user) db.store_user(current_user) return current_user
def addFlight(): user = User(dbHost,dbPort) if request.method == "POST": flight = Flight() flight.flight_source_city = request.form.get("sourceCity") flight.flight_depart = request.form["depart"] flight.flight_source_gate = request.form["departGate"] flight.flight_dest_city = request.form.get("destCity") flight.flight_arrive = request.form["arrive"] flight.flight_dest_gate = request.form["arriveGate"] flight.plane_id = request.form.get("plane") flight.flight_base_price = request.form["price"] status = flight.addFlight(user) print(status) flash(status) #return redirect("addFlight") return redirect("addFlight") else: city_list = [] cities = City() cities = cities.getAllCities(user) #Create a list with all cities for i in range(0,len(cities)): city = City() city.city_id = cities[i][0] city.city_name = cities[i][1] city.city_state = cities[i][2] city.city_lat = cities[i][3] city.cit_long = cities[i][4] city_list.append(city) plane_list = [] planes = Plane() planes = planes.getAllPlanes(user) for j in range(0,len(planes)): plane = Plane() plane.plane_id = planes[j][0] plane.airline_id = planes[j][1] plane.plane_model = planes[j][2] plane.plane_seats = planes[j][3] plane.airline_name = planes[j][4] plane_list.append(plane) return render_template("addFlight.html", city_list=city_list, plane_list=plane_list)
def send_account_info(dest_sock, username_length): username_length = int(username_length) username = dest_sock.recv(username_length) user = User(username) if user.exists(): user.by_file() msg = (user.get_info()) log("Sent user info of user " + username) answers_queue.append(Answer(dest_sock, Answer.ACC_TYPE, len(msg), msg)) if dest_sock not in outputs: outputs.append(dest_sock) inputs.remove(dest_sock)
async def start_func(query: types.CallbackQuery, state: FSMContext): user_id = query.from_user.id new_user[user_id] = User(user_id) id_ = new_user[user_id] id_.first_name = query.from_user.first_name if user_id not in database.get_users(): await bot.send_message(user_id, "Нужно зарегестрироваться", reply_markup=reg_btns) await Form.first_step.set() else: for i in range(len(database.get_users())): if user_id == database.get_users()[i][0]: await bot.send_message(user_id, "Вы уже зарегестрированы")
def register(): global username, users if request.method == 'POST': usernameS = request.form.get('username') password = request.form.get('password') firstname = request.form.get('firstname') lastname = request.form.get('lastname') user = User() user.register(database=db, login=usernameS, password=password, firstname=firstname, lastname=lastname, cursor=cursor) username = getUser().firstname, getUser().lastname return redirect(url_for('index')) if getUser().id is None: return render_template("register.html", logged=False, urlLogin=url_for('login')) else: return render_template("register.html", logged=True, urlLogin=url_for('login'))
def newGGLUser(email, basic_info, db, access_token): import json rand_username = ''.join( random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) user = User(basic_info['given_name'], basic_info['family_name'], email, 'google', rand_username, basic_info['picture']) db.session.add(user) data = db.session.commit() newConnection(email, basic_info, db, access_token, user) json = user.token_construction() return json
def login(): global username, users if request.method == 'POST': usernameS = request.form.get('username') password = request.form.get('password') user = User() user.login(database=db, login=usernameS, password=password, cursor=cursor) addUser(user) if getUser().id is not None: return redirect(url_for('index', username=getUser().firstname + " " + getUser().lastname)) else: return redirect(url_for('index', logged=False)) if getUser().id is None: return render_template("login.html", logged=False, urlReg=url_for('register')) else: return render_template("login.html", logged=True, urlReg=url_for('register'))
def listing(): user = User(dbHost,dbPort) reservation = Reservation() reservations = reservation.getReservations(user) listing_list = [] for i in range(0,len(reservations)): listing = Reservation() listing.reservation_id = reservations[i][0] listing.flight_id = reservations[i][1] listing.user_id = reservations[i][2] listing.billing_id = reservations[i][3] listing.timestamp = reservations[i][4] listing.reservation_seat = reservations[i][5] listing.reservation_total = reservations[i][6] listing_list.append(listing) return render_template("listing.html",dbHost=dbHost,dbPort=dbPort,listing_list=listing_list)
def send_login_msg(dest_sock, data_len): data_len = int(data_len) username = dest_sock.recv(data_len) usr = User(username) if usr.exists(): usr.by_file() msg = "Welcome back " + username log("User logged in : " + username) else: usr.new_user() log("User created : " + username) msg = "Welcome aboard " + username answers_queue.append(Answer(dest_sock, Answer.LOG_TYPE, len(msg), msg)) if dest_sock not in outputs: outputs.append(dest_sock) inputs.remove(dest_sock)
def createAccount(): if request.method == "POST": email = request.form["email"] phone = request.form["phone"] password1 = request.form["password1"] password2 = request.form["password2"] #Password check if password1 != password2: flash("Error: Passwords do not match. Please re-enter") return render_template("createAccount.html") user = User(dbHost, dbPort) #instantiate user class status = user.createAccount(email,password1, phone) flash(status) return render_template("createAccount.html") else: return render_template("createAccount.html")
def populate_users(ratings_file, tags_file, thresh): users = {} movies = open(ratings_file, encoding="utf8") tags = open(tags_file, encoding="utf8") movies_r = csv.reader(movies) tags_r = csv.reader(tags) next(tags_r) current_movies = next(movies_r) current_tags = next(tags_r) stay = True stay2 = True i = int(current_movies[0]) while stay: arr_movies_l = {} arr_movies_d = {} arr_liked_tags = [] arr_disliked_tags = [] while int(current_movies[0]) == i and stay: if float(current_movies[2]) >= thresh: arr_movies_l[current_movies[1]] = float(current_movies[2]) else: arr_movies_d[current_movies[1]] = float(current_movies[2]) try: current_movies = next(movies_r) except: stay = False while int(current_tags[0]) == i and stay2: if current_tags[1] in arr_movies_l: arr_liked_tags.append(current_tags[2]) else: arr_disliked_tags.append(current_tags[2]) try: current_tags = next(tags_r) except: stay2 = False users[str(i)] = User(arr_movies_l, arr_movies_d, arr_liked_tags, arr_disliked_tags) i = int(current_movies[0]) tags.close() movies.close() return users
def newFbUser(basic_info, user_pic, db, access_token): import json rand_username = ''.join( random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) user = User(basic_info['first_name'], basic_info['last_name'], basic_info['email'], 'facebook', rand_username, user_pic['data']['url']) db.session.add(user) data = db.session.commit() connection = Connections(basic_info['first_name'], basic_info['last_name'], basic_info['email'], 'facebook', user_pic['data']['url'], basic_info['id'], user.id, json.dumps(access_token)) db.session.add(connection) data = db.session.commit() if not data: json = user.token_construction() return json
def newTwitterUser(basic_info, db, tokens): import json name_lst = basic_info['name'].split(' ') first_name = name_lst[0] last_name = name_lst[1] user = User(first_name, last_name, basic_info['id_str'] + '@twit.com', 'twitter', basic_info['id_str'], basic_info['profile_image_url_https']) db.session.add(user) data = db.session.commit() connection = Connections(first_name, last_name, basic_info['id_str'] + '@twit.com', 'twitter', basic_info['profile_image_url_https'], basic_info['id_str'], user.id, json.dumps(tokens)) db.session.add(connection) data = db.session.commit() if not data: json = user.token_construction() return json
def reservation(): user = User(dbHost,dbPort) print ("USER: "******"POST": reservation = Reservation() #Get flight id from user reservation.flight_id = request.form.get("flight") #Get user_id from session reservation.user_id = user.uid #Get Base Price of flight flight = Flight() reservation.reservation_total = float(flight.getBasePrice(user,reservation.flight_id)) #Establish billing billing = Billing() billing.user_id = user.uid billing.billing_card_num = request.form["billingCardNum"] billing.billing_card_expr = datetime.strftime((datetime.strptime(request.form["billingCardDate"], '%m/%y')), "%Y-%m-%d") print(billing.billing_card_expr) billing.billing_card_csv = request.form["billingCardCSV"] billing.billing_firstname = request.form["billingCardFirst"] billing.billing_lastname = request.form["billingCardLast"] billing.billing_address = request.form["billingCardStreet"] billing.billing_city = request.form["billingCardCity"] billing.billing_state = request.form["billingCardState"] billing.billing_zip = request.form["billingCardZip"] status = billing.addBilling(user) if(status == "ERROR"): flash("ERROR: Problem adding payment method") return redirect("/") else: #Set reservation.billing_id after creating the billing above reservation.billing_id = status #Get User selected options option_list = [] option_total = 0.0 for i in range(1,7): opt_id = request.form.get("option"+str(i)) #print("opt_id: " + str(opt_id)) if(opt_id != None): option = Option() data = option.getOption(user,opt_id) option.option_id = data[0][0] option.option_name = data[0][1] option.option_price = data[0][2] #Set option total based on each option proce option_total = option_total + float(option.option_price) option_list.append(option) #Set new total based on base + option price reservation.reservation_total = reservation.reservation_total + float(option_total) #Calculate seat position based on remaining seats available reservation.reservation_seat=flight.getSeat(user,reservation.flight_id) #Add reservation reservation.reservation_id =reservation.addReservation(user) flash("Your reservation ID is: " + str(reservation.reservation_id)) #Add options selected to option list for i in range(0,len(option_list)): option.addUserOption(user,reservation.reservation_id,option_list[i].option_id) return redirect("/") else: flight_list = [] flights = Flight() flights = flights.getAllFlightsData(user) for i in range(0,len(flights)): flight = Flight() flight.flight_id = flights[i][0] flight.flight_source_city = flights[i][1] flight.flight_source_gate = flights[i][2] flight.flight_dest_id = flights[i][3] flight.flight_dest_gate = flights[i][4] flight.flight_rem_seats = flights[i][5] flight.flight_depart = flights[i][6] flight.flight_arrive = flights[i][7] flight.flight_base_price = flights[i][8] flight.plane_id = flights[i][9] #flights[i][10] - duplicate (plane_id) flight.airline_id = flights[i][11] flight.plane_model = flights[i][12] flight.plane_seats = flights[i][13] flight.airline_name = flights[i][14] #flights[i][15] - duplicate (source_id) flight.source_name = flights[i][16] flight.source_state = flights[i][17] flight.source_lat = flights[i][18] flight.source_long = flights[i][19] #flights[i][20] - duplicate (dest_id) flight.dest_name = flights[i][21] flight.dest_state = flights[i][22] flight.dest_lat = flights[i][23] flight.dest_long = flights[i][24] flight_list.append(flight) option_list = [] options = Option() options = options.getAllOptions(user) for i in range(0,len(options)): option = Option() option.option_id = options[i][0] option.option_name = options[i][1] option.option_price = options[i][2] option_list.append(option) return render_template("reservation.html", user=user,flight_list=flight_list,option_list=option_list)
from new_user import get_id, get_name, get_surname from Classes import User from form_Proton import get_email from form_Twitter import get_twitter_accounts accounts_number = int(input('Número de contas: ')) users_created = [] for i in range(0, accounts_number): user = User(get_id(), get_name(), get_surname()) get_email(user.username, user.password) get_twitter_accounts(user.username, user.email) print(user)
def setUp(self): random.seed(42) self.user = User("Lana")
if user[0] == event.user_id: thisUserIsSending = [event.user_id, user[1]] if request.lower() == "помощь": write_msg(event.user_id, messages.help) elif request.lower() == "отправитьЗапрос": if thisUserIsSending == False: users_sendingsZapros.append([event.user_id, 0]) write_msg(event.user_id, "Введите имя запроса:") elif thisUserIsSending[0] and thisUserIsSending[1] == 0: thisUserIsSending.append(request) write_msg(event.user_id, "Введите описание запроса:") thisUserIsSending[1] = 1 elif thisUserIsSending[0] and thisUserIsSending[1] == 1: thisUserIsSending.append(request) write_msg( event.user_id, "Чтобы сохранить запрос напишите да чтобы не отправлять напишите что-то другое:" ) thisUserIsSending[1] == 2 elif thisUserIsSending[0] and thisUserIsSending[1] == 2: if request.lower() == "Да": write_msg(event.user_id, "Запрос отправлен") art = Article() usr = User() art.newArticle(thisUserIsSending[1], thisUserIsSending[2], database=db, cursor=db.cursor(), user=usr) thisUserIsSending = []
def logout(): user = User(dbHost,dbPort) status = user.userLogOut() flash(status) return redirect("/")