public function save($data=array())
    {

		if (empty($data)) {
			throw new \Exception( "User data is missing" );
		}
        $data = (object) $data;

		if ((!isset($data->email) || empty($data->email))) {
			throw new \Exception( "Email is required" );
		}
		if ((!isset($data->password) || empty($data->password)) && !isset($data->id)) {
			throw new \Exception( "Password is required" );
		}

		$new  = false;
		if (isset($data->id)) {
			$entity = $this->getById($data->id);
		} else {
			$entity = new entity();
			$new    = true;
		}
		if (isset($data->name)) {
			$entity->setName($data->name);
		}
		if (isset($data->email)) {
			$entity->setEmail($data->email);
		}
		if (isset($data->password)) {
			$entity->setPassword($this->getSalted($data->password));
		} elseif (isset($data->new_password)){
			$entity->setPassword($this->getSalted($data->new_password));
		}
		if (empty($data->role)) {
			$data->role = $this->_getDefaultRole();
		}
		$entity->setRole($data->role);
		if (isset($data->gateway_customer_id)) {
			$entity->setGatewayCustomerId($data->gateway_customer_id);
		}

		if ($new) {
			$this->_em->persist($entity);
		} else {
			$this->_em->merge($entity);
		}

		// Save the entity
		try {
			$eventType = $new ? Log::EVENT_CREATE : Log::EVENT_UPDATE;
			if(isset($data->new_password)){
				$eventType = Log::EVENT_PASSWORD;
				unset($data->new_password);
			}
			unset($data->password);

			$this->createUserEventLog($eventType, $data);
			$this->_em->flush();
			$this->setEntity($entity);

			return $entity->getId();

		} catch ( \Doctrine\DBAL\Exception\UniqueConstraintViolationException $e ) {
			// \Erdiko::log(\Psr\Log\LogLevel::INFO, 'UniqueConstraintViolationException caught: '.$e->getMessage());
			throw new \Exception( "Can not create user with duplicate email" );
		}

		return null;
	}