Exemplo n.º 1
0
 def login(self, username, password):
     if ((username != '') and (password != '')):
         db = dbFunctions.db_class()
         table = "login"
         fields = ["id","password"]
         condition = "WHERE username='******'".format(username)
         res = db.select_from_table(table, fields, condition)[0]
         # print(res)
         if len(res) == 0:
             return {"code": "01", "msg": "User account does not exist"}
         else:
             # all action goes here!!!
             if sha256_crypt.verify(password, res['password']):
                 table     = "login"
                 fields    = {"status": "1", "last_login": "******"}
                 condition = "WHERE username='******'".format(username)
                 update_login = db.update_table(table, fields, condition)
                 # condition = "WHERE tbl_user_id='{0}'".format(res['id'])
                 # update_login = db.update_table(table, fields, condition)
                 db.closeInstanceConnection()
                 if update_login == True:
                     # res[0]['last_login'] = res[0]['last_login'].strftime("%Y-%m-%d %H:%M:%S")
                     return {"code": "00", "msg": res}
                 else:
                     return {"code": "01", "msg": "Failed to update tbl_login"}
             else:
                 return {"code": "01", "msg": "Invalid username or password"}
     else:
         return {"code": "01", "msg": "username or password cannot be empty"}
Exemplo n.º 2
0
 def log_out(self, username):
     db = dbFunctions.db_class()
     res = db.select_from_table("login", ["id"], "WHERE username='******'".format(username))
     table = "login"
     fields = {"status": "0"}
     condition = "WHERE id='{0}'".format(res[0]['id'])
     update_login = db.update_table(table, fields, condition)
     db.closeInstanceConnection()
     if update_login == True:
         return {"code": "00", "msg": "You are logged out"}
     else:
         return {"code": "01","msg": "An error occured while logging out"}