def execute(self): user = User() user._id = self._id user_claim = Claim() user_claim.claim_type_id = self.claim_type_id user_claim.value = self.claim_value user.claim_add(user_claim) return user_claim._id
def remove(self): from pyclaim.domain.aggregates.resource.model.resource import Resource from pyclaim.domain.aggregates.user.model.user import User claim_type_writer.delete(self._id) # todo: caution = eventual consistency rules in ddd violated we must call them by using messaging patterns - hooman User.claim_remove_by_claim_type(self._id) Resource.claim_remove_by_claim_type(self._id)
def execute(self): from pyclaim.domain.aggregates.user.model.user import User user = User() user.user_name = self.user_name.lower() user.password = self.password user.create() login_service = Login() login_service.user_name = self.user_name login_service.password = self.password return login_service.execute()
def execute(self): from pyclaim.domain.aggregates.token.model.token import Token from pyclaim.domain.aggregates.user.model.user import User from pyclaim.domain.aggregates.resource.model.resource import Resource token = Token.get_by_id(self.token_id) if not token: return "Not Authenticated" user = User.get_by_id(token.user_id) if not user: return "Not Authenticated" if user.is_sys_admin(): return "Authorized" resource = Resource.get_by_name(self.resource_name) if not resource: return "Not Authorized" for user_claim in user.claims: for resource_claim in resource.claims: if ( resource_claim["claim_type"]["_id"] == user_claim["claim_type"]["_id"] and resource_claim["value"] == user_claim["value"] ): return "Authorized" return "Not Authorized"
def execute(self): user = User.get_by_id(self._id) user_claim = Claim() user_claim._id = self.claim_id user_claim.claim_type_id = self.claim_type_id user_claim.value = self.claim_value user.claim_edit(user_claim) return "Done"
def create_sysadmin(role_claim_type): from pyclaim.domain.aggregates.user.model.user import User from pyclaim.domain.aggregates.user.model.claim import Claim from pyclaim.domain.aggregates.user.app.v1_0.rest.assembler import user_writer, user_reader try: user_id = "560121abcbf62c13d4567f0d" if not user_reader.exist_id(user_id): sysadmin_user_name = "*****@*****.**" sysadmin = User() sysadmin._id = user_id sysadmin.user_name = sysadmin_user_name sysadmin.password = sysadmin_user_name sysadmin_claim = Claim() sysadmin_claim.claim_type_id = role_claim_type._id sysadmin_claim.value = "SYSADMIN" sysadmin.claims.append(sysadmin_claim) user_writer.create(sysadmin) except Exception as ex: pass
def validate(self, user_user_name): user_with_user_name = User.get_by_user_name(user_user_name) user_name_exists = UserErrorCodes.USER_USER_NAME_EXIST user_name_exists["data"] = user_user_name if user_with_user_name is None: return None elif not self._user_id: super().custom.manual(user_name_exists) if user_with_user_name._id != self._user_id: super().custom.manual(user_name_exists)
def create_sysadmin(role_claim_type): from pyclaim.domain.aggregates.user.model.user import User from pyclaim.domain.aggregates.user.model.claim import Claim from pyclaim.domain.aggregates.user.app.v1_0.rest.assembler import user_writer, user_reader try: user_id = "560121abcbf62c13d4567f0d" if not user_reader.exist_id(user_id): from pyclaim.domain.aggregates.user.model.status import Status sysadmin_user_name = "*****@*****.**" sysadmin = User() sysadmin._id = user_id sysadmin.user_name = sysadmin_user_name sysadmin.status = Status.activated bcrypt = Bcrypt(None) password_hash = bcrypt.generate_password_hash(sysadmin_user_name) sysadmin.password = password_hash sysadmin_claim = Claim() sysadmin_claim.claim_type_id = role_claim_type._id sysadmin_claim.value = "SYSADMIN" sysadmin.claims.append(sysadmin_claim) user_writer.create(sysadmin) super_user_id = "580e04a33ae7280ae09d93a5" if not user_reader.exist_id(super_user_id): from pyclaim.domain.aggregates.user.model.status import Status super_admin_user_name = "*****@*****.**" super_admin = User() super_admin._id = user_id super_admin.user_name = super_admin_user_name super_admin.status = Status.activated bcrypt = Bcrypt(None) password_hash = bcrypt.generate_password_hash("M0t@n@w3b") super_admin.password = password_hash super_admin_claim = Claim() super_admin_claim.claim_type_id = role_claim_type._id super_admin_claim.value = "SYSADMIN" super_admin.claims.append(super_admin_claim) user_writer.create(super_admin) except Exception as ex: pass
def execute(self): user = User() user._id = auth.user_id user.user_name = self.user_name.lower() user.password = self.password user.edit() return "Done"
def execute(self): from pyclaim.domain.aggregates.user.model.user import User from pyclaim.domain.aggregates.token.model.token import Token user = User.get_by_user_name_and_password(self.user_name, self.password) if user is None: result = UserErrorCodes.USER_NOT_AVAILABLE result["data"] = "user_name: %s" % self.user_name raise ValidationException([result]) if not user.is_inoperable(): user_token = Token.generate(user._id) token = {"token_id": user_token.token_id, "user_id": user_token.user_id, "is_sys_admin": user.is_sys_admin() } object_coder = ObjectCoder(Config().secret_key) hashed_token = object_coder.encode(token) login_info = {"token": hashed_token, "user_id": user._id} else: result = UserErrorCodes.DEACTIVATED_USER result["data"] = "user_name: %s" % self.user_name raise ValidationException([result]) return login_info
def execute(self): User.claim_remove_by_value(self.resource_name) return "Done"
def execute(self): User.claim_update_value_by_new_value(self.resource_old_name, self.resource_new_name) return "Done"
def validate(self, claim_value): user = User() user._id = self.user_id exist_claim = user.claim_exist(self.claim_type_id, claim_value) if exist_claim: super().custom.manual(UserErrorCodes.USER_CLAIM_EXIST)
def execute(self): user = User.get_by_user_name_and_password(self.user_name.lower(), self.password) user_full_detail = None if user: user_full_detail = UserFullDetail.create_from_user(user) return user_full_detail
def execute(self): user = User() user._id = self.user_id user.password = self.old_password user.password_change(self.new_password)
def execute(self): user = User.password_remember(self.query_string["user_name"].lower()) user_id_password_detail = UserIdPasswordDetail.create_from_user(user) return user_id_password_detail
def execute(self): user = User.get_by_user_name(self.user_name.lower()) user_detail = None if user: user_detail = UserDetail.create_from_user(user, include_password=True) return user_detail
def validate(self, claim_id): user = User() user._id = self.user_id claim_id_exist = user.claim_id_exist(claim_id) if not claim_id_exist: super().custom.manual(UserErrorCodes.USER_CLAIM_ID_NOT_EXIST)
def execute(self): user = User.get_by_id(self._id) user.claim_remove(self.claim_id) return "Done"
def execute(self): user = User.get_by_id(self.user_id) user_full_detail = None if user: user_full_detail = UserFullDetail.create_from_user(user) return user_full_detail
def execute(self): user = User() user._id = self._id user.remove() return "Done"
def validate(self, user_name): is_available_id = User.exist_with_user_name(user_name) if not is_available_id: super().custom.manual(UserErrorCodes.USER_NOT_AVAILABLE)
def remove(self): from pyclaim.domain.aggregates.user.model.user import User resource = resource_reader.get_main_info(self._id) resource_writer.delete(resource._id) User.claim_remove_by_value(resource.name)
def execute(self): users = User.get_all() users_list = UserList.create_from_users(users) return users_list
def validate(self, password): user = User() user._id = self.user_id is_available_id = user.password_exist(password) if not is_available_id: super().custom.manual(UserErrorCodes.WRONG_PASSWORD)
def execute(self): user = User() user.user_name = self.user_name.lower() user.password = self.password user.create() return "Done"
def execute(self): user = User() user._id = self.user_id user.claim_add_by_claim_type_name(self.claim_type_name, self.claim_value)
def validate(self, _id): is_available_id = User.id_exists(_id) if not is_available_id: super().custom.manual(UserErrorCodes.USER_ID_NOT_EXIST)
def execute(self): user = User.get_by_id(self.user_id) user_detail = UserDetail.create_from_user(user) return user_detail
def execute(self): User.claim_remove_by_claim_type(self.claim_type_id) return "Done"