/**
  * Register new User
  * @return array
  */
 public function registerAction()
 {
     $formManager = $this->serviceLocator->get('FormElementManager');
     $form = $formManager->get('registerForm');
     $form->setInputFilter(new Form\RegisterFilter($this->getObjectManager()));
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             //CREATE NEW USER
             $user = new User();
             $user->setCompany($this->getRequest()->getPost('company'));
             $user->setFirstName($this->getRequest()->getPost('first_name'));
             $user->setLastName($this->getRequest()->getPost('last_name'));
             $user->setEmail($this->getRequest()->getPost('email'));
             $bcrypt = new Bcrypt();
             $securePass = $bcrypt->create($this->getRequest()->getPost('password'));
             $user->setPassword($securePass);
             $user->setStatus(0);
             $token = md5(uniqid(mt_rand(), true));
             $user->setToken($token);
             $user->setAddress("");
             $user->setZipcode("");
             $user->setCity("");
             $user->setCountry("");
             $user->setPhone("");
             $user->setCreated(new \DateTime("now"));
             $user->setLastModified(new \DateTime("now"));
             //AND SAVE USER TO DB
             $this->getObjectManager()->persist($user);
             $this->getObjectManager()->flush();
             // $newId = $user->getId();
             //COMPOSE AND SEND ACTIVATION MAIL
             //@TODO move hostname/baseurl to config
             $url = "http://www.example.net/login?token=" . $token;
             $translator = $this->getServiceLocator()->get('translator');
             //Create text part of mail
             $textContent = sprintf($translator->translate("registration_mail_text"), $url);
             $text = new MimePart($textContent);
             $text->type = "text/plain";
             //Create html part of mail
             $htmlMarkup = sprintf($translator->translate("registration_mail_html"), $url);
             $html = new MimePart($htmlMarkup);
             $html->type = "text/html";
             //Compose mail
             $body = new MimeMessage();
             $body->setParts(array($text, $html));
             $message = new Message();
             //@TODO move email address etc. to config
             $message->addFrom("*****@*****.**", "example.net")->addTo($user->getEmail(), $user->getFirstName() . " " . $user->getLastName())->setSubject($translator->translate("registration_mail_subject"));
             $message->setBody($body);
             $message->setEncoding("UTF-8");
             //Debug mail: echo $message->toString();
             //Depending on how you send mail..
             /*$transport = new SmtpTransport();
             		$options   = new SmtpOptions(array(
                			'name'              => 'localhost.localdomain',
                			'host'              => '127.0.0.1',
                			'connection_class'  => 'login',
                			'connection_config' => array(
                    			'username' => 'user',
                    			'password' => 'pass',
                			),
             		));
             		$transport->setOptions($options);*/
             //Send email
             $transport = new SendmailTransport();
             $transport->send($message);
             //REDIRECT TO SENT-PAGE
             return $this->redirect()->toRoute('home');
         }
     }
     return array('form' => $form);
 }