Beispiel #1
0
 public function getUserReserve()
 {
     if (isset($userReserve)) {
         return $userReserve;
     }
     return $userReserve = sfGuardUserTable::getInstance()->getUserById($this->getIdUserReserve())->fetchOne();
 }
Beispiel #2
0
 public function executeEdit(sfWebRequest $request)
 {
     //Get user Id
     $userId = $this->getUser()->getGuardUser()->getId();
     $sf_guard_user = sfGuardUserTable::getInstance()->findOneById($userId);
     $this->form = new sfGuardUserForm($sf_guard_user);
 }
 protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     $applicationConfig = sfProjectConfiguration::getApplicationConfiguration('frontend', 'prod', true);
     $context = sfContext::createInstance($applicationConfig);
     // Go to the Subreddit and obtain the past few keys.
     $reddit_location = $options['subreddit'];
     $reddit = new RedditObject($reddit_location);
     $quiet = (bool) $options['quiet'];
     if (!$quiet) {
         echo "Obtaining the most recent comments from {$reddit_location}...";
     }
     $reddit->appendData();
     $found_keys = count($reddit->getComments());
     if (!$quiet) {
         echo "\nFound {$found_keys} keys.  Updating keys in the database...";
     }
     ValidationTable::getInstance()->storeNewKeys($reddit->getComments());
     // Now that new keys are stored in the database we need to update all applicable users
     $users = sfGuardUserTable::getInstance()->getUsersToBeValidated();
     $updated = sfGuardUserTable::getInstance()->validateUsers($users);
     if (!$quiet) {
         echo "\nSending emails...";
     }
     foreach ($users as $user_id) {
         $sf_user = $context->getUser();
         $sf_user->setApiUserId($user_id);
         $sf_user->sendMail('RedditValidationSucceeded');
     }
     if (!$quiet) {
         echo "\n{$updated} users validated and email sent.\n";
     }
 }
 public function postValidateForm($validator, $values)
 {
     if (isset($values['promo_code'])) {
         $promo_code = PromoCodeTable::getInstance()->findOneByCode($values['promo_code']);
         if (!$promo_code) {
             throw new sfValidatorError($validator, 'Promotion Code is invalid');
         } else {
             $values['account_type'] = $promo_code->account_type;
         }
     }
     /** @var sfGuardUser $user */
     $user = sfGuardUserTable::getInstance()->createQuery('u')->where('u.email_address = ?', $values['email_address'])->fetchOne();
     if ($user && $values['password']) {
         if ($user->getIsActive() && $user->checkPassword($values['password'])) {
             sfContext::getInstance()->getUser()->signIn($user);
             sfContext::getInstance()->getController()->redirect('/project');
         } else {
             throw new sfValidatorError($validator, 'The email and/or password is invalid');
         }
     }
     $email = $values['email_address'];
     $domain = strtolower(substr($email, strpos($email, '@') + 1));
     if (DomainTable::getInstance()->findOneBy('name', $domain)) {
         $error = new sfValidatorError($validator, 'That looks like a personal email address. Please use your company email.');
         throw new sfValidatorErrorSchema($validator, array('email_address' => $error));
     }
     return $values;
 }
 protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     $applicationConfig = sfProjectConfiguration::getApplicationConfiguration('frontend', 'prod', true);
     $context = sfContext::createInstance($applicationConfig);
     $one_day_users = sfGuardUserTable::getInstance()->getOneDayEmailReminders();
     $one_week_users = sfGuardUserTable::getInstance()->getOneWeekEmailReminders();
     $quiet = (bool) $options['quiet'];
     if (!$quiet) {
         echo "Sending one-day reminder emails to  " . count($one_day_users) . " users...";
     }
     foreach ($one_day_users as $user) {
         $sf_user = $context->getUser();
         $sf_user->setApiUserId($user->getIncremented());
         $sf_user->sendMail('RegisterOneDay');
     }
     if (!$quiet) {
         echo "\nSending one-week reminder emails to " . count($one_week_users) . " users...";
     }
     foreach ($one_week_users as $user) {
         $sf_user = $context->getUser();
         $sf_user->setApiUserId($user->getIncremented());
         $sf_user->sendMail('RegisterOneWeek');
     }
     if (!$quiet) {
         echo "\n";
     }
 }
Beispiel #6
0
 public function executeImportTrello(sfWebRequest $request)
 {
     $this->external_ids = array();
     $external_decisions = DecisionTable::getInstance()->createQuery('d')->select('d.external_id')->where('d.external_id IS NOT NULL')->andWhereIn('d.user_id', sfGuardUserTable::getInstance()->getUsersInTeamIDs($this->getUser()->getGuardUser()))->fetchArray();
     foreach ($external_decisions as $external_decision) {
         $this->external_ids[] = $external_decision['external_id'];
     }
 }
