Exemplo n.º 1
0
 /**
  * creates a user from email if exists doesn't...
  * @param  string $email 
  * @param  string $name  
  * @param  string $password
  * @return Model_User        
  */
 public static function create_email($email, $name = NULL, $password = NULL)
 {
     $user = new self();
     $user->where('email', '=', $email)->limit(1)->find();
     if (!$user->loaded()) {
         if ($password === NULL) {
             $password = Text::random('alnum', 8);
         }
         $user->email = $email;
         $user->name = ($name === NULL or !isset($name)) ? substr($email, 0, strpos($email, '@')) : $name;
         $user->status = self::STATUS_ACTIVE;
         $user->id_role = Model_Role::ROLE_USER;
         $user->seoname = $user->gen_seo_title($user->name);
         $user->password = $password;
         $user->subscriber = 1;
         $user->last_ip = ip2long(Request::$client_ip);
         $user->country = euvat::country_code();
         //geo info EU
         try {
             $user->save();
             //send welcome email
             $url = $user->ql('oc-panel', array('controller' => 'profile', 'action' => 'edit'), TRUE);
             $user->email('auth-register', array('[USER.PWD]' => $password, '[URL.QL]' => $url));
         } catch (ORM_Validation_Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
     }
     return $user;
 }
Exemplo n.º 2
0
 /**
  * verify if a transaction is fraudulent
  * @return boolean                    
  */
 public function is_fraud()
 {
     //only production and api set
     if ($this->loaded() and core::config('payment.fraudlabspro') != '') {
         //get the country
         $country_code = euvat::country_code();
         // Include FraudLabs Pro library
         require Kohana::find_file('vendor/', 'FraudLabsPro.class');
         $fraud = new FraudLabsPro(core::config('payment.fraudlabspro'));
         try {
             // Check this transaction for possible fraud. FraudLabs Pro support comprehensive validation check,
             // and for this example, we only perform the IP address, BIN and billing country validation.
             // For complete validation, please check our developer page at http://www.fraudlabspro.com/developer
             $fraud_result = $fraud->check(array('ipAddress' => Request::$client_ip, 'billingCountry' => $country_code, 'quantity' => 1, 'amount' => $this->amount, 'currency' => $this->currency, 'emailAddress' => $this->user->email, 'paymentMode' => 'others', 'sessionId' => session_id()));
             $fraud_result_status = $fraud_result->fraudlabspro_status;
         } catch (Exception $e) {
             $fraud_result_status = 'DECLINED';
         }
         // This transaction is legitimate, let's submit to Stripe
         if ($fraud_result_status == 'APPROVE') {
             return FALSE;
         } else {
             Kohana::$log->add(Log::ERROR, 'Fraud detected id_order:' . $this->id_order);
             return TRUE;
         }
     }
     //by default we say is not fraud
     return FALSE;
 }