Advertisement
Guest User

Untitled

a guest
Nov 29th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.54 KB | None | 0 0
  1. '''
  2. Creating blog
  3. Homework for python-courses
  4. '''
  5.  
  6. import pymysql.cursors
  7. import hashlib
  8.  
  9.  
  10. class BlogApp():
  11.     def add_new_user(self, user_username, user_email, user_password):
  12.         connection = pymysql.connect(host='localhost',
  13.                                      user='BlogApp_User',
  14.                                      password='BlogApp_Password',
  15.                                      db='BlogApp',
  16.                                      charset='utf8mb4',
  17.                                      cursorclass=pymysql.cursors.DictCursor)
  18.  
  19.         salt = b'some_salt'
  20.         hash_obj = hashlib.md5()
  21.         hash_obj.update(salt)
  22.         hash_obj.update(user_password.encode('utf-8'))
  23.  
  24.         try:
  25.             with connection.cursor() as cursor:
  26.                 sql = "INSERT INTO User (Username, Email, Password) VALUES (%s, %s, %s)"
  27.                 cursor.execute(sql, (user_username, user_email, hash_obj.digest()))
  28.             connection.commit()
  29.  
  30.             with connection.cursor() as cursor:
  31.                 sql = "SELECT UserID, Username, Password FROM User WHERE Email=%s"
  32.                 cursor.execute(sql, user_email)
  33.                 result = cursor.fetchone()
  34.                 print(result)
  35.         finally:
  36.             connection.close()
  37.  
  38.     def authentication_user(self, user_email, user_password):
  39.         connection = pymysql.connect(host='localhost',
  40.                                      user='BlogApp_User',
  41.                                      password='BlogApp_Password',
  42.                                      db='BlogApp',
  43.                                      charset='utf8mb4',
  44.                                      cursorclass=pymysql.cursors.DictCursor)
  45.  
  46.         try:
  47.             with connection.cursor() as cursor:
  48.                 sql = "INSERT INTO User (Username, Email, Password) VALUES (%s, %s, %s)"
  49.  
  50.                 cursor.execute(sql, (user_email, user_password))
  51.         finally:
  52.             connection.close()
  53.  
  54.         return token_status
  55.  
  56.     def get_users_list(self):
  57.         pass
  58.  
  59.     def get_auth_user_blogs_list(self):
  60.         pass
  61.  
  62.     def get_blogs_list(self):
  63.         pass
  64.  
  65.     def create_blog(self):
  66.         pass
  67.  
  68.     def edit_blog(self):
  69.         pass
  70.  
  71.     def delete_blog(self):
  72.         pass
  73.  
  74.     def create_post(self):
  75.         pass
  76.  
  77.     def edit_post(self):
  78.         pass
  79.  
  80.     def delete_post(self):
  81.         pass
  82.  
  83.     def add_comment(self):
  84.         pass
  85.  
  86.     def get_user_comments(self):
  87.         pass
  88.  
  89.  
  90. a = BlogApp()
  91. a.add_new_user('bratishka', 'razrazraz', 'vilka')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement