src/User/Service/User.php
public function activate($idOrUser, $forceActivationForBannedUser = true) 
    {
		// All the services we need
		$main = $this->getServiceLocator()->get('neobazaar.service.main');
		$em = $main->getEntityManager();
		
		$user = $this->getEntity($idOrUser);
		
		if(UserEntity::USER_STATE_ACTIVE == $user->getState()) {
			throw new \Exception('Questo utente è già attivo!');
		}
		
		if(UserEntity::USER_STATE_BANNED != $user->getState() || $forceActivationForBannedUser) {
			$user->setState(UserEntity::USER_STATE_ACTIVE);
		}
		$user->setDateActivated(new \Datetime());
		
		// generate a password
		$password = substr(sha1(rand()), 0, 8);
		$user->setPassword($this->getCryptedPassword($password));
		
		$userModel = $this->getServiceLocator()->get('user.model.user');
		$userModel->init($user, $this->getServiceLocator());
	
		$url = $this->getServiceLocator()->get('ControllerPluginManager')->get('Url');
		
		$event = new UserActivationEvent(__FUNCTION__, null, array(
		    'to' => $userModel->email, 
		    'siteurl' => $url->fromRoute('home', array(), array('force_canonical' => true)),
		    'password' => $password
		));
		
		$this->getEventManager()->trigger(__FUNCTION__ . '.pre', $this, $event);
		$em->persist($user);
		$em->flush();
		$this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, $event);
		
		return $user;
    }
public function activate($idOrUser, $forceActivationForBannedUser = true) 
    {
		// All the services we need
		$main = $this->getServiceLocator()->get('neobazaar.service.main');
		$em = $main->getEntityManager();
		
		$user = $this->getEntity($idOrUser);
		
		if(UserEntity::USER_STATE_ACTIVE == $user->getState()) {
			throw new \Exception('Questo utente è già attivo!');
		}
		
		if(UserEntity::USER_STATE_BANNED != $user->getState() || $forceActivationForBannedUser) {
			$user->setState(UserEntity::USER_STATE_ACTIVE);
		}
		$user->setDateActivated(new \Datetime());
		
		// generate a password
		$password = substr(sha1(rand()), 0, 8);
		$user->setPassword($this->getCryptedPassword($password));
		
		$userModel = $this->getServiceLocator()->get('user.model.user');
		$userModel->init($user, $this->getServiceLocator());
	
		$url = $this->getServiceLocator()->get('ControllerPluginManager')->get('Url');
		
		$event = new UserActivationEvent(__FUNCTION__, null, array(
		    'to' => $userModel->email, 
		    'siteurl' => $url->fromRoute('home', array(), array('force_canonical' => true)),
		    'password' => $password
		));
		
		$this->getEventManager()->trigger(__FUNCTION__ . '.pre', $this, $event);
		$em->persist($user);
		$em->flush();
		$this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, $event);
		
		return $user;
    }
Activate and user

@param string $idOrUser
@return \Neobazaar\Entity\User