Example #1
0
def signup():
    # check if form was submitted
    form = request.form.keys()
    if 'username' in form and 'password' in form and 'password_repeat' in form:

        # read the data from the form
        username = request.form['username']
        password = request.form['password']
        password_repeat = request.form['password_repeat']

        # make sure that the form data is valid
        valid = True

        if not password == password_repeat:  # if they typed in a different password in repeat
            flash('Passwords do not match!', 'danger')
            valid = False

        if not User.username_avaliable(
                username):  # checks database if username already exists
            flash('Username already taken!', 'danger')
            valid = False

        if valid:
            User.new_user(username, password)
            flash("Account successfully created!", "success")
            return redirect('login')
    return render_template('signup.html', title='Sign Up')
Example #2
0
def populate():
    for x in range(50):
        gen = r.choice(["Male", "Female"])
        format = lambda input : input if len(f"{input}") > 1 else f"0{input}"
        date = f"{r.randint(2000, 2019)}-{format(r.randint(1, 12))}-{format(r.randint(10, 28))}"
        #username = ""
        #for i in range(10):
        #    username += r.choice(string.ascii_lowercase)
        User.new_user(x, "", names.get_full_name(gender=gen.lower()), gen, r.choice(["Both", "Males", "Females"]), date, "dummy email", "dummy phone number", "lorem ipsum shut up", f"{r.uniform(35, 45)},{r.uniform(-80, 70)}")
Example #3
0
def login():
    # check if form was submitted
    if (current_user()):
        return redirect('/welcome')
    form = request.form.keys()
    if 'username' in form and 'password' in form:
        # read the data from the form
        # we can use [] now since we know the key exists
        username = request.form['username']
        password = request.form['password']

        # make sure that the form data is valid
        valid = True

        to_login = User.get_user(username)  # gets user object using username

        auth_valid = True

        #TODO:Update the 'danger' and 'success' tags for foundation (not bootstrap)

        if to_login is None:  # if a user with that username doesn't exist
            flash('That username does not belong to a registered account!',
                  'danger')
            auth_valid = False
        elif to_login.password != password:  # if they typed in the wrong password
            flash('Incorrect password!', 'danger')
            auth_valid = False

        if valid and auth_valid:
            session['user_id'] = to_login.id
            message = 'Successfully logged in'
            flash(message, 'success')
            return redirect(url_for('welcome'))
    return render_template("login.html", title="Log In")
Example #4
0
    def loop(self):
        while self.running:
            for generic in self.network_handle.get_generics():
                if generic["type"] == "new_user":
                    self.network_handle.reply(generic, identify_prompt())
                elif generic["type"] == "identify":
                    self.users.append(
                        User(generic["name"],
                             (generic["socket"], generic["address"])))
                    self.network_handle.add_user(self.users[-1])
                    self.network_handle.broadcast(
                        connect_packet(generic["name"]))

            disconnected = []

            for user in self.users:
                for message in self.network_handle.get_unreads(user):
                    if message["type"] == "message":
                        if not self.user_called(message["target"]):
                            self.network_handle.send(
                                user,
                                message_packet(
                                    "Server",
                                    "User Not Found. Message not sent"))
                        else:
                            self.network_handle.send(
                                self.user_called(message["target"]),
                                message_packet(user.name, message["content"]))
                            self.network_handle.send(
                                user,
                                message_packet(user.name, message["content"]))
                    elif message["type"] == "disconnect":
                        self.network_handle.broadcast(
                            disconnect_packet(user.name))
                        self.network_handle.disconnect(user)
                        disconnected.append(user)
                    elif message["type"] == "queue":
                        self.queue.append((user, message["deck"]))
                        # TODO at this point, verify deck.
                        self.network_handle.send(user, queue_enter())
                    elif message["type"] == "game_action":
                        if user in self.instances:
                            if user is self.instances[user].active_player.user:
                                self.instances[user].tick(message)
                            else:
                                self.network_handle.send(
                                    user, NOT_ACTIVE_PLAYER_ERROR)

            if len(self.queue) >= 2:
                self.start_instance()

            for user in disconnected:
                self.users.remove(user)

            for user, game in self.instances.items():
                if game.over:
                    for player in game.players:
                        del self.instances[player]
Example #5
0
def pending_requests():
    '''This function handles the requests that the user has sent to other users, stores and displays them'''
    recieved = current_user().sent_pending()
    counter = 0
    searchMatches = []
    try:
        for person in recieved:
            if (counter > 45):
                break
            info = []
            userDOB = current_user().dob.split("-")
            this = util.matchmaker.Person(userDOB[0], userDOB[1], userDOB[2])
            otherDOB = User.query_by_id(person, "dob").split("-")
            other = util.matchmaker.Person(
                otherDOB[0], otherDOB[1],
                otherDOB[2])  #Person object for other user
            other_user = User(person)
            info.append(other_user.name)
            info.append(
                round((util.matchmaker.personalityCompatibility(this, other)) *
                      100))
            info.append(
                round(
                    (util.matchmaker.sexualCompatibility(this, other)) * 100))
            info.append(
                round(
                    (util.matchmaker.inLawsCompatibility(this, other)) * 100))
            info.append(
                round((util.matchmaker.futureSuccess(this, other)) * 100))
            info.append(other_user.bio)
            info.append(person)
            info.append(round(current_user().user_dist(person)))
            info.append(other_user.get_starsign().capitalize())
            info.append(starsign_compatibilites[current_user().get_starsign()][
                other_user.get_starsign()])
            counter += 1
            searchMatches.append(info)
    except Exception as e:
        print(e)
    session["prev_url"] = "/requests/pending"
    return render_template("pending_requests.html", listings=searchMatches)
Example #6
0
def matchmaking():
    '''The matchmaking function measures compatibility with other users in the database using available user data,
    and displays the data'''
    # return f"{current_user().unmatched()}"
    counter = 0
    searchMatches = []
    print(current_user().unmatched())
    for person in current_user().unmatched():
        if (counter > 45):
            break
        # try:
        info = []
        userDOB = current_user().dob.split("-")
        this = util.matchmaker.Person(userDOB[0], userDOB[1], userDOB[2])
        otherDOB = User.query_by_id(person, "dob").split("-")
        other = util.matchmaker.Person(
            otherDOB[0], otherDOB[1],
            otherDOB[2])  #Person object for other user
        other_user = User(person)
        info.append(other_user.name)
        info.append(
            round(
                (util.matchmaker.personalityCompatibility(this, other)) * 100))
        info.append(
            round((util.matchmaker.sexualCompatibility(this, other)) * 100))
        info.append(
            round((util.matchmaker.inLawsCompatibility(this, other)) * 100))
        info.append(round((util.matchmaker.futureSuccess(this, other)) * 100))
        info.append(other_user.bio)
        info.append(person)
        info.append(round(current_user().user_dist(person)))
        info.append(other_user.get_starsign().capitalize())
        info.append(starsign_compatibilites[current_user().get_starsign()][
            other_user.get_starsign()])
        counter += 1
        searchMatches.append(info)
        # except Exception as e:
        #     print(e)
    searchMatches.sort(key=lambda x: x[7])
    session["prev_url"] = "/hotsingles"
    return render_template("matchmaking.html", listings=searchMatches)
Example #7
0
async def bw(ctx, *args):
    rows = []
    header = 'STARS IGN FKDR WR WS'.split()
    rows.append(header)
    for arg in args:
        user = User(arg)
        row = [
            f'[{"?" if user.bw_stars is None else user.bw_stars}✫]', user.ign,
            utils.ratio_str(user.bw_fkills, user.bw_fdeaths),
            utils.prop_str(user.bw_wins, user.bw_losses), user.bw_winstreak
        ]
        rows.append(row)
    await ctx.send(utils.tabulate(rows))
