示例#1
0
 public function forgotPasswordAction()
 {
     $error = false;
     $message = "";
     $old_pass = "";
     if (isset($this->_params['email'])) {
         $u = $this->getUsers()->getByEmail($this->_params['email']);
         if (is_null($u)) {
             $u = $this->getCenters()->getByEmail($this->_params['email']);
             if (is_null($u)) {
                 $error = true;
                 $message = "Email dosen't exist !";
                 $this->view->assign("errorMessage", $message);
             }
         }
         if (!is_null($u)) {
             $new_pass = NL_Utils::randomPassword();
             $md5_new_pass = Table_Abstract::encryptPassword($new_pass);
             $email = new NL_HtmlMailer();
             if (!$email->sendForgot($new_pass, $this->_params['email'])) {
                 $error = true;
                 $message = "Service not available, please contact us to fix this !";
                 $this->view->assign("errorMessage", $message);
             } else {
                 $u->setPassword($md5_new_pass);
                 $u->setFirstTime(0);
                 if ($u->save()) {
                     $this->view->assign("successMessage", 'Please check your email to log in with your new password, please remember to change it after you loggedin');
                 } else {
                     $this->view->assign("errorMessage", $message);
                 }
             }
         }
     }
 }
示例#2
0
 /**
  * Set data
  *
  * @param mixed $k
  * @param mixed $v
  */
 public function setData($k, $v)
 {
     /** if column exists */
     if (isset($this->{$k})) {
         /** if password & !empty */
         if ($k == 'password' && !empty($v)) {
             $v = Table_Abstract::encryptPassword($v);
             $this->{$k} = $v;
         } elseif ($k != 'password') {
             /** @var set key value pair */
             $this->{$k} = $v;
         }
     }
 }
示例#3
0
文件: Users.php 项目: tudorfis/urfx
 /**
  * @param $username
  * @param $password
  * @return null|Model_User
  */
 public function getAuthUsernamePassword($username, $password)
 {
     $password = Table_Abstract::encryptPassword($password);
     $select = $this->select()->where("username = ?", strtolower($username))->where("password = ?", $password)->where("status <> '" . Table_Abstract::STATUS_DELETED . "'");
     return $this->fetchRow($select);
 }
示例#4
0
 /**
  * Get all values, or just by id from table by filter
  * status is always <> deleted
  * @param mixed $filter
  */
 public function selectBy($filter = null, $id = null, $join = null, $like = null, $col = null, $method = null)
 {
     // safety measure
     if (!is_array($filter)) {
         $filter = array();
     }
     if (!is_array($join)) {
         $join = array();
     }
     /** If by columns */
     if (!isNE($col)) {
         $col_ = array();
         foreach ($col as $k => $v) {
             if (in_array($k, $this->info('cols'))) {
                 $col_[] = $k;
             }
         }
         $select = $this->select()->setIntegrityCheck(false)->from(array("t" => $this->_name), $col_);
     } else {
         $select = $this->select()->setIntegrityCheck(false)->from(array("t" => $this->_name));
     }
     // If by id
     if (!is_null($id)) {
         $select->where("t.id = ?", $id);
     }
     // select by status id
     if (in_array('status_id', $this->info('cols'))) {
         if (!empty($filter["status_id"])) {
             $select->where("t.status_id = ?", $filter["status_id"]);
             // where status <> deleted if has column status
         } else {
             $select->where("t.status_id <> '3'");
         }
     }
     // iterate filter
     foreach ($filter as $k => $v) {
         if (!in_array($k, $this->_unpermited_filters)) {
             /* check if column exists */
             if (in_array($k, $this->info('cols'))) {
                 /* encrypt password */
                 if ($k == 'password' && !empty($v)) {
                     $v = Table_Abstract::encryptPassword($v);
                 }
                 /** check for null */
                 if ($v === null) {
                     $select->where("t.{$k} is null");
                 } else {
                     $select->where("t.{$k} = ?", $v);
                 }
             }
         }
     }
     // iterate join
     $join['tbl'] = $join;
     foreach ($join['tbl'] as $table => $table_id) {
         if (!in_array($table, $this->_unpermited_joins)) {
             $joinDbTable = new Table_Abstract();
             $joinDbTable->setDbTable($table);
             $tableJoins = $joinDbTable->info('cols');
             /* build colums */
             $columns = array();
             foreach ($tableJoins as $j) {
                 if (!in_array($j, array('id', 'status_id'))) {
                     $columns[$table . '|' . $table_id . '|' . $j] = $j;
                 }
             }
             $alias_name = APPLICATION_DB . substr(md5(mt_rand(0, 9999)), 0, 6);
             $join['alias'][$table] = $alias_name;
             $select->joinLeft(array($alias_name => $table), "t.{$table_id} = {$alias_name}.id", $columns);
             unset($join[$table]);
         }
     }
     // iterate like
     $like_req = '';
     if (!isNE($like)) {
         // if with join
         if (isset($join['alias']) && $method != 'map_all') {
             foreach ($like as $table => $table_v) {
                 foreach ($table_v as $k => $v) {
                     $alias_name = $join['alias'][$table];
                     $like_req .= "{$alias_name}.{$k} like '%{$v}%' or ";
                 }
             }
         } else {
             foreach ($like as $k => $v) {
                 $like_req .= "t.{$k} like '%{$v}%' or ";
             }
         }
         $like_req = trim($like_req, ' or ');
         $select->where($like_req);
     }
     // Limit
     if (isset($filter['limit']) && !empty($filter['limit'])) {
         $select->limit($filter['limit']);
     }
     // Limit count & offset
     if (isset($filter['limit_count']) && isset($filter['limit_offset'])) {
         $select->limit($filter['limit_count'], $filter['limit_offset']);
     }
     // Order by
     if (isset($filter['order'])) {
         $select->order("t." . $filter['order']);
     } else {
         $select->order("t.id desc");
     }
     // Save query
     $this->query = $select->__toString();
     // By Id
     if (!is_null($id) || isset($filter['single_row']) && $filter['single_row'] == 1) {
         $this->result = $this->fetchRow($select);
         return !isNE($this->result) ? $this->result : $this->createRow();
     } else {
         return $this->result = $this->fetchAll($select);
     }
 }
