The ATM-3 of Python basics

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.