Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Creating blog
- Homework for python-courses
- '''
- import pymysql.cursors
- import hashlib
- class BlogApp():
- def add_new_user(self, user_username, user_email, user_password):
- connection = pymysql.connect(host='localhost',
- user='BlogApp_User',
- password='BlogApp_Password',
- db='BlogApp',
- charset='utf8mb4',
- cursorclass=pymysql.cursors.DictCursor)
- salt = b'some_salt'
- hash_obj = hashlib.md5()
- hash_obj.update(salt)
- hash_obj.update(user_password.encode('utf-8'))
- try:
- with connection.cursor() as cursor:
- sql = "INSERT INTO User (Username, Email, Password) VALUES (%s, %s, %s)"
- cursor.execute(sql, (user_username, user_email, hash_obj.digest()))
- connection.commit()
- with connection.cursor() as cursor:
- sql = "SELECT UserID, Username, Password FROM User WHERE Email=%s"
- cursor.execute(sql, user_email)
- result = cursor.fetchone()
- print(result)
- finally:
- connection.close()
- def authentication_user(self, user_email, user_password):
- connection = pymysql.connect(host='localhost',
- user='BlogApp_User',
- password='BlogApp_Password',
- db='BlogApp',
- charset='utf8mb4',
- cursorclass=pymysql.cursors.DictCursor)
- try:
- with connection.cursor() as cursor:
- sql = "INSERT INTO User (Username, Email, Password) VALUES (%s, %s, %s)"
- cursor.execute(sql, (user_email, user_password))
- finally:
- connection.close()
- return token_status
- def get_users_list(self):
- pass
- def get_auth_user_blogs_list(self):
- pass
- def get_blogs_list(self):
- pass
- def create_blog(self):
- pass
- def edit_blog(self):
- pass
- def delete_blog(self):
- pass
- def create_post(self):
- pass
- def edit_post(self):
- pass
- def delete_post(self):
- pass
- def add_comment(self):
- pass
- def get_user_comments(self):
- pass
- a = BlogApp()
- a.add_new_user('bratishka', 'razrazraz', 'vilka')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement