public function executeSignin($request)
 {
     $user = $this->getUser();
     if ($user->isAuthenticated()) {
         return $this->redirect('@homepage');
     }
     // Create SimpleSAML module
     $simpleSAMLAuth = new SimpleSAML_Auth_Simple('default-sp');
     // If the user is authenticated from the IdP
     if ($simpleSAMLAuth->isAuthenticated()) {
         $attributes = $simpleSAMLAuth->getAttributes();
         // save the referer
         $user_referer = $user->getReferer($request->getReferer());
         // Try to find the user with his uid
         $query = Doctrine_Core::getTable('sfGuardUser')->createQuery('u')->where('u.username = ?', $attributes['eduPersonPrincipalName'][0]);
         // If the sGuardUser already exists in the database, it's OK
         if ($query->count() >= 1) {
             $guard_user = $query->fetchOne();
             $guard_user->setEmailAddress($attributes['mail'][0]);
             $guard_user->setLastName($attributes['cn'][0]);
             $guard_user->save();
         } else {
             // the user doesn't exist, we create a new one with random password
             $guard_user = new sfGuardUser();
             $guard_user->setUsername($attributes['eduPersonPrincipalName'][0]);
             $guard_user->setPassword(md5(microtime() . $attributes['eduPersonPrincipalName'][0] . mt_rand()));
             $guard_user->setEmailAddress($attributes['mail'][0]);
             $guard_user->setLastName($attributes['cn'][0]);
             $guard_user->setIsActive(true);
             $guard_user->save();
         }
         // Let the User signin
         // The auth is not rembered : the IdP can decide that
         $this->getUser()->signin($guard_user, $remember = false);
         // always redirect to a URL set in app.yml
         // or to the referer
         // or to the homepage
         $signinUrl = sfConfig::get('app_sf_guard_plugin_success_signin_url', $user_referer);
         return $this->redirect('' != $signinUrl ? $signinUrl : '@homepage');
     } else {
         if ($request->isXmlHttpRequest()) {
             $this->getResponse()->setHeaderOnly(true);
             $this->getResponse()->setStatusCode(401);
             return sfView::NONE;
         }
         // if we have been forwarded, then the referer is the current URL
         // if not, this is the referer of the current request
         $user->setReferer($this->getContext()->getActionStack()->getSize() > 1 ? $request->getUri() : $request->getReferer());
         /* gyufi $this->url_idp = $simpleSAMLAuth->login(array(
              //'saml:idp' => 'https://openidp.feide.no',
              'saml:idp' => 'https://aai.sztaki.hu/idp-partners',
              'saml:idp' => 'https://aai.sztaki.hu/idp',
            ));
            */
         $this->url_idp = $simpleSAMLAuth->login();
         // Nothing happened after there, $simpleSAMLAuth->login() calls exit()
         /*
               $module = sfConfig::get('sf_login_module');
               if ($this->getModuleName() != $module)
               {
                 return $this->redirect($module.'/'.sfConfig::get('sf_login_action'));
               }
         
               $this->getResponse()->setStatusCode(401);
         */
     }
 }
 /**
  * executeRegister
  *
  * @access public
  * @return void
  */
 public function executeRegister(sfWebRequest $request)
 {
     $this->form = new sfGuardFormRegister();
     if ($request->isMethod(sfRequest::POST)) {
         $this->form->bind($request->getParameter($this->form->getName()));
         if ($this->form->isValid()) {
             $values = $this->form->getValues();
             $sfGuardUser = new sfGuardUser();
             $sfGuardUser->fromArray($values, BasePeer::TYPE_FIELDNAME);
             if (isset($values['email'])) {
                 $sfGuardUser->setEmail($values['email']);
             }
             $sfGuardUser->setIsActive(false);
             $sfGuardUser->save();
             $messageParams = array('sfGuardUser' => $sfGuardUser, 'password' => $values['password']);
             $body = $this->getComponent($this->getModuleName(), 'send_request_confirm', $messageParams);
             $from = sfConfig::get('app_sf_guard_extra_plugin_mail_from', '*****@*****.**');
             $fromName = sfConfig::get('app_sf_guard_extra_plugin_name_from', 'noreply');
             $to = $sfGuardUser->getEmail();
             $toName = $sfGuardUser->getUsername();
             $subject = sfConfig::get('app_sf_guard_extra_plugin_subject_confirm', 'Confirm Registration');
             $mailer = $this->getMailer();
             $message = $mailer->compose(array($from => $fromName), array($to => $toName), $subject, $body);
             $mailer->send($message);
             $this->getUser()->setFlash('values', $values);
             $this->getUser()->setFlash('sfGuardUser', $sfGuardUser);
             return $this->redirect('@sf_guard_do_register');
         }
     }
 }
示例#3
0
 private function registerUser($username, $data = NULL)
 {
     try {
         $gingerKey = sfConfig::get('app_portail_ginger_key');
         if ($gingerKey != "abc") {
             $ginger = new \Ginger\Client\GingerClient(sfConfig::get('app_portail_ginger_key'));
             $cotisants = $ginger->getUser($username);
         } else {
             $cotisants = new stdClass();
             $cotisants->mail = $username . "@etu.utc.fr";
             $cotisants->prenom = "Le";
             $cotisants->nom = "Testeur";
             $cotisants->type = "etu";
         }
         if (!$data) {
             $data = new sfGuardUser();
         }
         $data->setUsername($username);
         $data->setEmailAddress($cotisants->mail);
         $data->setFirstName($cotisants->prenom);
         $data->setLastName($cotisants->nom);
         $data->setIsActive(true);
         $data->save();
         $profile = new Profile();
         $profile->setUser($data);
         $profile->setDomain($cotisants->type);
         $profile->save();
         return $data;
     } catch (\Ginger\Client\ApiException $ex) {
         $this->setFlash('error', "Il n'a pas été possible de vous identifier. Merci de contacter simde@assos.utc.fr en précisant votre login et le code d'erreur " . $ex->getCode() . ".");
     }
     return false;
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $user = new sfGuardUser();
     $user->setUsername($arguments['username']);
     $user->setPassword($arguments['password']);
     $user->setIsActive(true);
     $user->save();
     $this->logSection('guard', sprintf('Create user "%s"', $arguments['username']));
 }
示例#5
0
 public function doSave($con = null)
 {
     $user = new sfGuardUser();
     $user->setUsername($this->getValue('username'));
     $user->setPassword($this->getValue('password'));
     // They must confirm their account first
     $user->setIsActive(false);
     $user->save();
     $this->userId = $user->getId();
     return parent::doSave($con);
 }
 /**
  * Accepts proof of identity from the client side Facebook SDK.
  * https://developers.facebook.com/docs/howtos/login/signed-request/#step2
  * This will not work if your site doesn't have a proper
  * domain name (it will not work in dev, in most cases).
  */
 public function executeFacebookLogin(sfWebRequest $request)
 {
     $fb = sfConfig::get('app_sfApplyPlugin_facebook');
     $secret = isset($fb['secret']) ? $fb['secret'] : null;
     if (!$secret) {
         throw new sfException('app_sfApplyPlugin_facebook not configured, secret missing');
     }
     $signed_request = $request->getParameter('signed_request');
     list($encoded_sig, $payload) = explode('.', $signed_request, 2);
     // decode the data
     $sig = $this->base64UrlDecode($encoded_sig);
     $data = json_decode($this->base64UrlDecode($payload), true);
     // Contrary to FB docs we're not done yet, we have to
     // trade the 'code' in for an access token and then we
     // can query for information about the user
     $code = $data['code'];
     $url = "https://graph.facebook.com/oauth/access_token?" . http_build_query(array('client_id' => $fb['id'], 'redirect_uri' => '', 'client_secret' => $secret, 'code' => $code));
     $accessToken = file_get_contents($url);
     parse_str($accessToken, $result);
     $accessToken = $result['access_token'];
     $me = json_decode(file_get_contents("https://graph.facebook.com/me?" . http_build_query(array('access_token' => $accessToken))), true);
     if (!isset($me['email'])) {
         $this->forward404();
     }
     $email = $me['email'];
     $first_name = $me['first_name'];
     $last_name = $me['last_name'];
     $username = '******' . (isset($me['username']) ? $me['username'] : $me['id']);
     if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
         $this->forward404();
     }
     // Adding the verification of the signed_request below
     $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
     if ($sig !== $expected_sig) {
         $this->forward404();
     }
     $user = Doctrine::getTable('sfGuardUser')->findOneByEmailAddress($email);
     if (!$user) {
         $user = new sfGuardUser();
         $user->setIsActive(true);
         $user->setPassword(aGuid::generate());
         $user->setEmailAddress($email);
         $user->setUsername($username);
     }
     $user->setFirstName($firstName);
     $user->setLastName($lastName);
     $user->setEmailAddress($email);
     $user->save();
     $this->getUser()->signIn($user);
     return $this->renderText('OK');
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $user = new sfGuardUser();
     $user->setEmailAddress($arguments['email_address']);
     $user->setUsername($arguments['username']);
     $user->setPassword($arguments['password']);
     $user->setFirstName($arguments['first_name']);
     $user->setLastName($arguments['last_name']);
     $user->setIsActive(true);
     $user->setIsSuperAdmin($options['is-super-admin']);
     $user->save();
     $this->logSection('guard', sprintf('Create user "%s"', $arguments['username']));
 }
 public function doSave($con = null)
 {
     if ($this->isNew) {
         $user = new sfGuardUser();
         $user->setUsername($this->getValue('username'));
         $user->setPassword($this->getValue('password'));
         $user->setEmailAddress($this->getValue('email'));
         $user->addGroupByName(sfConfig::get('app_user_default_group'));
         // They must confirm their account first
         $user->setIsActive(false);
         $user->save();
         $this->getObject()->setUserId($user->getId());
     }
     return parent::doSave($con);
 }
示例#9
0
 public function executeApply()
 {
     $request = $this->getRequest();
     $this->form = new RegisterForm();
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         $this->form->bind($request->getParameter('register'));
         if ($this->form->isValid()) {
             mysfLog::log($this, "DEBUG: " . print_r($this->form->getValues(), TRUE));
             $this->form_ref =& $this->form;
             $username = $this->form->getValue('email');
             $password = $this->form->getValue('password');
             $sfGuardUser = new sfGuardUser();
             $sfGuardUser->setUsername($username);
             $sfGuardUser->setPassword($password);
             // Not until confirmed
             $sfGuardUser->setIsActive(false);
             $profile = $sfGuardUser->getProfile();
             $sfGuardUser->save();
             // save sfGuardUser before we populate the user profile because we need the user id
             $this->myPopulateProfileSettings($profile, $sfGuardUser);
             $profile->save();
             // Email start
             $opts = array();
             $opts['from_name'] = sfConfig::get('app_mail_fromname', "Spectralmind");
             $opts['from_email'] = sfConfig::get('app_mail_from', "*****@*****.**");
             $opts['parameters'] = array('validate' => $profile->getValidate());
             $opts['body_is_partial'] = true;
             $opts['to_name'] = $profile->getName();
             $opts['to_email'] = $profile->getEmail();
             $opts['subject'] = sfConfig::get('app_mail_subjectconfirmmail', "Confirm your registration");
             //$opts['html'] = "sendValidateNew";
             $opts['text'] = "sendValidateNew";
             /*
             				 // Or to use the Echo Logger
             				 $logger = new Swift_Plugins_Loggers_EchoLogger();
             				 $this->getMailer()->registerPlugin(new Swift_Plugins_LoggerPlugin($logger));
             				 * */
             $numSent = smintMailHelper::mail($opts);
             // not sent? react accordingly
             if ($numSent != 1) {
                 mysfLog::log($this, "ERROR: confirmation email not sent. Return value was {$numSent}");
                 return 'Error';
             }
             mysfLog::log($this, "DEBUG: Confirm link:" . url_for("sfApply/confirm?validate=" . $profile->getValidate(), true));
             return 'After';
         }
     }
 }
示例#10
0
 /**
  * DOCUMENT ME
  * @return mixed
  */
 public static function getTaskUser()
 {
     $user = Doctrine::getTable('sfGuardUser')->findOneByUsername('ataskuser');
     if (!$user) {
         $user = new sfGuardUser();
         $user->setUsername('ataskuser');
         // Set a good unique password just in case someone cluelessly sets the active flag.
         // This further ensures that no one can ever log in with this account
         $user->setPassword(aGuid::generate());
         // Prevents normal login
         $user->setIsActive(false);
         $user->setIsSuperAdmin(true);
         $user->save();
     }
     return $user;
 }
