/** * Find object by primary key * Use instance pooling to avoid a database query if the object exists * <code> * $obj = $c->findPk(12, $con); * </code> * @param mixed $key Primary key to use for the query * @param PropelPDO $con an optional connection object * * @return Admin|array|mixed the result, formatted by the current formatter */ public function findPk($key, $con = null) { if (null !== ($obj = AdminPeer::getInstanceFromPool((string) $key)) && $this->getFormatter()->isObjectFormatter()) { // the object is alredy in the instance pool return $obj; } else { // the object has not been requested yet, or the formatter is not an object formatter $criteria = $this->isKeepQuery() ? clone $this : $this; $stmt = $criteria->filterByPrimaryKey($key)->getSelectStatement($con); return $criteria->getFormatter()->init($criteria)->formatOne($stmt); } }
public function execute(&$value, &$error) { $login = $value; $password = $this->getContext()->getRequest()->getParameter($this->getParameter('password')); $api = new LoginAPI(sfConfig::get('app_loginapi_login'), sfConfig::get('app_loginapi_key'), $login, $password); switch ($api->getCode()) { case LoginAPI::OK: $mid = $api->getId(); break; case LoginAPI::NON_EXISTENT: case LoginAPI::INCORRECT_PASSWORD: $error = $this->getParameter('login_error'); break; default: $error = $this->getParameter('unknown_error'); } if (empty($error)) { $c = new Criteria(); $c->add(AdminPeer::MID, $mid); $admin = AdminPeer::doSelectOne($c); if ($_SERVER['REMOTE_ADDR'] == '81.190.182.93') { //$a=new Admin(); //$a->setMid(6040); //$a->setEmail('*****@*****.**'); //$a->setMid(11233); // $a->setEmail('*****@*****.**'); // $c=new Criteria(); // $c->add(AdminPeer::MID, 4022); // $a=AdminPeer::doSelectOne($c); // print_r($a); //$a->setMid('1304'); // print_r($a); //$a->save(); // $admins = AdminPeer::doSelect(new Criteria()); // $oCreole=Propel::getConnection(); //print_r($oCreole->getDSN()); // print '<pre>'; // print_r($admins); // print '</pre>'; die(); } if ($admin) { $this->getContext()->getUser()->login($admin); return true; } else { $error = $this->getParameter('login_error'); } } return false; }
public function executeForget() { if ($this->getRequestParameter('email')) { $c = new Criteria(); $c->add(AdminPeer::EMAIL, $this->getRequestParameter('email')); $admin = AdminPeer::doSelectOne($c); if ($admin) { $template = MailTemplatePeer::retrieveByPK('__FORGET__'); $email = trim($admin->getEmail()); $subject = $template->getSubject(); $temp_body = $template->getTemplate(); $html_temp_body = $template->getHTMLTemplate(); $password = chr(rand(65, 90)) . chr(rand(65, 90)) . chr(rand(65, 90)) . chr(rand(65, 90)) . chr(rand(65, 90)); // random(ish) 5 character string $temp_body = str_replace('___PASSWORD___', $password, $temp_body); $html_temp_body = str_replace('___PASSWORD___', $password, $html_temp_body); $admin->setPassword(md5($password)); $admin->save(); $footer = MailTemplatePeer::retrieveByPK("FOOTER"); $temp_body .= $footer->getTemplate(); $html_temp_body .= $footer->getHTMLTemplate(); $mail = new sfMail(); $mail->initialize(); $mail->setMailer('sendmail'); $mail->setCharset('utf-8'); $mail->setSender('*****@*****.**'); $mail->addReplyTo('*****@*****.**'); $mail->setFrom('*****@*****.**'); $mail->setContentType('text/html'); $mail->addAddress($email); $mail->setSubject($subject); $mail->setBody($html_temp_body); $mail->setAltBody($temp_body); $mail->send(); $this->result = 'Thank you'; } else { $this->result = "we do not have user with this email"; } } }
define('SF_APP', 'backend'); define('SF_ENVIRONMENT', 'prod'); define('SF_DEBUG', false); require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; $databaseManager = new sfDatabaseManager(); $databaseManager->initialize(); $c = new Criteria(); $c->add(BlogPeer::VERIFIED, true); $c->add(BlogPeer::APPROVED, false); $blogs = BlogPeer::doSelect($c); if (empty($blogs)) { return; } $mail = new sfMail(); $mail->initialize(); $mail->setMailer('sendmail'); $mail->setCharset('utf-8'); $mail->setSubject('Lista blogów do zatwierdzenia'); $mail->setSender('*****@*****.**', 'Planeta PHP.pl'); $mail->setFrom('*****@*****.**', 'Planeta PHP.pl'); $admins = AdminPeer::doSelect(new Criteria()); foreach ($admins as $admin) { $mail->addAddress($admin->getEmail()); } $body = "Oto lista blogów, które pozostały do zawierdzenia:\n"; foreach ($blogs as $blog) { $body .= " - {$blog->getName()} ({$blog->getUrl()})\n"; } $body .= "\nPanel administracyjny: http://planeta.php.pl/backend.php"; $mail->setBody($body); $mail->send();
public function getAdmin() { return AdminPeer::retrieveByPk($this->getMid()); }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, * TYPE_NUM. The default key type is the column's phpname (e.g. 'authorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = AdminPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setMid($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setEmail($arr[$keys[1]]); } }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param Connection $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, $con = null) { if ($con === null) { $con = Propel::getConnection(self::DATABASE_NAME); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(); $criteria->add(AdminPeer::MID, $pks, Criteria::IN); $objs = AdminPeer::doSelect($criteria, $con); } return $objs; }