Beispiel #7
0
 public function executeIndex(sfWebRequest $request)
 {
     if ($this->getUser()->isAuthenticated() && $this->getUser()->getGuardUser()->account_type != 'Trial') {
         $this->getUser()->setFlash('notice', 'You are already registered and signed in!');
         $this->redirect('/project');
     }
     if ($this->getUser()->isAuthenticated()) {
         $user = $this->getUser()->getGuardUser();
         $user->email_address = '';
         $user->account_type = 'Free';
         $this->form = new sfGuardRegisterForm($user);
     } else {
         $this->form = new sfGuardRegisterForm();
         if ($this->getUser()->getAttribute('google_token')) {
             $google_token = json_decode($this->getUser()->getAttribute('google_token'));
             $browser = new sfWebBrowser(array(), null, array('ssl_verify_host' => false, 'ssl_verify' => false));
             $result = $browser->get('https://www.googleapis.com/oauth2/v1/userinfo?access_token=' . $google_token->access_token);
             if ($result->getResponseCode() == 200) {
                 $response_text = json_decode($result->getResponseText());
                 if (property_exists($response_text, 'email')) {
                     $user_exists = sfGuardUserTable::getInstance()->createQuery('u')->where('email_address = ?', $response_text->email)->fetchOne();
                     if (is_object($user_exists)) {
                         $this->getUser()->setAttribute('google_token', null);
                         if ($user_exists->is_active) {
                             $this->getUser()->signIn($user_exists);
                             $this->redirect('/project');
                         } else {
                             $this->getUser()->setFlash('notice', 'Check your e-mail! You should verify your email address.');
                             $this->redirect('@sf_guard_signin');
                         }
                     }
                     $this->getUser()->setAttribute('google_token_info', array($response_text->email => array('given_name' => $response_text->given_name, 'family_name' => $response_text->family_name)));
                     $this->form->setDefault('email_address', $response_text->email);
                     //            $this->form->getWidget('email_address')->setAttribute('readonly', 'readonly');
                 }
             }
         }
     }
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter($this->form->getName()));
         if ($this->form->isValid()) {
             $user = $this->form->save();
             $google_token_info = $this->getUser()->getAttribute('google_token_info');
             $this->getUser()->setAttribute('google_token', null);
             $this->getUser()->setAttribute('google_token_info', null);
             if (is_array($google_token_info) && array_key_exists($user->email_address, $google_token_info)) {
                 $user->first_name = $google_token_info[$user->email_address]['given_name'];
                 $user->last_name = $google_token_info[$user->email_address]['family_name'];
                 $user->is_active = true;
                 @$user->save();
                 $this->getUser()->signIn($user);
                 $this->redirect('/project');
             } else {
                 $this->sendConfirmationEmail($user);
             }
         }
     }
 }
 /**
  * @param sfGuardUser $user
  */
 private function load_data(sfGuardUser $user)
 {
     $rows = $this->createQuery('il')->whereIn('il.user_id', sfGuardUserTable::getInstance()->getUsersInTeamIDs($user))->fetchArray();
     $this->data = array();
     foreach ($rows as $row) {
         $this->data[$row['type']] = array('singular' => $row['singular'], 'plural' => $row['plural']);
     }
     $this->loaded = true;
 }
 public function verifyUnique($validator, $values)
 {
     if (sfGuardUserTable::getInstance()->findOneBy('email_address', $values['email_address'])) {
         sfContext::getInstance()->getConfiguration()->loadHelpers(array('Url'));
         $error = new sfValidatorError($validator, 'You are already registered, maybe you <a href="' . url_for('@sf_guard_forgot_password') . '">Forgot the password</a>?');
         throw new sfValidatorErrorSchema($validator, array('email_address' => $error));
     }
     return $values;
 }
