forked from jzamora5/AirBnB_clone_v3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.py
executable file
·37 lines (32 loc) · 1.11 KB
/
user.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/python3
""" holds class User"""
import models
from models.base_model import BaseModel, Base
from os import getenv
import sqlalchemy
from sqlalchemy import Column, String
from sqlalchemy.orm import relationship
from hashlib import md5
class User(BaseModel, Base):
"""Representation of a user """
if models.storage_t == 'db':
__tablename__ = 'users'
email = Column(String(128), nullable=False)
password = Column(String(128), nullable=False)
first_name = Column(String(128), nullable=True)
last_name = Column(String(128), nullable=True)
places = relationship("Place", backref="user")
reviews = relationship("Review", backref="user")
else:
email = ""
password = ""
first_name = ""
last_name = ""
def __init__(self, *args, **kwargs):
"""initializes user"""
super().__init__(*args, **kwargs)
def __setattr__(self, name, value):
"""sets a password with md5 encryption"""
if name == "password":
value = md5(value.encode()).hexdigest()
super().__setattr__(name, value)