Example #8
0
async def bg(ctx, *args):
    rows = []
    header = 'TITLE,IGN,SOLO WR,2s WR,4s WR,WS'.split(',')
    rows.append(header)
    for arg in args:
        user = User(arg)
        row = [
            f'[{"?" if user.bg_title is None else user.bg_title}]', user.ign,
            utils.ratio_str(user.bg_wins1, user.bg_losses1),
            utils.ratio_str(user.bg_wins2, user.bg_losses2),
            utils.ratio_str(user.bg_wins4, user.bg_losses4), user.bg_winstreak
        ]
        rows.append(row)
    await ctx.send(utils.tabulate(rows))
Example #9
0
def authenticate():
    '''Authentication function to log stored users in'''
    #Getting data inputting in login form
    username = request.form["username"]
    password = request.form["pass"]
    #Getting username from database
    user_auth = User.authenticate_user(username, password)
    if not user_auth:
        return redirect("/login")
    else:
        #Passed all checks, good to login
        session["username"] = username
        print(session)
        print(current_user().id)
        current_user().update_location()
    if ("prev_url" in session):
        return redirect(session.pop("prev_url"))
    return redirect("/welcome")
Example #10
0
def show_post(qaf_id, post_id):
    if current_user() == None:
        flash('You must be logged in to access this page', 'warning')
        return redirect(url_for('login'))
    if ('comment' in request.form):
        entry = request.form
        Comment.new_comment(current_user().id, entry['comment'], post_id,
                            qaf_id)
    if ('post_id' in request.form):
        return redirect(url_for('edit_title', post=request.form['post_id']))
    if ('comment_id' in request.form):
        return redirect(
            url_for('edit_comment', comment=request.form['comment_id']))

    post = Post(post_id)
    comments = post.get_comments()
    return render_template('post.html',
                           title=post.title,
                           post=post,
                           comments=comments,
                           author=User(post.author_id).username)
Example #11
0
def createAccount():
    '''When you create an account, you have to submit a bunch of personal information'''
    if (request.form["password"] != request.form["password-confirm"]):
        return redirect("/create")
    for data in request.form:
        if (len(request.form[data]) == 0):
            print("bad")
            flash("Please enter a value in every field")
            return redirect("/create")
    loc_info = api.json2dict(api.ip_location(
        api.user_ip()))  #current ip location
    if not User.new_user(request.form["username"], request.form["password"],
                         request.form["name"], request.form["gender"],
                         request.form["preference"], request.form["dob"],
                         request.form["email"], request.form["phone"],
                         request.form["bio"],
                         f"{loc_info['lat']},{loc_info['lon']}"):
        return redirect("/create")
    session["username"] = request.form["username"]
    if ("prev_url" in session):
        return redirect(session.pop("prev_url"))
    return redirect("/welcome")
Example #12
0
def accepted_requests():
    '''This function handles requests from the user that have been accepted from another user, stores and displays them'''
    recieved = current_user().accepted()
    counter = 0
    searchMatches = []
    try:
        for person in recieved:
            if (counter > 45):
                break
            info = []
            match = User(person)
            info.append(match.name)
            info.append(match.email)
            info.append(match.phone_number)
            info.append(match.bio)
            info.append(match.location)
            info.append(person)
            info.append(round(current_user().user_dist(person)))
            counter += 1
            searchMatches.append(info)
    except Exception as e:
        print(e)
    session["prev_url"] = "/requests/accepted"
    return render_template("accepted_requests.html", listings=searchMatches)
Example #13
0
def before_request():
    g.user = None
    if 'user_token' in session:
        g.user = User(session['user_token'])
Example #14
0
def current_user():
    if 'username' in session:
        return User(User.get_by_username(session['username']))
Example #15
0
def current_user():
    if 'user_id' in session:
        return User(session['user_id'])
    return None
Example #16
0
def load_user(user_id):
    # reload config in case the user info changed
    reload_config()
    return User()