示例#11
0
 /**
  * Executes register action
  *
  * @param sfWebRequest $request A request object
  */
 public function executeRegister(sfWebRequest $request)
 {
     if (!StoreTable::getInstance()->getValueCached(StoreTable::REGISTER_ON)) {
         return $this->notFound();
     }
     $user = new sfGuardUser();
     $this->form = new RegisterForm($user);
     if ($request->getGetParameter('widgetval')) {
         $storage = sfContext::getInstance()->getStorage();
         if ($storage instanceof policatSessionStorage) {
             $storage->needSession();
         }
         $this->getUser()->setAttribute(myUser::SESSION_WIDGETVAL_ON, 1);
     }
     if ($request->isMethod('post')) {
         if (!$this->getUser()->human()) {
             return $this->captchaModal();
         }
         $this->form->bind($request->getPostParameter($this->form->getName()));
         if ($this->form->isValid()) {
             $user->setIsActive(false);
             $user = $this->form->updateObject();
             $user->setUsername($user->getEmailAddress());
             $user->setValidationKind(sfGuardUserTable::VALIDATION_KIND_REGISTER_LINK);
             $user->randomValidationCode();
             $user->save();
             $user->addPermissionByName(myUser::CREDENTIAL_USER);
             $subject = 'validate register';
             $body = "#VALIDATION-URL#";
             $store = StoreTable::getInstance()->findByKeyAndLanguageWithFallback(StoreTable::REGISTER_MAIL, $user->getLanguageId());
             if ($store) {
                 $subject = $store->getField('subject');
                 $body = $store->getField('body');
             }
             $subst = array('#VALIDATION-URL#' => $this->generateUrl('register_validation', array('id' => $user->getId(), 'code' => $user->getValidationCode()), true), '#USER-NAME#' => $user->getFullName());
             UtilMail::send(null, null, $user->getEmailAddress(), $subject, $body, null, $subst);
             return $this->ajax()->form($this->form)->attr('#register_form input, #register_form select, #register_form button', 'disabled', 'disabled')->scroll()->alert('Congratulations! You have created a new account. For your first login, you need to check your inbox ' . 'and click the account validation link in the e-mail we have sent to you.', 'Please check your inbox now!', '.page-header', 'after')->render();
         } else {
             return $this->ajax()->form($this->form)->render();
         }
     }
     $this->includeChosen();
 }
示例#12
0
 public function executeApply()
 {
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         $username = $this->getRequestParameter('username');
         $password = $this->getRequestParameter('password');
         $sfGuardUser = new sfGuardUser();
         $sfGuardUser->setUsername($username);
         $sfGuardUser->setPassword($password);
         // Not until confirmed
         $sfGuardUser->setIsActive(false);
         $profile = $sfGuardUser->getProfile();
         $this->populateProfileSettings($profile);
         $sfGuardUser->save();
         $profile->save();
         $this->setFlash('sfApplyPlugin_id', $sfGuardUser->getId(), false);
         $this->sendEmail('sfApply', 'sendValidate');
         return 'After';
     }
 }
示例#13
0
 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');
 }
示例#14
0
 public function executeIdentification(sfWebRequest $request)
 {
     if (!$this->getUser()->isAuthenticated()) {
         $this->formInscription = new InscriptionForm();
         $class = sfConfig::get('app_sf_guard_plugin_signin_form', 'sfGuardFormSignin');
         $this->form = new $class();
         if ($request->ismethod('post')) {
             if ($request->getParameter('send') == "signin") {
                 $this->form->bind($request->getParameter('signin'));
                 if ($this->form->isValid()) {
                     $values = $this->form->getValues();
                     $this->getUser()->signin($values['user'], array_key_exists('remember', $values) ? $values['remember'] : false);
                     if ($this->getUser()->getAttribute('montantLocation')) {
                         $paypal = new PayPal();
                         $ret = $paypal->doExpressCheckout($this->getUser()->getAttribute('montantLocation'), 'Location de la voiture');
                         print_r($ret);
                     } else {
                         $this->redirect('espace_membre_profil');
                     }
                 }
             } else {
                 if ($request->getParameter('send') == "signup") {
                     $this->formInscription->bind($request->getParameter('signup'));
                     if ($this->formInscription->isValid()) {
                         $values = $this->formInscription->getValues();
                         //print_r($values);
                         //exit;
                         $user = new sfGuardUser();
                         $user->setEmailAddress($values['email_address']);
                         $user->setUsername($values['email_address']);
                         $user->setLastName($values['nom']);
                         $user->setFirstName($values['prenom']);
                         $user->setPassword($values['password1']);
                         $user->setIsActive(1);
                         $user->getProfile()->setAdresse($values['adresse']);
                         $user->getProfile()->setCodepostal($values['codepostal']);
                         $user->getProfile()->setVille($values['ville']);
                         $user->getProfile()->setFixe($values['fixe']);
                         $user->getProfile()->setMobile($values['mobile']);
                         $user->getProfile()->setDateNaissance($values['date_naissance']);
                         $user->getProfile()->setNumeroPermis($values['numero_permis']);
                         $user->getProfile()->setVilleDelivrance($values['ville_permis']);
                         $user->getProfile()->setPaysDelivrance($values['pays_permis']);
                         $user->getProfile()->setDateDelivrance($values['date_delivrance_permis']);
                         $user->getProfile()->setIsActivated(1);
                         $user->addGroupByName("client");
                         $user->save();
                         $this->getUser()->setAttribute('email_address', $values['email_address']);
                         $message = $this->getMailer()->compose(sfConfig::get('app_mail_saidi'), $values['email_address'], '[Mobilyrent] - Inscription Mobilyrent location de voiture', '[Mobilyrent] - Inscription Mobilyrent location de voiture');
                         $this->getMailer()->send($message);
                         //echo $this->getUser()->getAttribute('montantLocation');exit;
                         if ($this->getUser()->getAttribute('montantLocation')) {
                             $paypal = new PayPal();
                             $ret = $paypal->doExpressCheckout($this->getUser()->getAttribute('montantLocation'), 'Location de la voiture');
                             print_r($ret);
                         }
                         //$this->getUser()->setFlash('notice', sprintf('Inscription terminée.<br/>Un email vous a été envoyé. Connectez vous et continuer votre reservation.'));
                     }
                 }
             }
         }
     } else {
         $paypal = new PayPal();
         $ret = $paypal->doExpressCheckout($this->getUser()->getAttribute('montantLocation'), 'Location de la voiture');
         print_r($ret);
     }
 }
示例#15
0
 protected function processOrganizerForm(sfWebRequest $request, sfForm $form)
 {
     //$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         //$form->save();
         $name = $form->getValue('name');
         $email = $form->getValue('email');
         //$colour = $form->getValue('colour_code');
         $guard_user = new sfGuardUser();
         $guard_user->setEmailAddress($email);
         $guard_user->setUsername($email);
         $guard_user->setPassword($form->getValue('password'));
         $guard_user->setIsActive(1);
         $guard_user->save();
         $organizer = new Organizer();
         $organizer->setName($name);
         $organizer->setSfGuardId($guard_user->getId());
         //$organizer->setColourCode($colour);
         $organizer->save();
         $this->redirect('organize/new');
     }
 }
示例#16
0
 protected function doSave($con = null)
 {
     //--------------------------------------------------------------------------
     // populate objects related to ReservationForm & ClientForm with posted data
     //--------------------------------------------------------------------------
     $this->updateObject();
     //--------------------------------------------------------------------------
     // get populated reservation object
     //--------------------------------------------------------------------------
     $reservation = $this->getObject();
     //--------------------------------------------------------------------------
     // if it's a new reservation we have to make sure to detect existing clients
     // and retrieve their client id if it's the case
     //--------------------------------------------------------------------------
     if ($this->isNew()) {
         if (isset($this->embeddedForms['client'])) {
             //----------------------------------------------------------------------
             // check if the client exists, if not, save and get new client id
             //----------------------------------------------------------------------
             $values = $this->getValue('client');
             if (null == ($client = Doctrine::getTable('Client')->getByEmail($values['email_address']))) {
                 //--------------------------------------------------------------------
                 // create login user
                 //--------------------------------------------------------------------
                 $sfGuardUser = new sfGuardUser();
                 $sfGuardUser->first_name = $values['firstname'];
                 $sfGuardUser->last_name = $values['lastname'];
                 $sfGuardUser->username = $values['email_address'];
                 $sfGuardUser->email_address = $values['email_address'];
                 $sfGuardUser->setPassword('admin');
                 $sfGuardUser->setIsActive(true);
                 $sfGuardUser->save();
                 //--------------------------------------------------------------------
                 // save object related to ClientForm
                 //--------------------------------------------------------------------
                 $client = $this->embeddedForms['client']->object;
                 $client->sf_guard_user_id = $sfGuardUser->id;
                 $client->save();
             }
             $reservation->client_id = $client->id;
         } else {
             $reservation->client_id = $this->getOption('client_id');
         }
         //------------------------------------------------------------------------
         // add the uniqe confirmation id and set initial status
         //------------------------------------------------------------------------
         $reservation->uniqid = 'pending';
         $reservation->status = 'open';
         $reservation->firstname = $values['firstname'];
         $reservation->lastname = $values['lastname'];
     } else {
         // triggered only when updating reservations
         self::$dispatcher->notify(new sfEvent($reservation, 'reservation.pre_update'));
     }
     //--------------------------------------------------------------------------
     // the price depends on destination, round_trip and no_pax
     //--------------------------------------------------------------------------
     $reservation->price = Doctrine::getTable('Transfer')->getPrice($reservation->destination_id, $reservation->round_trip, $reservation->no_pax);
     $reservation->save();
     $reservation->uniqid = strtoupper(base_convert((int) sprintf('1%07d', $reservation->id), 10, 36));
     $reservation->save();
     self::$dispatcher->notify(new sfEvent($reservation, $this->isNew() ? 'reservation.created' : 'reservation.post_update'));
 }
 /**
  * Method to activate user
  * @param sfGuardUser $user
  * @author Grzegorz Śliwiński
  */
 protected function activateUser(sfGuardUser $user)
 {
     $user->setIsActive(true);
     $user->save();
     $this->getUser()->signIn($user);
 }
示例#18
0
 public function executeEdit(sfWebRequest $request)
 {
     $id = $request->getParameter('id');
     if (is_numeric($id)) {
         $user = sfGuardUserTable::getInstance()->find($id);
         /* @var $user sfGuardUser */
         if (!$user) {
             return $this->notFound();
         }
     } else {
         $user = new sfGuardUser();
         $user->setIsActive(false);
     }
     if (!$this->getGuardUser()->getIsSuperAdmin() && $user->getIsSuperAdmin()) {
         $this->noAccess();
     }
     if ($user->isNew()) {
         $this->form = new UserNewForm($user);
     } else {
         $this->form = new UserForm($user);
     }
     if ($request->isMethod('post')) {
         $this->form->bind($request->getPostParameter($this->form->getName()));
         if ($this->form->isValid()) {
             $con = sfGuardUserTable::getInstance()->getConnection();
             $con->beginTransaction();
             try {
                 $this->form->updateGroupsList($this->form->getValues());
                 $user = $this->form->updateObject();
                 $user->setUsername($user->getEmailAddress());
                 if ($user->isNew()) {
                     $user->setValidationKind(sfGuardUserTable::VALIDATION_KIND_BACKEND_LINK);
                     $user->randomValidationCode();
                     $user->save();
                     $subject = 'validate activation';
                     $body = "#VALIDATION-URL#";
                     $store = StoreTable::getInstance()->findByKeyAndLanguageWithFallback(StoreTable::NEW_USER_ADMIN_MAIL, $user->getLanguageId());
                     if ($store) {
                         $subject = $store->getField('subject');
                         $body = $store->getField('body');
                     }
                     $subst = array('#VALIDATION-URL#' => $this->generateUrl('user_validation', array('id' => $user->getId(), 'code' => $user->getValidationCode()), true), '#USER-NAME#' => $user->getFullName());
                     UtilMail::send(null, null, $user->getEmailAddress(), $subject, $body, null, $subst);
                 } else {
                     $user->save();
                 }
                 $con->commit();
             } catch (Exception $e) {
                 $con->rollback();
                 throw $e;
             }
             return $this->ajax()->redirectRotue('user_idx')->render();
         } else {
             return $this->ajax()->form($this->form)->render();
         }
     }
     if (!$user->isNew()) {
         $this->campaign_rights_list = CampaignRightsTable::getInstance()->queryByUser($user)->execute();
         $this->petition_rights_list = PetitionRightsTable::getInstance()->queryByUser($user)->execute();
     }
 }
