def insert_user(database, payload):

        cursor = connection_db(database)
        if cursor[1] == 401:
            print(cursor[0])
            return cursor[0]

        try:
            sql = f"select * from users where username='******'username']}'"
            user_exists = cursor[0].execute(sql)

            if not user_exists:
                import password
                passwd = password.create_password(16)
                password = password.TrataHash.insere_hash(passwd)

                val = (payload['username'], payload['email'], str(password))
                sql = f"insert into users (username, email, password) values {val}"

                cursor[0].execute(sql)
                cursor[1].commit()
                cursor[1].close()
                print(
                    f"Record ID {cursor[0].lastrowid} successfully inserted. Password {passwd}",
                )

            else:
                print(f'User {payload["username"]} already exists.')
                return {'msg': f'User {payload["username"]} already exists.'}

        except pymysql.err.InternalError:
            cursor[1].rollback()
            cursor[1].close()
            print('Failed to insert the record.')
            return {'erro': 'Failed to insert the record.'}
def create_users():
    abouts = [
        'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscin.',
        'I love jujubes cotton candy sweet liquorice jujubes. Donut candy jelly gingerbread muffin carrot cake pastry marshmallow topping. Sweet roll jelly beans lemon drops jelly beans icing tiramisu cake pie. Jujubes cookie croissant gingerbread. Wafer apple pie jelly beans candy canes gingerbread tiramisu donut lollipop apple pie. Pudding cake gummies I love chupa chups tart cotton candy jujubes lollipop. Cake chocolate wafer brownie. Halvah pudding chocolate tootsie roll I love cake icing croissant candy canes. Biscuit sesame snaps lemon drops sweet pudding. Donut chocolate cake toffee topping ice cream. Biscuit pastry candy icing tootsie roll. Croissant chupa chups carrot cake carrot cake. Lollipop caramels tiramisu jelly beans.',
        'Zombies reversus ab inferno, nam malum cerebro. De carne animata corpora quaeritis. Summus sit​​, morbo vel maleficia? De Apocalypsi undead dictum mauris. Hi mortuis soulless creaturas, imo monstra adventus vultus comedat cerebella viventium. Qui offenderit rapto, terribilem incessu. The voodoo sacerdos suscitat mortuos comedere carnem. Search for solum oculi eorum defunctis cerebro. Nescio an Undead zombies. Sicut malus movie horror.',
        'Don\'t be too proud of this technological terror you\'ve constructed. The ability to destroy a planet is insignificant next to the power of the Force. As you wish. Look, I can take you as far as Anchorhead. You can get a transport there to Mos Eisley or wherever you\'re going.'
    ]

    emails = [
        '*****@*****.**',
        '*****@*****.**',
        '*****@*****.**',
        '*****@*****.**',
    ]

    first_names = [
        'Roman',
        'Andrew',
        'Chay',
        'Spencer',
        'Jaydan',
    ]

    last_names = ['Carter', 'Hunt', 'Williams', 'Parker', 'Hamilton']
    usernames = ['a', 'b', 'c', 'd']

    users = []
    for i in range(0, 4):
        print("Created user: "******"b", "c"]
            email=emails[i],
            facebook_link='/',
            first_name=first_names[i],
            gender='male',
            last_name=last_names[i],
            linkedin_link='/',
            password=salted_password,
            pininterest_link='/',
            profile_pic='userprofile.png',
            salt=new_salt,
            snapchat_link='/',
            twitter_link='/',
            #tags = ['a', 'ghfgh', 'ghfhgfh']
            username=usernames[i],
        )

        session.add(user)
        session.commit()

    print("Finished making users")
Example #3
0
 def dump(self,*args):
     f = None
     if not args:
         f = open(datetime.now().strftime("%d.%m.%Y.-%H:%M:%S"),"wb")
     else:
         f = open(args[0],"wb")
     writestring = "<ID>\t<DATE>\t<TIME>\t<TYPE>\t<CONTENT>\n"
     for i in self.notebook:
         for j in i:
             writestring+=j+"\t"
         writestring+="\n"
     f.write(AESCipher(password.create_password()).encrypt(writestring))
     f.close()
def register():
    if request.method == 'POST':
        # validate form
        username = request.form['username']
        first_name = request.form['first_name']
        last_name = request.form['last_name']
        email = request.form['email']
        password1 = request.form['pw']
        password2 = request.form['pw1']

        if password1 == password2:
            print("Passwords Match")
        
            # create salt
            new_salt = make_salt()
            print(new_salt)
        
            # create salted password
            salted_password = create_password(password1, new_salt)
            print(salted_password)
            start_up_blog = Blog(title="My first blog", body="Your blog is a little lonely", date_uploaded=datetime.now(), is_public= False)

            new_user = Users(username=username, first_name=first_name, last_name=last_name, email=email, password=salted_password, salt=new_salt, gender='male', blog=start_up_blog)
            # create a sample blog
            #blog=blog1

            session.add(new_user)
            session.commit()
            redirect('/')

        return render_template("register.html")

    else:
       # {% if current_user.is_authenticated %}
       #     Hi {{ current_user.name }}!
       #     {% endif %}
        return render_template("register.html")
Example #5
0
 def set_salted_password(self):
     """SETS salt password."""
     # create salted password
     self.password = create_password(self.password, self.salt)
     print(self.password)
Example #6
0
# session.rollback()
session = DBSession()

# TEST 1 ADD MULTIPLE BLOGS TO A USER

default_body = '''
Tumeric austin adaptogen edison bulb irony cornhole put a bird on it, four dollar toast kinfolk cardigan affogato hell of chartreuse raw denim. Normcore etsy la croix tattooed meggings edison bulb hammock hella. Skateboard hexagon salvia taiyaki prism, letterpress godard blog gluten-free twee. Occupy skateboard YOLO, intelligentsia forage pinterest kombucha snackwave vexillologist glossier readymade. Raw denim etsy health goth hammock coloring book everyday carry humblebrag pickled try-hard unicorn. Blue bottle disrupt mumblecore viral meggings before they sold out snackwave knausgaard put a bird on it. Venmo tbh semiotics readymade, butcher leggings blog listicle activated charcoal farm-to-table hoodie. Roof party whatever celiac art party, quinoa tbh you probably haven't heard of them wayfarers blue bottle tacos. Kogi snackwave letterpress truffaut, vegan ramps ugh copper mug freegan retro yuccie small batch flannel fingerstache. Keffiyeh af biodiesel wayfarers semiotics godard. Man braid skateboard gluten-free four loko enamel pin tumeric.
'''

i = 0
# CREATE USERS FIRST THEN DD BLOGS TO THEM

new_salt = make_salt()

# create salted password
salted_password = create_password('a', new_salt)

user1 = Users(
    about="ghjhjghjghjgjhg hj ghjgjhgjhgjhgjhgjhg",
    #blogs_following = ["b", "c"]
    email="*****@*****.**",
    facebook_link='/',
    first_name='hgjhghjgjhg',
    gender='male',
    last_name='hgujgfhfhg',
    linkedin_link='/',
    password=salted_password,
    pininterest_link='/',
    profile_pic='userprofile.png',
    salt=new_salt,
    snapchat_link='/',