public function executeSignUp($request)
 {
     $this->form = new SignUpForm();
     if ($request->isMethod('get')) {
         return;
     }
     $this->form->bind($request->getParameter('form'));
     if (!$this->form->isValid()) {
         return;
     }
     $sfGuardUser = new sfGuardUser();
     $sfGuardUser->setUsername($this->form->getValue('username'));
     $sfGuardUser->setPassword($this->form->getValue('password'));
     $sfGuardUser->setIsActive(false);
     $sfGuardUser->save();
     $sfGuardUserProfile = new sfGuardUserProfile();
     $sfGuardUserProfile->setSfGuardUser($sfGuardUser);
     $sfGuardUserProfile->setEmail($this->form->getValue('email'));
     $sfGuardUserProfile->setFirstName($this->form->getValue('first_name'));
     $sfGuardUserProfile->setLastName($this->form->getValue('last_name'));
     $sfGuardUserProfile->setGender($this->form->getValue('gender'));
     $sfGuardUserProfile->setBirthday($this->form->getValue('birthday'));
     $sfGuardUserProfile->setWebpage($this->form->getValue('webpage'));
     $sfGuardUserProfile->save();
     try {
         $connection = new Swift_Connection_SMTP('mail.sis-nav.com', 25);
         $connection->setUsername('*****@*****.**');
         $connection->setPassword('gahve123');
         $mailer = new Swift($connection);
         $message = new Swift_Message('Account Confirmation');
         $mailContext = array('email' => $sfGuardUserProfile->getEmail(), 'full_name' => $sfGuardUserProfile->getFullName(), 'activation_key' => $sfGuardUserProfile->getActivationKey());
         $message->attach(new Swift_Message_Part($this->getPartial('mail/signUpHtmlBody', $mailContext), 'text/html'));
         $message->attach(new Swift_Message_Part($this->getPartial('mail/signUpTextBody', $mailContext), 'text/plain'));
         $mailer->send($message, $sfGuardUserProfile->getEmail(), '*****@*****.**');
         $mailer->disconnect();
     } catch (Exception $e) {
         $mailer->disconnect();
     }
     $this->getUser()->setFlash('info', 'A confirmation email has been sent to your email address.');
     $this->forward('site', 'message');
 }
Beispiel #2
0
 public function executeInvite($request)
 {
     $this->user_invite_form = new UserInviteForm();
     if ($request->isMethod('post')) {
         $userParams = $request->getParameter('user');
         $this->user_invite_form->bind($userParams);
         if ($this->user_invite_form->isValid()) {
             $db = Doctrine_Manager::connection();
             try {
                 $db->beginTransaction();
                 //create user
                 $user = new sfGuardUser();
                 $user->username = $userParams['email'];
                 $user->algorithm = 'sha1';
                 $user->setPassword('pending');
                 $user->is_active = false;
                 $user->addGroupByName($userParams['group']);
                 $user->save();
                 //create user profile
                 $profile = new sfGuardUserProfile();
                 $profile->user_id = $user->id;
                 $profile->name_first = $userParams['name_first'];
                 $profile->name_last = $userParams['name_last'];
                 $profile->email = $userParams['email'];
                 $profile->is_visible = false;
                 $profile->invitation_code = substr(sha1($profile->getEmail() . time()), 0, 10);
                 $profile->save();
                 //send welcome email
                 $mailBody = $this->getPartial($userParams['template'], array('profile' => $profile));
                 $mailer = new Swift(new Swift_Connection_NativeMail());
                 $message = new Swift_Message("You're invited to become a LittleSis analyst!", $mailBody, 'text/plain');
                 $address = new Swift_Address(sfConfig::get('app_mail_invite_sender_address'), sfConfig::get('app_mail_invite_sender_name'));
                 $mailer->send($message, $profile->email, $address);
                 $mailer->disconnect();
                 //all's well, commit transaction
                 $db->commit();
             } catch (Exception $e) {
                 $db->rollback();
                 throw $e;
             }
             $this->redirect('user/list');
         }
         //gather errors
         $this->errors = $this->user_invite_form->getErrorSchema()->getErrors();
     }
 }