示例#19
0
 public function executeSignin($request)
 {
     $this->op = $request->getParameter('op');
     //echo $this->op;
     //die;
     $dialog = $request->getParameter('dialog', false);
     /* IF FB CONNECT */
     if ($this->op == 'fbc' && ($facebook_uid = VoFacebook::getUid())) {
         //echo "FBC";die;
         $c = new Criteria();
         $c->addJoin(SfGuardUserProfilePeer::USER_ID, SfGuardUserPeer::ID);
         $c->add(SfGuardUserProfilePeer::FACEBOOK_UID, $facebook_uid);
         $sfGuardUser = SfGuardUserPeer::doSelectOne($c);
         if (!$sfGuardUser instanceof sfGuardUser) {
             // Comprobación de que no existe ya el usuario con ese username (bug #734)
             $c = new Criteria();
             $c->add(sfGuardUserPeer::USERNAME, 'Facebook_' . $facebook_uid);
             $existingUser = sfGuardUserPeer::doSelectOne($c);
             if ($existingUser) {
                 $existingUser->setUsername('Facebook_' . $facebook_uid . '-' . time());
                 $existingUser->save();
             }
             $sfGuardUser = new sfGuardUser();
             $sfGuardUser->setUsername('Facebook_' . $facebook_uid);
             $sfGuardUser->save();
             $voProfile = $sfGuardUser->getProfile();
             $vanityUrl = SfVoUtil::encodeVanity('Facebook_' . $facebook_uid);
             $voProfile->setFacebookUid($facebook_uid);
             if (!$voProfile->getNombre()) {
                 $data = VoFacebook::getData($voProfile->getFacebookUid());
                 $voProfile->setNombre($data->first_name);
                 $voProfile->setApellidos($data->last_name);
             }
             $c2 = new Criteria();
             $c2->add(SfGuardUserProfilePeer::VANITY, "{$vanityUrl}%", Criteria::LIKE);
             $usuariosLikeMe = SfGuardUserProfilePeer::doSelect($c2);
             $counter = 0;
             foreach ($usuariosLikeMe as $usuarioLikeMe) {
                 if (preg_match("/^Facebook_{$facebook_uid}-([0-9]*)/i", $usuarioLikeMe->getVanity(), $matches)) {
                     $curIdx = $matches[1];
                     if ($curIdx > $counter) {
                         $counter = $curIdx + 1;
                     }
                 } else {
                     $counter++;
                 }
             }
             $voProfile->setVanity("{$vanityUrl}" . ($counter == 0 ? '' : "-{$counter}"));
             $voProfile->setMailsComentarios(0);
             $voProfile->setMailsNoticias(0);
             $voProfile->setMailsContacto(0);
             $voProfile->setMailsSeguidor(0);
             $voProfile->save();
         }
         $this->getUser()->signin($sfGuardUser, false);
         $signinUrl = sfConfig::get('app_sf_guard_plugin_success_signin_url', $this->getUser()->getReferer('@homepage'));
         $this->redirect($signinUrl);
     }
     /* FI FB CONNECT */
     $this->registrationform = new RegistrationForm();
     $this->signinform = new SigninForm();
     if ($request->isMethod('post') && !$dialog) {
         // Register
         if ($this->op == 'r') {
             $this->registrationform = new RegistrationForm();
             $this->registrationform->bind($request->getParameter('registration'));
             if ($this->registrationform->isValid()) {
                 $user = new sfGuardUser();
                 $user->setUsername($this->registrationform->getValue('username'));
                 $user->setPassword($this->registrationform->getValue('password'));
                 $user->setIsActive(0);
                 $user->setCreatedAt(time());
                 $c = new Criteria();
                 $c->add(sfGuardUserPeer::USERNAME, $user->getUsername());
                 sfGuardUserPeer::doInsert($user);
                 $user = sfGuardUserPeer::doSelect($c);
                 if (count($user) == 1) {
                     $profile = $user[0]->getProfile();
                     $profile->setNombre($this->registrationform->getValue('nombre'));
                     $profile->setApellidos($this->registrationform->getValue('apellidos'));
                     $profile->setPresentacion($this->registrationform->getValue('presentacion'));
                     $profile->setAnonymous($this->registrationform->getValue('anonymous'));
                     $profile->setCodigo(util::generateUID());
                     /* Generar vanity */
                     if ($profile->getVanity() == '') {
                         $vanityUrl = SfVoUtil::encodeVanity($profile->getNombre() . "-" . $profile->getApellidos());
                         $c2 = new Criteria();
                         $c2->add(SfGuardUserProfilePeer::VANITY, "{$vanityUrl}%", Criteria::LIKE);
                         $c2->add(SfGuardUserProfilePeer::ID, $user[0]->getId(), Criteria::NOT_EQUAL);
                         $usuariosLikeMe = SfGuardUserProfilePeer::doSelect($c2);
                         $counter = 0;
                         foreach ($usuariosLikeMe as $usuarioLikeMe) {
                             $counter++;
                         }
                         $profile->setVanity("{$vanityUrl}" . ($counter == 0 ? '' : "-{$counter}"));
                     }
                     /* Fin Generar vanity */
                     sfGuardUserProfilePeer::doInsert($profile);
                     $this->sendWelcome($user[0]);
                     $this->user = $user[0];
                     return "Registered";
                 }
             }
             /*
             else {
                   		$this->getUser()->setFlash('notice_type', 'error', false);
                   		$this->getUser()->setFlash('notice', sfVoForm::getFormNotValidMessage(), false);
             }
             */
         } else {
             $r = new SigninForm();
             $r->bind($request->getParameter('signin'));
             if ($r->isValid()) {
                 $r->addPostValidation();
                 $r->bind($request->getParameter('signin'));
                 if ($r->isValid()) {
                     $this->doSignin($request, $this->op);
                 }
             }
             /*
             	      else {
                   		$this->getUser()->setFlash('notice_type', 'error', false);
                   		$this->getUser()->setFlash('notice', sfVoForm::getFormNotValidMessage(), false);
             }
             */
             $this->signinform = $r;
         }
     }
     $this->title = sfContext::getInstance()->getI18N()->__('Acceso usuarios', array());
     $this->title .= ' - Voota';
     $this->response->setTitle($this->title);
     if ($this->op == 'fb') {
         return 'FB';
     }
 }
