forked from alexaorrico/AirBnB_clone_v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.py
executable file
·51 lines (45 loc) · 1.46 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
48
49
50
51
#!/usr/bin/python3
"""
User Class from Models Module
"""
import os
from models.base_model import BaseModel, Base
from sqlalchemy.orm import relationship
from sqlalchemy import Column, Integer, String, Float
from hashlib import md5
storage_type = os.environ.get('HBNB_TYPE_STORAGE')
class User(BaseModel, Base):
"""User class handles all application users"""
if storage_type == "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='delete')
reviews = relationship('Review', backref='user', cascade='delete')
else:
email = ''
password = ''
first_name = ''
last_name = ''
def __init__(self, *args, **kwargs):
"""
initialize User Model, inherits from BaseModel
"""
super().__init__(*args, **kwargs)
@property
def password(self):
"""
getter for password
:return: password (hashed)
"""
return self.__dict__.get("password")
@password.setter
def password(self, password):
"""
Password setter, with md5 hasing
:param password: password
:return: nothing
"""
self.__dict__["password"] = md5(password.encode('utf-8')).hexdigest()