User class

I added a classOf function that calculates your class of graduation and adds it to the dictionary

from werkzeug.security import generate_password_hash, check_password_hash
from datetime import date
import json

class User:    

    def __init__(self, name, uid, password, dob):
        self._name = name    # variables with self prefix become part of the object, 
        self._uid = uid
        self.set_password(password)
        self._dob = dob
        self._classOf = 0
    
    @property
    def name(self):
        return self._name
    
    # a setter function, allows name to be updated after initial object creation
    @name.setter
    def name(self, name):
        self._name = name
    
    # a getter method, extracts email from object
    @property
    def uid(self):
        return self._uid
    
    # a setter function, allows name to be updated after initial object creation
    @uid.setter
    def uid(self, uid):
        self._uid = uid
        
    # check if uid parameter matches user id in object, return boolean
    def is_uid(self, uid):
        return self._uid == uid
    
    # dob property is returned as string, to avoid unfriendly outcomes
    @property
    def dob(self):
        dob_string = self._dob.strftime('%m-%d-%Y')
        return dob_string
    
    # dob should be have verification for type date
    @dob.setter
    def dob(self, dob):
        self._dob = dob
        
    # age is calculated and returned each time it is accessed
    @property
    def age(self):
        today = date.today()
        return today.year - self._dob.year - ((today.month, today.day) < (self._dob.month, self._dob.day))
    
    # sets the class of graduation to 18 years after date of birth
    def classOf(self):
        self._classOf = self._dob.year + 18
        return self._classOf
    
    # dictionary is customized, removing password for security purposes
    @property
    def dictionary(self):
        dict = {
            "name" : self.name,
            "uid" : self.uid,
            "dob" : self.dob,
            "age" : self.age,
            "class of graduation" : self._classOf
        }
        return dict
    
    # update password, this is conventional setter
    def set_password(self, password):
        """Create a hashed password."""
        self._password = generate_password_hash(password, method='sha256')

    # check password parameter versus stored/encrypted password
    def is_password(self, password):
        """Check against hashed password."""
        result = check_password_hash(self._password, password)
        return result
        
    # output content using json dumps, this is ready for API response
    def __str__(self):
        return json.dumps(self.dictionary)
    
    # output command to recreate the object, uses attribute directly
    def __repr__(self):
        return f'User(name={self._name}, uid={self._uid}, password={self._password},dob={self._dob})'
    

if __name__ == "__main__":
    u1 = User(name='Ryan McWeeny', uid='Ryan', password='Password', dob=date(2006, 3, 27))
    u1.classOf()
    print("JSON ready string:\n", u1, "\n") 
    print("Raw Variables of object:\n", vars(u1), "\n") 
    print("Raw Attributes and Methods of object:\n", dir(u1), "\n")
    print("Representation to Re-Create the object:\n", repr(u1), "\n")
    #print("class of graduation: ", u1.classOf())
JSON ready string:
 {"name": "Ryan McWeeny", "uid": "Ryan", "dob": "03-27-2006", "age": 16, "class of graduation": 2024} 

Raw Variables of object:
 {'_name': 'Ryan McWeeny', '_uid': 'Ryan', '_password': 'sha256$O5cjuN0ytlf7K9Kw$977f8890f49ea3b092448b374406d28c56820045029827c51a8bb3961ce54e79', '_dob': datetime.date(2006, 3, 27), '_classOf': 2024} 

Raw Attributes and Methods of object:
 ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_classOf', '_dob', '_name', '_password', '_uid', 'age', 'classOf', 'dictionary', 'dob', 'is_password', 'is_uid', 'name', 'set_password', 'uid'] 

Representation to Re-Create the object:
 User(name=Ryan McWeeny, uid=Ryan, password=sha256$O5cjuN0ytlf7K9Kw$977f8890f49ea3b092448b374406d28c56820045029827c51a8bb3961ce54e79,dob=2006-03-27) 

CPT related class

This class is related to my create performance task where the user can input information about their account like their name, password, and email

from datetime import date
import json
    

class User:    
    def __init__(self, name, password, email):
        self._name = name    
        self._password = password
        self._email = email


    # getter method for username
    @property
    def name(self):
        return self._name
    
    # setter method for username
    @name.setter
    def name(self, username):
        self._name = name
        
    # getter method for password
    @property
    def password(self):
        return self._password
    
    # setter method for password
    @password.setter
    def password(self, password):
        self._password = password
  
    # getter method for email
    @property
    def email(self):
        return self._email
    
    # setter method for email
    @email.setter
    def email(self, email):
        self._email = email
    
    # dictionary is customized, removing password for security purposes
    @property
    def dictionary(self):
        dict = {
            "name" : self.name,
            "email" : self.email,
        }
        return dict
  
    # output content using json dumps, this is ready for API response
    def __str__(self):
        return json.dumps(self.dictionary)
    
    # output command to recreate the object, uses attribute directly
    def __repr__(self):
        return f'User(username={self._name}, password={self._password},email={self._email})'
    

if __name__ == "__main__":
    
    u1 = User(name='Ryan', password='Password', email = 'ryanrob327@gmail.com')
    
    print("JSON ready string:\n", u1, "\n") 
    print("Raw Variables of object:\n", vars(u1), "\n") 
    print("Raw Attributes and Methods of object:\n", dir(u1), "\n")
    print("Representation to Re-Create the object:\n", repr(u1), "\n") 
JSON ready string:
 {"name": "Ryan", "email": "ryanrob327@gmail.com"} 

Raw Variables of object:
 {'_name': 'Ryan', '_password': 'Password', '_email': 'ryanrob327@gmail.com'} 

Raw Attributes and Methods of object:
 ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_email', '_name', '_password', 'dictionary', 'email', 'name', 'password'] 

Representation to Re-Create the object:
 User(username=Ryan, password=Password,email=ryanrob327@gmail.com)