Browse Source

add change password to mutate user

ilya_shyian 1 year ago
parent
commit
3a28e42eb2
1 changed files with 10 additions and 0 deletions
  1. 10 0
      store_back/apps/authAPI/schema.py

+ 10 - 0
store_back/apps/authAPI/schema.py

@@ -145,9 +145,15 @@ class UserUpsert(graphene.Mutation):
     @staticmethod
     def mutate(root,info,user):
         new_user={}
+        password = None
         ava = None
         acl = []
 
+        if "password" in user and len(user["password"] < 3):
+            raise Exception("Не вірні дані (пароль)")
+        elif "password" in user:
+            password = str(user.pop("password"))
+
         if "acl" in user:
             acl = user.get("acl", [])
             user.pop("acl")
@@ -169,6 +175,10 @@ class UserUpsert(graphene.Mutation):
 
             user.pop("_id",None)
             new_user.__dict__.update(**user)
+
+            if password:
+                new_user.set_password(password)
+
         except Exception as e:
 
             if info.context.user.is_authenticated: