Import JSON
Import OS
Import Sys
Import time
Import accounts
Import Db_handler
Base_dir = Os.path.dirname (Os.path.dirname (Os.path.abspath (__file__)))
Sys.path.append (Base_dir)
From conf import settings
Import accounts
Import Logger
‘‘‘
This module is auth, user authentication, wherein the adorner is checking whether the account is frozen
‘‘‘
def Lock_judge (func):
‘‘‘
This method is implemented to determine if the account is frozen
:p Aram Func: Method for entering the parameter
: return:
‘‘‘
def lock_account (User_data):
Print (User_data)
Func (User_data)
Acc_account = Accounts.load (user_data["Account_data" ["Account"])
If acc_account["status"] = = "Lock":
Exit ("The account has been frozen")
Return User_data
Return Lock_account
def acc_auth (Account,password):
‘‘‘
The module realizes the user login information
:p Aram Account: credit card accounts
:p Aram Password: credit card password
: return: Returns user information
‘‘‘
Db_path = Db_handler.db_handler (settings. DATABASE)
Db_file = "%s\%s.json"% (Db_path,account)
If Os.path.isfile (db_file):
With open (Db_file) as F:
Account_data = Json.load (f)
If account_data["pass"] = = password:
Exp_time_stamp = Time.mktime (Time.strptime (account_data["engine"], "%y-%m-%d"))
If Time.time () > Exp_time_stamp:
Print ("The account%s has expired, please replace the card"%account)
Else
Return Account_data
@lock_judge
def acc_login (User_data):
‘‘‘
This function is used for user input user name, password, call authentication function, set user login status data after successful authentication
:p Aram User_data:
: Return User_data
‘‘‘
Count = 0
While user_data["Is_auth") is False and Count < 3:
account = input ("Please enter your credit card ID >>>")
Password = input ("Please enter credit card password >>>")
Auth = Acc_auth (Account,password)
If Auth:
user_data["Is_auth"] = True
user_data["account_id"] = Account
user_data["account_data"] = Auth
Info = "%s has landed credit card center"% account
Logger.write_logger (Settings.logfile1, info)
Return User_data
Count + = 1
The ATM-3 of Python basics