Beispiel #10
0
 public function executeListExportCsv(sfWebRequest $request)
 {
     $this->pDomainProfiles = DomainProfileTable::getInstance()->createQuery()->orderBy('created_at DESC')->execute();
     $this->pOtherUsers = sfGuardUserTable::getInstance()->createQuery()->from('SfGuardUser s')->leftJoin('s.DomainProfiles d')->where('d.id IS NULL')->execute();
     $this->setLayout('csv');
     $this->getResponse()->clearHttpHeaders();
     $this->getResponse()->setHttpHeader("Content-Type", 'text/plain');
     $this->getResponse()->setHttpHeader('Content-Disposition', 'attachment; filename=DomainProfiles-' . date("Y-m-d") . '.txt;');
 }
 public function executeList()
 {
     $filter_form = new FilterUserForm();
     $filter_form->bindSelf('user');
     $this->form = $filter_form;
     $page = isset($this->page) ? $this->page : 1;
     $query = $filter_form->filter(sfGuardUserTable::getInstance()->queryAll($this->getUser()->isSuperAdmin()));
     $this->users = new policatPager($query, $page, 'user_pager', array(), true, 20);
 }
 public function configure()
 {
     $this->widgetSchema->setFormFormatterName('bootstrapInline');
     $this->widgetSchema->setNameFormat('resign_officer[%s]');
     $campaign = $this->getOption(self::OPTION_CAMPAIGN);
     $query = sfGuardUserTable::getInstance()->queryAdminsByCampaign($campaign);
     $this->setWidget('new', new sfWidgetFormDoctrineChoice(array('model' => 'sfGuardUser', 'query' => $query, 'method' => 'getFullName', 'label' => 'please select new one')));
     $this->setValidator('new', new sfValidatorDoctrineChoice(array('model' => 'sfGuardUser', 'query' => $query)));
 }
Beispiel #13
0
 public function configure()
 {
     unset($this['lft'], $this['rgt'], $this['level'], $this['root_id'], $this['user_id'], $this['created_at'], $this['updated_at'], $this['folder_id'], $this['external_id']);
     $this->setValidator('name', new sfValidatorDecisionName(array('max_length' => 255, 'required' => true, 'user_id' => $this->getObject()->user_id, 'decision_id' => $this->getObject()->id)));
     if ($this->getOption('type') == 'edit') {
         unset($this['type_id'], $this['template_id']);
     } else {
         $this->widgetSchema['template_id'] = new sfWidgetFormChoice(array('choices' => array()));
         if (isset($this->getObject()->user_id) && !empty($this->getObject()->user_id)) {
             $this->widgetSchema['type_id']->setOption('query', DecisionTypeTable::getInstance()->createQuery('t')->innerJoin('t.Users u')->where('u.id = ?', $this->getObject()->user_id));
         } else {
             $this->widgetSchema['type_id']->setOption('query', DecisionTypeTable::getInstance()->createQuery('t'));
         }
         $this->widgetSchema->setLabel('template_id', 'Template name');
         // One response is for dashboard by default
         if ($this->getObject()->Response->count() > 1) {
             $this->widgetSchema['template_id']->setAttribute('disabled', 'disabled');
             $this->widgetSchema->setHelp('template_id', 'Remove all responses first');
         }
         $this->validatorSchema['template_id']->setOption('required', false);
     }
     $this->widgetSchema['upload'] = new laWidgetFileUpload(array('module_partial' => 'decision/import'));
     $this->widgetSchema['assigned_to']->setOption('query', sfGuardUserTable::getInstance()->getUsersInTeamQuery($this->getObject()->getUser()));
     $this->widgetSchema['objective'] = new laWidgetFormCKEditor(array('config' => array('height' => '250px')));
     $this->validatorSchema['assigned_to']->setOption('query', sfGuardUserTable::getInstance()->getUsersInTeamQuery($this->getObject()->getUser()));
     /** @var sfWidget $widget */
     foreach ($this->widgetSchema->getFields() as $widget) {
         $widget->setAttribute('class', 'form-control autosave');
     }
     /* Get all tags and create input field */
     $tags = array();
     foreach ($this->getObject()->getTagDecision() as $tag) {
         $tags[] = $tag->Tag->name;
     }
     $this->widgetSchema['tags'] = new sfWidgetFormInputText(array(), array('value' => implode(',', $tags), 'class' => 'tags_input', 'data-role' => 'tagsinput'));
     $start_date_native = $this->getObject()->getStartDate();
     $end_date_native = $this->getObject()->getEndDate();
     $end_data = new DateTime($this->getObject()->getEndDate());
     $start_date = new DateTime($this->getObject()->getStartDate());
     $this->widgetSchema['start_date'] = new sfWidgetFormInputText(array(), array('value' => '', 'data-value' => !empty($start_date_native) && $start_date_native !== '0000-00-00 00:00:00' ? $start_date->format('Y/m/j') : ''));
     $this->widgetSchema['end_date'] = new sfWidgetFormInputText(array(), array('value' => '', 'data-value' => !empty($end_date_native) && $end_date_native !== '0000-00-00 00:00:00' ? $end_data->format('Y/m/j') : ''));
     $this->widgetSchema['color'] = new sfWidgetFormSelect(array('choices' => array('#FFFFFF' => '#FFFFFF', '#CCCCCC' => '#CCCCCC', '#A0522D' => '#A0522D', '#CD5C5C' => '#CD5C5C', '#FF4500' => '#FF4500', '#008B8B' => '#008B8B', '#B8860B' => '#B8860B', '#32CD32' => '#32CD32', '#FFD700' => '#FFD700', '#48D1CC' => '#48D1CC', '#87CEEB' => '#87CEEB', '#FF69B4' => '#FF69B4', '#87CEFA' => '#87CEFA', '#6495ED' => '#6495ED', '#DC143C' => '#DC143C', '#FF8C00' => '#FF8C00', '#C71585' => '#C71585', '#000000' => '#000000')));
     if ($this->isNew()) {
         $this->widgetSchema['assigned_to']->setDefault($this->getObject()->getUser()->getId());
         $now = new DateTime();
         $this->widgetSchema['start_date']->setDefault($now->format('Y/m/j'));
         $this->widgetSchema['start_date']->setAttribute('data-value', $now->format('Y/m/j'));
         $now = $now->modify('+1 month');
         $this->widgetSchema['end_date']->setDefault($now->format('Y/m/j'));
         $this->widgetSchema['end_date']->setAttribute('data-value', $now->format('Y/m/j'));
     }
     $this->disableCSRFProtection();
 }
 public function configure()
 {
     parent::configure();
     $this->useFields(array('name', 'enable_advanced', 'users_list'));
     $user_list_options = array('model' => 'sfGuardUser', 'order_by' => array('first_name', 'ASC'), 'renderer_class' => 'izarusWidgetFormBootstrapSelectDoubleList', 'renderer_options' => array('label_unassociated' => 'No asociados', 'label_associated' => 'Asociados'));
     if (method_exists(sfGuardUserTable::getInstance(), 'AdvancedLayoutList')) {
         $user_list_options['table_method'] = 'AdvancedLayoutList';
     }
     $this->widgetSchema['users_list'] = new sfWidgetFormDoctrineChoice($user_list_options);
     $this->widgetSchema->setLabels(array('name' => 'Nombre', 'enable_advanced' => 'Personalización Activada', 'users_list' => 'Usuarios con este permiso'));
     $this->widgetSchema->setHelps(array('enable_advanced' => 'Si está activada esta opción entonces será posible utilizar este permiso como Perfil de Acceso.'));
 }
