forked from feliciahsieh/AirBnB_clone_v3
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuser.py
executable file
·47 lines (42 loc) · 1.42 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
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python3
""" holds class User"""
import hashlib
import models
from models.base_model import BaseModel, Base
from os import getenv
from sqlalchemy.orm import relationship
from sqlalchemy import Column, String
class User(BaseModel, Base):
"""Representation of a user """
if getenv('HBNB_TYPE_STORAGE') == 'db':
__tablename__ = 'users'
email = Column(String(128),
nullable=False)
_password = Column('password',
String(128),
nullable=False)
first_name = Column(String(128),
nullable=True)
last_name = Column(String(128),
nullable=True)
places = relationship("Place",
backref="user",
cascade="all, delete-orphan")
reviews = relationship("Review",
backref="user",
cascade="all, delete-orphan")
else:
email = ""
_password = ""
first_name = ""
last_name = ""
def __init__(self, *args, **kwargs):
"""initializes user"""
super().__init__(*args, **kwargs)
@property
def password(self):
return self._password
@password.setter
def password(self, pwd):
"""hashing password values"""
self._password = hashlib.md5(pwd.encode()).hexdigest()