示例#5
0
 /**
  * Set table parameters accordingly
  *  
  * @param mixed $a
  * @param mixed $params
  */
 protected function _setSwitchTables($a = array(), $params = array())
 {
     switch ($params['table']) {
         // COMPANIES
         case 'companies':
             $params['first_time'] = isset($params['first_time']) ? $params['first_time'] : 0;
             $params['first_time'] = isset($params['user_mod']) ? 1 : $params['first_time'];
             $params['with_check'] = isset($params['with_check']) ? $params['with_check'] : 0;
             if (isset($params['email']) && !empty($params['email'])) {
                 $a->setEmail($params['email']);
             }
             if (isset($params['password']) && !empty($params['password'])) {
                 $params['password'] = Table_Abstract::encryptPassword($params['password']);
                 $a->setPassword($params['password']);
             }
             $a->setWithCheck($params['with_check'])->setFirstTime($params['first_time'])->setName($params["name"])->setImgId($params["img_id"])->setCashSFlatFee($params["cash_s_flat_fee"])->setCashSPercentageFee($params["cash_s_percentage_fee"])->setCashSMinimumFee($params["cash_s_minimum_fee"])->setCashSFeeType($params["cash_s_fee_type"])->setCashBFlatFee($params["cash_b_flat_fee"])->setCashBPercentageFee($params["cash_b_percentage_fee"])->setCashBMinimumFee($params["cash_b_minimum_fee"])->setCashBFeeType($params["cash_b_fee_type"])->setTcSFlatFee($params["tc_s_flat_fee"])->setTcSPercentageFee($params["tc_s_percentage_fee"])->setTcSMinimumFee($params["tc_s_minimum_fee"])->setTcSFeeType($params["tc_s_fee_type"])->setTcBFlatFee($params["tc_b_flat_fee"])->setTcBPercentageFee($params["tc_b_percentage_fee"])->setTcBMinimumFee($params["tc_b_minimum_fee"])->setTcBFeeType($params["tc_b_fee_type"])->setChequeSFlatFee($params["cheque_s_flat_fee"])->setChequeSPercentageFee($params["cheque_s_percentage_fee"])->setChequeSMinimumFee($params["cheque_s_minimum_fee"])->setChequeSFeeType($params["cheque_s_fee_type"])->setChequeBFlatFee($params["cheque_b_flat_fee"])->setChequeBPercentageFee($params["cheque_b_percentage_fee"])->setChequeBMinimumFee($params["cheque_b_minimum_fee"])->setChequeBFeeType($params["cheque_b_fee_type"]);
             break;
             // CUSTOMERS
         // CUSTOMERS
         case 'customers':
             $a->setName($params['name']);
             break;
             // Payments
         // Payments
         case 'payments':
             $a->setName($params['name']);
             break;
             // CENTERS
         // CENTERS
         case 'centers':
             $params['first_time'] = isset($params['first_time']) ? $params['first_time'] : 0;
             $params['first_time'] = isset($params['user_mod']) ? 1 : $params['first_time'];
             $a->setName($params['name'])->setHexColor($params['hex_color'])->setContact($params['contact'])->setFirstTime($params['first_time']);
             if (isset($params['email']) && !empty($params['email'])) {
                 $a->setEmail($params['email']);
             }
             if (isset($params['password']) && !empty($params['password'])) {
                 $params['password'] = Table_Abstract::encryptPassword($params['password']);
                 $a->setPassword($params['password']);
             }
             break;
             // MARGINS
         // MARGINS
         case 'margins':
             $a->setRateCCode($params['rate_c_code'])->setCashFeeB($params['cash_fee_b'])->setCashFeeS($params['cash_fee_s'])->setTcFeeB($params['tc_fee_b'])->setTcFeeS($params['tc_fee_s'])->setChequeFeeB($params['cheque_fee_b']);
             //                    ->setChequeFeeS($params['cheque_fee_s']);
             break;
             // RATES
         // RATES
         case 'rates':
             $params['c_unit'] = empty($params['c_unit']) || is_null($params['c_unit']) ? 1 : $params['c_unit'];
             $a->setCountry($params['country'])->setCUnit($params['c_unit'])->setCCode($params['c_code'])->setCSymbol($params['c_symbol'])->setBRate($params['b_rate'])->setBNote($params['b_note'])->setSRate($params['s_rate'])->setSNote($params['s_note'])->setDateUpdate($params['date_update']);
             break;
             // USERS
         // USERS
         case 'users':
             $params['approval_limit'] = empty($params['approval_limit']) || is_null($params['approval_limit']) ? 1 : $params['approval_limit'];
             $params['first_time'] = isset($params['user_mod']) ? 1 : $params['first_time'];
             if (!isset($params['user_mod'])) {
                 $a->setApprovalLimit($params['approval_limit'])->setRole($params['role'])->setCustomerId($params['customer_id'])->setCompanyId($params['company_id'])->setCenterId($params['center_id']);
             }
             if (isset($params['username']) && !empty($params['username'])) {
                 $a->setUsername($params['username']);
             }
             if (isset($params['password']) && !empty($params['password'])) {
                 $params['password'] = Table_Abstract::encryptPassword($params['password']);
                 $a->setPassword($params['password']);
             }
             $a->setFullName($params['full_name'])->setPhone($params['phone'])->setFax($params['fax'])->setMobile($params['mobile'])->setEmail($params['email'])->setFirstTime($params['first_time']);
             break;
             // APPROVERS
         // APPROVERS
         case 'approvers':
             $params['approval_limit'] = empty($params['approval_limit']) || is_null($params['approval_limit']) ? 1 : $params['approval_limit'];
             $params['first_time'] = isset($params['user_mod']) ? 1 : $params['first_time'];
             if (!isset($params['user_mod'])) {
                 $a->setApprovalLimit($params['approval_limit'])->setCustomerId($params['customer_id'])->setCompanyId($params['company_id']);
             }
             if (isset($params['username']) && !empty($params['username'])) {
                 $a->setUsername($params['username']);
             }
             if (isset($params['password']) && !empty($params['password'])) {
                 $params['password'] = Table_Abstract::encryptPassword($params['password']);
                 $a->setPassword($params['password']);
             }
             $a->setFullName($params['full_name'])->setPhone($params['phone'])->setFax($params['fax'])->setMobile($params['mobile'])->setEmail($params['email'])->setFirstTime($params['first_time']);
             break;
             // ORDERS
         // ORDERS
         case 'orders':
             //                dd($params);
             $params['date_created'] = empty($params['date_created']) || is_null($params['date_created']) ? date('Y-m-d') : convertUKtoUSdate($params['date_created']);
             $params['date_delivery'] = empty($params['date_delivery']) || is_null($params['date_delivery']) ? date('Y-m-d') : convertUKtoUSdate($params['date_delivery']);
             if (isset($params['status']) && !empty($params['status'])) {
                 $a->setStatus($params['status']);
             }
             if (isset($params['date_created'])) {
                 $a->setDateCreated($params['date_created']);
             }
             if (isset($params['date_response'])) {
                 $a->setDateResponse(convertUKtoUSdate($params['date_response']));
             }
             if (isset($params['date_delivery'])) {
                 $a->setDateDelivery($params['date_delivery']);
             }
             if (isset($params['company_id'])) {
                 $a->setCompanyId($params['company_id']);
             }
             if (isset($params['center_id'])) {
                 $a->setCenterId($params['center_id']);
             }
             if (isset($params['customer_id'])) {
                 $a->setCustomerId($params['customer_id']);
             }
             if (isset($params['amount'])) {
                 $a->setAmount($params['amount']);
             }
             if (isset($params['uk_amount'])) {
                 $a->setUkAmount($params['uk_amount']);
             }
             if (isset($params['rate_id'])) {
                 $a->setRateId($params['rate_id']);
             }
             if (isset($params['created_user_id'])) {
                 $a->setCreatedUserId($params['created_user_id']);
             }
             if (isset($params['response_user_id'])) {
                 $a->setResponseUserId($params['response_user_id']);
             }
             if (isset($params['type'])) {
                 $a->setType($params['type']);
             }
             if (isset($params['payment_type'])) {
                 $a->setPaymentType($params['payment_type']);
             }
             if (isset($params['traveller_name'])) {
                 $a->setTravellerName($params['traveller_name']);
             }
             if (isset($params['comment'])) {
                 $a->setComment($params['comment']);
             }
             if (isset($params['uid'])) {
                 $a->setUid($params['uid']);
             }
             break;
     }
     return $a;
 }