Beispiel #15
0
 public function getUserResponse(sfGuardUser $user)
 {
     $request = $this->getRequest();
     if ($user->is_super_admin && $request->hasParameter('user_id')) {
         $request_user = sfGuardUserTable::getInstance()->find($request->getParameter('user_id'));
         if ($request_user) {
             return array('status' => 'success', 'result' => array('user_id' => $request_user->id, 'email' => $request_user->email_address, 'account_type' => $request_user->account_type));
         } else {
             return array('status' => 'error', 'error' => 'User not found');
         }
     }
     return array('status' => 'success', 'result' => array('user_id' => $user->id, 'email' => $user->email_address, 'account_type' => $user->account_type));
 }
 public function postUp()
 {
     $types = DecisionTypeTable::getInstance()->findAll();
     $users = sfGuardUserTable::getInstance()->findAll();
     foreach ($types as $type) {
         foreach ($users as $user) {
             $userType = new UserDecisionType();
             $userType->Type = $type;
             $userType->User = $user;
             $userType->save();
         }
     }
 }
Beispiel #17
0
 public function executeUser($request)
 {
     $id = $request->getParameter("id");
     $user = sfGuardUserTable::getInstance()->retrieveByUsernameOrEmailAddress($id);
     $this->forward404Unless($user);
     $hosts = array();
     foreach ($user->getDomainProfiles() as $domain_profile) {
         $hosts[] = $domain_profile->getUrl();
     }
     $lDm = MongoManager::getStatsDM();
     $this->activities = $lDm->createQueryBuilder("Documents\\AnalyticsActivity")->field("host")->in($hosts)->sort(array("date" => -1))->limit(10)->getQuery()->execute();
     $this->user = $user;
     $this->setLayout("atom_layout");
 }
 public function executeVerify(sfWebRequest $request)
 {
     $key = $request->getParameter('key');
     $user = sfGuardUserTable::getInstance()->findOneBy('email_authorization_key', $key);
     $this->forward404Unless($key && $user);
     $user->setIsAuthorized(true);
     $user->setAuthorizedAt(date('Y-m-d H:i:s'));
     $user->save();
     $this->getUser()->setApiUserId($user->getIncremented());
     $this->getUser()->sendMail('RegisterRedditPost');
     $this->getUser()->setFlash('notice', 'Your email address has been validated!  While you can technically log in you can\'t yet do much of anything.  You should have one final email waiting for you with your final instructions to get you started.');
     $this->getUser()->setFlash('email_link', $user->getEmailAddress());
     $this->redirect('@sf_guard_signin');
 }
Beispiel #19
0
 public function configure()
 {
     unset($this['lft'], $this['rgt'], $this['level'], $this['root_id'], $this['decision_id'], $this['files_list'], $this['created_at'], $this['updated_at'], $this['created_by'], $this['updated_by'], $this['type_id'], $this['item_id']);
     $this->widgetSchema['notes'] = $this->widgetSchema['additional_info'] = new laWidgetFormCKEditor(array('config' => array('height' => '75px')));
     $this->widgetSchema['upload'] = new laWidgetFileUpload();
     $this->widgetSchema['work_progress'] = new sfWidgetFormInputRange(array('min' => 0, 'max' => 100));
     /** @var sfWidget $widget */
     foreach ($this->widgetSchema->getFields() as $widget) {
         $widget->setAttribute('class', 'form-control');
     }
     /* Get all tags and create input field */
     $tags = array();
     foreach ($this->getObject()->getTagAlternative() as $tag) {
         $tags[] = $tag->Tag->name;
     }
     $this->widgetSchema['tags'] = new sfWidgetFormInputText(array(), array('value' => implode(',', $tags), 'class' => 'tags_input', 'data-role' => 'tagsinput'));
     /* Create field with relations */
     $related_alternatives_choices = array();
     if ($this->getOption('user')) {
         foreach (AlternativeTable::getInstance()->getListForUser($this->getOption('user')->getGuardUser()) as $alternative) {
             $related_alternatives_choices[$alternative->getId()] = $alternative->getName() . ' (' . $alternative->getDecision()->getName() . ')';
         }
     }
     unset($related_alternatives_choices[$this->getObject()->getId()]);
     $related_alternatives_default = array();
     foreach ($this->getObject()->getAlternativeRelation() as $related_alternative) {
         $related_alternatives_default[] = $related_alternative->to_id;
     }
     $this->widgetSchema['related_alternatives'] = new sfWidgetFormSelectMany(array('choices' => $related_alternatives_choices));
     $this->widgetSchema['related_alternatives']->setDefault($related_alternatives_default);
     $notify_date_native = $this->getObject()->getNotifyDate();
     $due_date_native = $this->getObject()->getDueDate();
     $due_data = new DateTime($this->getObject()->getDueDate());
     $notify_date = new DateTime($this->getObject()->getNotifyDate());
     $this->widgetSchema['notify_date'] = new sfWidgetFormInputText(array(), array('value' => '', 'data-value' => !empty($notify_date_native) && $notify_date_native !== '0000-00-00 00:00:00' ? $notify_date->format('Y/m/j') : ''));
     $this->widgetSchema['due_date'] = new sfWidgetFormInputText(array(), array('value' => '', 'data-value' => !empty($due_date_native) && $due_date_native !== '0000-00-00 00:00:00' ? $due_data->format('Y/m/j') : ''));
     if ($this->getOption('user')) {
         $assigned_to = array('' => '');
         $team_users = sfGuardUserTable::getInstance()->getUsersInTeamQuery($this->getOption('user')->getGuardUser())->execute();
         foreach ($team_users as $team_user) {
             $assigned_to[$team_user->getId()] = $team_user->getUserName();
         }
         $this->widgetSchema['assigned_to'] = new sfWidgetFormChoice(array('choices' => $assigned_to), array('class' => 'form-control'));
         if ($this->getObject()->isNew()) {
             $this->widgetSchema['assigned_to']->setDefault($this->getOption('user')->getGuardUser()->getId());
         }
     }
     $this->disableCSRFProtection();
 }
Beispiel #20
0
 /**
  * Try to login with the CAS server
  */
 public function login()
 {
     sfCAS::initPhpCAS();
     phpCAS::forceAuthentication();
     $username = phpCAS::getUser();
     $data = sfGuardUserTable::getInstance()->findOneBy('username', $username);
     if (!$data || $data->getPassword() == NULL && !$data->getIsActive()) {
         $data = $this->registerUser($username, $data);
     }
     if ($data) {
         $this->signin($data, false);
     } else {
         die('Unauthorized.');
     }
 }
 public function isValid()
 {
     $valid = parent::isValid();
     if ($valid) {
         $values = $this->getValues();
         $this->user = sfGuardUserTable::getInstance()->findOneBy('email_address', $values['email_address']);
         if ($this->user) {
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Beispiel #22
0
 /**
  * @param sfGuardUser $user
  * @param string $type
  * @return mixed|string|void
  */
 public function getForUserJSON(sfGuardUser $user, $type = 'project')
 {
     /** @var Folder[] $folders */
     $query = $this->createQuery('f');
     if ($type == 'project') {
         $query->leftJoin('f.Decisions d');
     } else {
         $query->leftJoin('f.Roadmaps r');
     }
     $query->leftJoin('f.User u')->leftJoin('u.TeamMember tm')->whereIn('f.user_id', sfGuardUserTable::getInstance()->getUsersInTeamIDs($user))->andWhere('f.type = ?', $type);
     $folders = $query->execute();
     $result = array();
     foreach ($folders as $folder) {
         $result[] = $folder->getRowData($type);
     }
     return json_encode($result);
 }
 /**
  * Request a new xAuth key for a user.
  *
  * @param string $email_address Email address of the user.
  * @param string $password      Password of the user.
  * @param int    $expires_in    How long the auth key should last. Max 1 year.
  * @return string|boolean       The auth key for this API.  False upon failure.
  */
 public function requestAuthKey($email_address, $password, $expires_in = 7200)
 {
     if (!$this->getIsActive()) {
         throw new sfException('API is inactive!');
     }
     // Attempt to find user by email address
     $user = sfGuardUserTable::getInstance()->findOneByEmailAddress($email_address);
     /* @var $user sfGuardUser */
     if (!$user) {
         throw new sfException('Email address or password is incorrect.');
     }
     // Find out how many failures in the past two minutes - max of five
     $failures = AuthFailureTable::getInstance()->countFailuresMadeInRecentSeconds($this->getIncremented(), $user->getIncremented(), 120);
     if ($failures >= 6) {
         throw new sfException('Too many failures. Please wait a few minutes and try again.');
     }
     if ($user && $user->checkPassword($password) && $user->getIsAuthorized() && $user->getIsActive()) {
         $year = 31536000;
         $expires_in = $expires_in >= $year ? $year : $expires_in;
         $user_auth = new sfGuardUserAuthKey();
         $user_auth->setSfGuardUser($user);
         $user_auth->setApiKey($this);
         $user_auth->setExpiresAt(date('Y-m-d H:i:s', time() + $expires_in));
         $auth_key = sha1(rand(0, 10000) . time());
         $user_auth->setAuthKey($auth_key);
         $user_auth->save();
         return $auth_key;
     }
     $failure = new AuthFailure();
     $failure->setSfGuardUser($user);
     $failure->setApiKey($this);
     $failure->save();
     if (!$user) {
         throw new sfException('Email address or password is incorrect.');
     } elseif (!$user->getIsActive()) {
         throw new sfException('Email address or password is incorrect.');
     } elseif (!$user->getIsAuthorized()) {
         throw new sfException('User has not validated their email address yet');
     } elseif (!$user->checkPassword($password)) {
         throw new sfException('Email address or password is incorrect.');
     } else {
         throw new sfException('An unexpected error occured.');
     }
 }
Beispiel #24
0
 public function executeDelete(sfWebRequest $request)
 {
     $request->checkCSRFProtection();
     $this->forward404Unless($tag = Doctrine_Core::getTable('Tag')->find(array($request->getParameter('id'))), sprintf('Object tag does not exist (%s).', $request->getParameter('id')));
     $team_members = sfGuardUserTable::getInstance()->getUsersInTeamQuery($this->getUser()->getGuardUser())->execute();
     $team_members_id = array();
     foreach ($team_members as $team_member) {
         $team_members_id[] = $team_member->id;
     }
     if (in_array($tag->user_id, $team_members_id)) {
         $tagAlternatives = TagAlternativeTable::getInstance()->findByTagId($tag->id);
         foreach ($tagAlternatives as $tagAlternative) {
             Doctrine_Query::create()->delete('Graph')->where('decision_id = ?', $tagAlternative->Alternative->decision_id)->execute();
         }
         Doctrine_Query::create()->delete('TagAlternative')->where('tag_id = ?', $tag->id)->execute();
         Doctrine_Query::create()->delete('TagDecision')->where('tag_id = ?', $tag->id)->execute();
         $tag->delete();
     }
     $this->redirect('tag/index');
 }
 public static function eventSubmit($event)
 {
     sfContext::getInstance()->getLogger()->notice("{DealListener} eventSubmit");
     $deal = $event->getSubject();
     $sender = array(sfConfig::get("app_email_address") => sfConfig::get("app_email_sender"));
     $admins = sfGuardUserTable::getInstance()->findByIsSuperAdmin(true);
     foreach ($admins as $admin) {
         sfContext::getInstance()->getLogger()->notice("{DealListener} Sending email to admin: " . $admin->getEmailAddress());
         try {
             sfContext::getInstance()->getMailer()->composeAndSend($sender, $admin->getEmailAddress(), '[Deal submitted]: ' . preg_replace('/\\n/', '', $deal->getName()), sfConfig::get("app_settings_url") . '/backend.php/approve_deal/approve/deal_id/' . $deal->getId());
         } catch (Exception $e) {
             sfContext::getInstance()->getLogger()->err("{DealListener} Failed to send email.\n" . $e->getMessage());
         }
     }
     sfContext::getInstance()->getLogger()->notice("{DealListener} Sending email to deal owner: " . $deal->getSfGuardUser()->getEmailAddress());
     try {
         $fullname = $deal->getSfGuardUser()->getProfile()->getFullname();
         $message = "" . "Hallo {$fullname},\n\nIhr Deal ist bei Spreadly eingegangen und wird in Kürze von einem Mitarbeiter bearbeitet. Sie erhalten so schnell wie möglich ein Mail mit der Freigabe.\n\nYour Deal has been submitted to Spreadly. It will be reviewed by an employee shortly. You will receive an email with our approval as soon as possible.\n\nViele Grüße & many regards\nSpreadly-Team\n\ninfo@spreadly.com\nekaabo GmbH\nGrundelbachstr. 84\nD-69469 Weinheim\ntel: +49 6201 845200\nfax: +49 6201 84520-29\nwww.ekaabo.de\nAmtsgericht Mannheim / HRB 701542\nGeschäftsführer: Marco Ripanti\nGet your button & Spread your likes –www.Spreadly.com\nWeblog – Blog.spreadly.com\n";
         sfContext::getInstance()->getMailer()->composeAndSend($sender, $deal->getSfGuardUser()->getEmailAddress(), '[Deal submitted]: ' . preg_replace('/\\n/', '', $deal->getName()), $message);
     } catch (Exception $e) {
         sfContext::getInstance()->getLogger()->err("{DealListener} Failed to send email.\n" . $e->getMessage());
     }
 }
 public function advancedImport()
 {
     foreach ($this->prepareData() as $item) {
         $alternative = null;
         if (array_key_exists('id', $item) && !empty($item['id'])) {
             $alternative = AlternativeTable::getInstance()->createQuery('a')->leftJoin('a.Decision d')->leftJoin('d.User u')->leftJoin('u.TeamMember tm')->whereIn('d.user_id', sfGuardUserTable::getInstance()->getUsersInTeamIDs($this->guard_user))->andWhere('a.item_id = ?', $item['id'])->andWhere('d.id = ?', $this->decision->getId())->fetchOne();
         }
         if (!is_object($alternative)) {
             $alternative = new Alternative();
             $alternative->setDecision($this->decision);
             $alternative->setCreatedBy($this->created_and_updated_by);
             $alternative->setUpdatedBy($this->created_and_updated_by);
         }
         $alternative->setName($item['name']);
         foreach (array('status', 'work progress', 'additional info', 'notes', 'due date', 'notify date') as $prop) {
             if (array_key_exists($prop, $item) && !empty($item[$prop])) {
                 $alternative->{str_replace(' ', '_', $prop)} = $item[$prop];
             }
         }
         if (array_key_exists('tags', $item)) {
             // Process tags
             $tags_request = array_map('trim', explode(',', $item['tags']));
             $tags = array();
             foreach ($alternative->getTagAlternative() as $tag) {
                 $tags[] = $tag->Tag->name;
             }
             foreach (array_diff($tags_request, $tags) as $result) {
                 Tag::newTag($this->guard_user, $alternative->getId(), $result, 'alternative');
             }
             foreach (array_diff($tags, $tags_request) as $result) {
                 Tag::removeTag($this->guard_user, $alternative->getId(), $result, 'alternative');
             }
         }
         $alternative->save();
     }
 }
Beispiel #27
0
 /**
  * @param sfGuardUser $user
  * @param $name
  * @param $decision_id
  * @return bool
  */
 public function verifyAvailableName($user, $name, $decision_id = 0)
 {
     $decisions = $this->createQuery('d')->leftJoin('d.User u')->leftJoin('u.TeamMember tm')->whereIn('d.user_id', sfGuardUserTable::getInstance()->getUsersInTeamIDs($user))->andWhere('d.name = ?', $name)->andWhere('d.id != ?', $decision_id)->count();
     return !(bool) $decisions;
 }
 public function executeResignDataOfficer(sfWebRequest $request)
 {
     $campaign = CampaignTable::getInstance()->findById($request->getParameter('id'), $this->userIsAdmin());
     /* @var $campaign Campaign */
     if (!$campaign) {
         return $this->ajax()->alert('Campaign not found', 'Error')->render();
     }
     if (!$this->getUser()->hasCredential(myUser::CREDENTIAL_SYSTEM) && !$this->getGuardUser()->isDataOwnerOfCampaign($campaign)) {
         return $this->ajax()->alert('You do not have the rights.', 'Error')->render();
     }
     $form = new ResignDataOfficerForm(array(), array(ResignDataOfficerForm::OPTION_CAMPAIGN => $campaign));
     if ($request->isMethod('post')) {
         $form->bind($request->getPostParameter($form->getName()));
         if ($form->isValid()) {
             $new_id = $form->getValue('new');
             /* @var $new sfGuardUser */
             if (!$campaign->getDataOwnerId() || $campaign->getDataOwnerId() != $new_id) {
                 if ($this->getUser()->hasCredential(myUser::CREDENTIAL_SYSTEM)) {
                     $this->removeOldResignAndCallTickets($campaign);
                     $campaign->setDataOwnerId($new_id);
                     $campaign->save();
                 } else {
                     $ticket = TicketTable::getInstance()->generate(array(TicketTable::CREATE_AUTO_FROM => true, TicketTable::CREATE_CAMPAIGN => $campaign, TicketTable::CREATE_CHECK_DUPLICATE => true, TicketTable::CREATE_KIND => TicketTable::KIND_RESIGN_DATA_OFFICER, TicketTable::CREATE_TO => sfGuardUserTable::getInstance()->find($new_id)));
                     if ($ticket) {
                         $con = TicketTable::getInstance()->getConnection();
                         $con->beginTransaction();
                         try {
                             $this->removeOldResignAndCallTickets($campaign);
                             $ticket->save();
                             $ticket->notifyAdmin();
                             $con->commit();
                         } catch (Exception $e) {
                             $con->rollback();
                             return $this->ajax()->alert('Transactional error', 'Error')->render();
                         }
                     } else {
                         // duplicate
                     }
                 }
             } else {
                 if ($campaign->getDataOwnerId() == $new_id) {
                     $this->removeOldResignAndCallTickets($campaign);
                 }
             }
             return $this->ajax()->modal('#resign_data_officer_modal', 'hide')->redirectRotue('campaign_edit_', array('id' => $campaign->getId()))->render();
         } else {
             return $this->ajax()->form_error_list($form, '#resign_data_officer_modal .modal-body')->render();
         }
     } else {
         return $this->ajax()->appendPartial('body', 'resignDataOfficer', array('form' => $form, 'campaign' => $campaign))->modal('#resign_data_officer_modal')->render();
     }
 }
 /** Signs the user in as the specified user[name] or email address.
  *
  * Note:  This actually injects a listener that will log the user in before
  *  the next request because the browser clears out the context before making
  *  the request ({@see sfBrowser->doCall()}).
  *
  * @param string|sfGuardUser $user
  *
  * @throws LogicException           If sfDoctrineGuardPlugin is not enabled.
  * @throws InvalidArgumentException If $user cannot be resolved to an
  *  sfGuardUser.
  * @return static
  */
 public function signin($user)
 {
     /* This functionality relies on sfDoctrineGuardPlugin. */
     $plugins = sfContext::getInstance()->getConfiguration()->getPlugins();
     if (!in_array('sfDoctrineGuardPlugin', $plugins)) {
         throw new LogicException(sprintf('Cannot invoke %s->%s(); sfDoctrineGuardPlugin is not enabled.', __CLASS__, __FUNCTION__));
     }
     if (is_string($user)) {
         $name = $user;
         $user = sfGuardUserTable::getInstance()->retrieveByUsernameOrEmailAddress($name);
         if (!$user) {
             throw new InvalidArgumentException(sprintf('No such user "%s".', $name));
         }
     }
     if (!$user instanceof sfGuardUser) {
         throw new InvalidArgumentException(sprintf('Invalid %s encountered; sfGuardUser or string expected.', is_object($user) ? get_class($user) : gettype($user)));
     }
     $this->addListener(new Test_Browser_Listener_Signin($user));
     return $this;
 }
Beispiel #30
0
 /**
  * Список пользователей
  */
 public function executeIndex(sfWebRequest $request)
 {
     $this->users = sfGuardUserTable::getInstance()->createQuery('u')->where('u.is_active = 1')->orderBy('u.username ASC')->execute()->getData();
 }