Example #1
0
def refresh_tabard():
    request = requests.get(url=wowAPI.guild_info_uri + wowAPI.key)
    content = json.loads(request.text)
    tabard = {
        'emblem': content['emblem']['icon'],
        'border': content['emblem']['border'],
        'icon color': content['emblem']['iconColorId'],
        'bg color': content['emblem']['backgroundColorId'],
        'border color': content['emblem']['borderColorId'],
        'faction': 'Alliance'
    }
    cnx = db.get_connection()
    cursor = cnx.cursor()
    cursor.execute("DELETE FROM GuildTabard")
    cursor.execute((
        "INSERT INTO GuildTabard (Icon, Border, IconColor, BgColor, BorderColor, faction) VALUES (%(emblem)s, %(border)s, %(icon color)s, %(bg color)s, %(border color)s, %(faction)s)"
    ), tabard)
    cnx.commit()
    cursor.close()
    emblem = str(content['emblem']['icon']).zfill(
        2) if content['emblem']['icon'] < 10 else content['emblem']['icon']
    border = str(content['emblem']['border']).zfill(
        2) if content['emblem']['border'] < 10 else content['emblem']['border']
    urllib_request.urlretrieve(
        "{}emblem_{}.png".format(wowAPI.tabard_uri, emblem),
        "guild_app/static/images/guild/tabards/emblem_{}.png".format(emblem))
    urllib_request.urlretrieve(
        "{}border_{}.png".format(wowAPI.tabard_uri, border),
        "guild_app/static/images/guild/tabards/border_{}.png".format(border))
    return redirect("/tabard")
Example #2
0
 def __call__(self, form, field):
     cnx = db.get_connection()
     cursor = cnx.cursor(buffered=True)
     cursor.execute(("SELECT ID FROM Users WHERE Username = %s"),
                    (field.data, ))
     if cursor.rowcount == 0:
         cursor.close()
         cnx.close()
         raise ValidationError(self.message)
     cursor.close()
     cnx.close()
Example #3
0
def login():
    form = forms.LoginForm()
    if form.validate_on_submit():
        cnx = db.get_connection()
        cursor = cnx.cursor()
        cursor.execute(
            ("SELECT Username, Role FROM Users WHERE Username = %s"),
            (form.username.data, ))
        result = cursor.fetchone()
        flask_session['username'] = result[0]
        flask_session['role'] = result[1]
        cursor.close()
        cnx.close()
        return redirect("/index")
    return render_template('login.html', form=form)
Example #4
0
 def __call__(self, form, field):
     cnx = db.get_connection()
     cursor = cnx.cursor(buffered=True)
     data = field.data.split('-')
     if len(data) != 2:
         raise ValidationError(self.message)
     name = data[0]
     realm = data[1]
     cursor.execute(
         ("SELECT ID FROM Characters WHERE Name = %s AND Realm = %s"),
         (name, realm))
     if cursor.rowcount != 0:
         cursor.close()
         cnx.close()
         raise ValidationError(self.message)
     cursor.close()
     cnx.close()
Example #5
0
def register():
    form = forms.RegistrationForm()
    if form.validate_on_submit():
        salt = ''.join(choice(ascii_uppercase) for i in range(10))
        t_sha = hashlib.sha512()
        t_sha.update((form.password.data + salt).encode('utf-8'))
        hashed_password = base64.urlsafe_b64encode(t_sha.digest())
        cnx = db.get_connection()
        cursor = cnx.cursor()
        name, realm = form.username.data.split('-')
        user_data = {
            'username': form.username.data,
            'password': hashed_password,
            'salt': salt,
            'role': 1
        }
        cursor.execute((
            "INSERT INTO Users (Username, PasswordHash, Salt, Role) VALUES (%(username)s, %(password)s, %(salt)s, %(role)s)"
        ), user_data)
        character_data = {'name': name, 'realm': realm}
        cursor.execute((
            "INSERT INTO Characters (Name, Realm) VALUES (%(name)s, %(realm)s)"
        ), character_data)
        cnx.commit()
        cursor.execute(("SELECT ID FROM Users WHERE Username = %s"),
                       (form.username.data, ))
        user_id = cursor.fetchone()[0]
        cursor.execute(
            ("SELECT ID FROM Characters WHERE Name = %s AND Realm = %s"),
            (name, realm))
        character_id = cursor.fetchone()[0]
        cursor.execute(("UPDATE Users SET MainChar = %s WHERE ID = %s"),
                       (character_id, user_id))
        cursor.execute(("UPDATE Characters SET UserID = %s WHERE ID = %s"),
                       (user_id, character_id))
        cnx.commit()
        cursor.close()
        cnx.close()
        return redirect("/index")
    return render_template('register.html', form=form)
Example #6
0
 def __call__(self, form, field):
     cnx = db.get_connection()
     cursor = cnx.cursor(buffered=True)
     cursor.execute(
         ("SELECT PasswordHash, Salt FROM Users WHERE Username = %s"),
         (form.username.data, ))
     if cursor.rowcount == 0:
         cursor.close()
         cnx.close()
         raise ValidationError(self.message)
     result = cursor.fetchone()
     hash = result[0]
     salt = result[1]
     t_sha = hashlib.sha512()
     t_sha.update((field.data + salt).encode('utf-8'))
     hashed_password = base64.urlsafe_b64encode(t_sha.digest())
     if hash != hashed_password.decode('utf-8'):
         cursor.close()
         cnx.close()
         raise ValidationError(self.message)
     cursor.close()
     cnx.close()