Skip to content

Commit

Permalink
CRUD user and profile Fixed #6, Login activity from backend Close #4
Browse files Browse the repository at this point in the history
  • Loading branch information
leonelphm committed Jul 2, 2019
1 parent eae9d55 commit fdf888e
Show file tree
Hide file tree
Showing 29 changed files with 20,287 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ migrations
migrations/*
__pycache__
__pycache__/*
*/__pycache__
*/migrations/
*/__pycache__/*
*/migrations/*
*/*/__pycache__/*
*/*/migrations/*

# Frontend
package-lock.json
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ SGE open source
pip install -r requirements.txt
```

* Make migrations for djangop
* Make migrations for django and load initial data

```
python manage.py makemigrations
python manage.py makemigrations utils company users
```

```
python manage.py migrate
```

```
python manage.py loaddata fixtures/initial_data_groups.json fixtures/initial_data_user.json fixtures/initial_data_sorter.json
```

* Run project
Expand All @@ -43,3 +51,6 @@ SGE open source
```
npm run serve
```

User: admin
pass: watchin123456
65 changes: 62 additions & 3 deletions WatchInSGE/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
https://docs.djangoproject.com/en/2.2/ref/settings/
"""

import datetime
import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
Expand Down Expand Up @@ -38,17 +39,24 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework_simplejwt.token_blacklist',
'djoser',
'django_filters',
'corsheaders',
]

PROJECT_APPS = [
'base',
'base.utils',
'business',
'business.company',
'base.users',
]

INSTALLED_APPS = DJANGO_APPS + PROJECT_APPS

MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
Expand Down Expand Up @@ -86,6 +94,7 @@
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ATOMIC_REQUESTS': True, # Create transactions on each view request
}
}

Expand Down Expand Up @@ -132,11 +141,12 @@
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
#'rest_framework.permissions.IsAuthenticated',
'rest_framework.permissions.IsAuthenticated',
],
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework_simplejwt.authentication.JWTAuthentication',
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
),
'DEFAULT_PARSER_CLASSES': (
'rest_framework.parsers.JSONParser',
Expand All @@ -146,4 +156,53 @@
'PAGE_SIZE': 20,
'UNICODE_JSON': True,
'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',),
}
}

SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': datetime.timedelta(hours=12),
'AUTH_HEADER_TYPES': ('JWT',),
'SLIDING_TOKEN_LIFETIME': datetime.timedelta(hours=12),
'REFRESH_TOKEN_LIFETIME': datetime.timedelta(days=1),
'ROTATE_REFRESH_TOKENS': False,
'BLACKLIST_AFTER_ROTATION': True,
}


DOMAIN = os.environ.get('SITE_DOMAIN', None) #'localhost:8080'
# se puede cambiar por el dominio del frontend
SITE_NAME = 'localhost'


DJOSER = {
'PASSWORD_RESET_CONFIRM_URL': '/auth/password/reset/confirm/{uid}/{token}', # Coloque la ruta del frontend y tome el uid y el token para enviarlos como parametros
'ACTIVATION_URL': '/auth/activate/{uid}/{token}',
'PASSWORD_RESET_SHOW_EMAIL_NOT_FOUND': True,
'SEND_ACTIVATION_EMAIL': False,
'SERIALIZERS': {'user_create': 'base.users.serializers.CreateUserSerializer',
'user': 'djoser.serializers.UserSerializer'
},
}

DATETIME_FORMAT = {
'DATETIME_USER': '%B, %d de %Y, %I:%M:%S %P ',
}

EMAIL_USE_TLS = True

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'passaccount'
EMAIL_FROM = EMAIL_HOST_USER

# During production only
#EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# During development only
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'


CORS_ORIGIN_ALLOW_ALL=True

CORS_ORIGIN_WHITELIST = (
'http:https://localhost:8080',
)
24 changes: 22 additions & 2 deletions WatchInSGE/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,29 @@
"""
from django.contrib import admin
from django.urls import path, include
from .routers import router

from djoser.urls import (
authtoken, urlpatterns
)
from rest_framework_jwt.views import obtain_jwt_token
from rest_framework_jwt.views import refresh_jwt_token
from rest_framework_jwt.views import verify_jwt_token

from base.users.urls import urlpatterns as users_urls

url_djoser_users = urlpatterns + users_urls

url_djoser_users.pop(1)
url_djoser_users.pop(8)

urlpatterns = [
path('api/api-auth/', include('rest_framework.urls',
namespace='rest_framework')),
path('admin/', admin.site.urls),
path('api/', include(router.urls)),
#: Djoser auth And User Create
path('api/auth/', include(url_djoser_users)),
#: Sorter urls
path('api/utils/', include('base.utils.urls')),
#: Djoser JWT
path('api/auth/', include('djoser.urls.jwt')),
]
Empty file added base/users/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions base/users/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions base/users/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class UserConfig(AppConfig):
name = 'users'
2 changes: 2 additions & 0 deletions base/users/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ADMINS = "Administrator"
USER = "User"
33 changes: 33 additions & 0 deletions base/users/email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
WatchInSGE System
"""

## @package base.users.email
#
# Driver for handling email
# @author Team WatchIn
# @version 1.0.0

from templated_mail.mail import BaseEmailMessage


class AccountCreateEmail(BaseEmailMessage):
"""!
Class that handles the context of the email that is generated when creating an account from the administrator
@author Leonel P. Hernandez M. (leonelphm at gmail.com)
@date 03-10-2018
@version 1.0.0
"""
template_name = 'email/account_create.html'

def get_context_data(self):
"""
Method that obtains context values to create the message
"""
context = super(AccountCreateEmail, self).get_context_data()

user = context.get('user')
password = context.get('password')
return context
49 changes: 49 additions & 0 deletions base/users/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
WatchInSGE System
"""

## @package base.users.models
#
# Model that builds users data models
# @author Team WatchIn
# @date 23-05-2019
# @version 1.0

from django.contrib.auth.models import User
from django.db import models

from business.company.models import Job
from base.utils.models import (
Sorter, AbstractBaseModels
)
from base.utils.constants import COUNTRY


class UserProfile(AbstractBaseModels):
"""!
Class that contains the profiles of the users
@author Ing. Leonel P. Hernandez M. (leonelphm at gmail.com)
@date 17-04-2018
@version 1.0.0
"""
fk_user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='user')
fk_job = models.ForeignKey(Job, on_delete=models.CASCADE,
null=True, blank=True)
fk_country = models.ForeignKey(Sorter, on_delete=models.CASCADE,
limit_choices_to={'group_sorter': COUNTRY},
null=True, blank=True)
address = models.TextField(null=True, blank=True)
state = models.CharField(max_length=50, null=True, blank=True)
telephone = models.CharField(max_length=20, null=True, blank=True)

class Meta:
"""
Class that builds model metadata
"""
ordering = ('pk',)
db_table = 'base_userProfile'

def __str__(self):
return self.fk_user.username

Loading

0 comments on commit fdf888e

Please sign in to comment.