示例#20
0
 public function ajouterUtilisateur($values)
 {
     $user = new sfGuardUser();
     $user->setEmailAddress($values['email_address']);
     $user->setUsername($values['email_address']);
     $user->setLastName($values['nom']);
     $user->setFirstName($values['prenom']);
     $user->setPassword($values['password1']);
     $user->setIsActive(1);
     $user->getProfile()->setAdresse($values['adresse']);
     $user->getProfile()->setCodepostal($values['codepostal']);
     $user->getProfile()->setVille($values['ville']);
     $user->getProfile()->setFixe($values['fixe']);
     $user->getProfile()->setMobile($values['mobile']);
     $user->getProfile()->setDateNaissance($values['date_naissance']);
     $user->getProfile()->setNumeroPermis($values['numero_permis']);
     $user->getProfile()->setVilleDelivrance($values['ville_permis']);
     $user->getProfile()->setPaysDelivrance($values['pays_permis']);
     $user->getProfile()->setDateDelivrance($values['date_delivrance_permis']);
     $user->getProfile()->setIsActivated(1);
     $user->addGroupByName("client");
     $user->save();
     $this->getUser()->setAttribute('email_address', $values['email_address']);
     return $user;
 }
 protected function createUserAndProfile($username, $con = null)
 {
     // no user with this username
     if (null === $con) {
         $con = Propel::getConnection(sfGuardUserPeer::DATABASE_NAME);
     }
     try {
         $con->begin();
         // create a new user object
         $user = new sfGuardUser();
         $user->setUsername($username);
         $user->setIsActive(1);
         $user->setAlgorithm('');
         $user->save($con);
         // do we have a profile in the system with this net_id?
         // this could happen if the profile was added manually by an admin
         $userProfile = UserProfilePeer::selectByNetIdWithNoUserId($username);
         if ($userProfile) {
             // there is already a dangling user profile with this net id, link the user with the profile
             $userProfile->setUserId($user->getId());
             $userProfile->save($con);
         } else {
             // make a new user profile
             $userProfile = new UserProfile();
             $userProfile->setUserId($user->getId());
             $userProfile->setNetId($user->getUsername());
             $userProfile->save($con);
         }
         $con->commit();
     } catch (PropelException $e) {
         $con->rollback();
         throw $e;
     }
     return $user;
 }