Skip to content

Commit

Permalink
fix: los usuario se crean usando el mismo recurso
Browse files Browse the repository at this point in the history
Refs: #2
Refs: #3
Refs: #16
  • Loading branch information
ybenitezf committed Apr 13, 2021
1 parent 56a52bf commit e79dfa5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
19 changes: 16 additions & 3 deletions newswriter/models/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,30 @@ def getCreditLine(self):
return self.credit_line or self.name or self.username


def create_user(username: str, password: str, name='', email='') -> User:
def create_user(
username: str,
password: str,
name='',
email='',
credit_line='',
id=None
) -> User:
"""Crear un usuario"""
user = User()
if id is None:
user = User()
else:
user = User(id=id)
user.name = name
user.set_password(password)
user.username = username
user.email = email
user.credit_line = credit_line

# crear grupo especial para el usuario
Role.createUserEspecialRole(user)

# crear el board personal del usuario

return user


Expand All @@ -128,7 +141,7 @@ def password_generator(length=8):
:returns string <class 'str'>
'''
LETTERS = string.ascii_letters
NUMBERS = string.digits
NUMBERS = string.digits
PUNCTUATION = string.punctuation

# create alphanumerical from string constants
Expand Down
16 changes: 8 additions & 8 deletions newswriter/modules/import_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from newswriter.schemas import ImageModelExportSchema
from newswriter.models.content import Article, ImageModel
from newswriter.models.security import User, Role, password_generator
from newswriter.models.security import create_user
from flask import current_app, json
from marshmallow import fields, validate
import tempfile
Expand Down Expand Up @@ -72,14 +73,13 @@ def importUserInfo(user_data) -> User:
# Ya tengo este usuario en la BD
return u
else:
u = User()
u.name = user_data["name"]
u.username = user_data["username"]
u.credit_line = user_data["credit_line"]
u.email = user_data["email"]
u.id = user_data.get('id')
u.set_password(password_generator())
Role.createUserEspecialRole(u)
u = create_user(
user_data["username"], password_generator(),
name=user_data["name"],
email=user_data["email"],
credit_line=user_data["credit_line"],
id=user_data.get('id')
)

return u

Expand Down

0 comments on commit e79dfa5

Please sign in to comment.