Beispiel #1
0
 /**
  * Encrypt the data before saving, also stripping out an html
  * @Developer brandon
  * @Date May 18, 2010
  */
 public function __set($key, $value)
 {
     if (in_array($key, array('content', 'title'))) {
         $encrypt = new Encrypt();
         $value = $encrypt->encode(strip_tags($value));
     }
     parent::__set($key, $value);
 }
Beispiel #2
0
 public function send()
 {
     $c = new Encrypt();
     $message = $c->encode(json_encode($this->attributes));
     $q = MessageQueue::Get($account);
     try {
         $q->send($this->queue, $message);
         return TRUE;
     } catch (AWSException $ex) {
         return FALSE;
     }
 }
Beispiel #3
0
 /**
  * sends an email using our configs
  * @param  string/array $to       array(array('name'=>'chema','email'=>'chema@'),)
  * @param  [type] $to_name   [description]
  * @param  [type] $subject   [description]
  * @param  [type] $body      [description]
  * @param  [type] $reply     [description]
  * @param  [type] $replyName [description]
  * @param  [type] $file      [description]
  * @return boolean
  */
 public static function send($to, $to_name = '', $subject, $body, $reply, $replyName, $file = NULL)
 {
     require_once Kohana::find_file('vendor', 'php-mailer/phpmailer', 'php');
     $body = Text::nl2br($body);
     //get the unsubscribe link
     $email_encoded = NULL;
     //is sent to a single user get hash to auto unsubscribe
     if (!is_array($to) or count($to) == 1) {
         //from newsletter sent
         if (isset($to[0]['email'])) {
             $email_encoded = $to[0]['email'];
         } else {
             $email_encoded = $to;
         }
         //encodig the email for extra security
         $encrypt = new Encrypt(Core::config('auth.hash_key'), MCRYPT_MODE_NOFB, MCRYPT_RIJNDAEL_128);
         $email_encoded = Base64::fix_to_url($encrypt->encode($email_encoded));
     }
     $unsubscribe_link = Route::url('oc-panel', array('controller' => 'auth', 'action' => 'unsubscribe', 'id' => $email_encoded));
     //get the template from the html email boilerplate
     $body = View::factory('email', array('title' => $subject, 'content' => $body, 'unsubscribe_link' => $unsubscribe_link))->render();
     //sendign via elasticemail
     if (Core::config('email.elastic_active') == TRUE) {
         return self::ElasticEmail($to, $to_name, $subject, $body, core::config('email.notify_email'), "no-reply " . core::config('general.site_name'));
     } else {
         $mail = new PHPMailer();
         $mail->CharSet = Kohana::$charset;
         if (core::config('email.smtp_active') == TRUE) {
             require_once Kohana::find_file('vendor', 'php-mailer/smtp', 'php');
             $mail->IsSMTP();
             //SMTP HOST config
             if (core::config('email.smtp_host') != "") {
                 $mail->Host = core::config('email.smtp_host');
                 // sets custom SMTP server
             }
             //SMTP PORT config
             if (core::config('email.smtp_port') != "") {
                 $mail->Port = core::config('email.smtp_port');
                 // set a custom SMTP port
             }
             //SMTP AUTH config
             if (core::config('email.smtp_auth') == TRUE) {
                 $mail->SMTPAuth = TRUE;
                 // enable SMTP authentication
                 $mail->Username = core::config('email.smtp_user');
                 // SMTP username
                 $mail->Password = core::config('email.smtp_pass');
                 // SMTP password
                 if (core::config('email.smtp_ssl') == TRUE) {
                     $mail->SMTPSecure = "ssl";
                     // sets the prefix to the server
                 }
             }
         }
         $mail->From = core::config('email.notify_email');
         $mail->FromName = "no-reply " . core::config('general.site_name');
         $mail->Subject = $subject;
         $mail->MsgHTML($body);
         if ($file !== NULL) {
             $mail->AddAttachment($file['tmp_name'], $file['name']);
         }
         $mail->AddReplyTo($reply, $replyName);
         //they answer here
         if (is_array($to)) {
             foreach ($to as $contact) {
                 $mail->AddBCC($contact['email'], $contact['name']);
             }
         } else {
             $mail->AddAddress($to, $to_name);
         }
         $mail->IsHTML(TRUE);
         // send as HTML
         if (!$mail->Send()) {
             //to see if we return a message or a value bolean
             Alert::set(Alert::ALERT, "Mailer Error: " . $mail->ErrorInfo);
             return FALSE;
         } else {
             return TRUE;
         }
     }
     return FALSE;
 }
 /**
  * @param type $key Encryption Key
  * @param type $mode Encryption Mode
  * @param type $cipher Encryption Cipher
  * @param type $txt_plain Plain text to encode and then decode back
  *
  * @dataProvider provider_encode_decode
  * @covers Encrypt::encode
  */
 public function test_consecutive_encode_produce_different_results($key, $mode, $cipher, $txt_plain)
 {
     // initialize, encode twice
     $e = new Encrypt($key, $mode, $cipher);
     $txt_encoded_first = $e->encode($txt_plain);
     $txt_encoded_second = $e->encode($txt_plain);
     // assert
     $this->assertNotEquals($txt_encoded_first, $txt_encoded_second);
 }
Beispiel #5
0
	/**
	 * Returns the current session as an encrypted string.
	 *
	 * @return unknown
	 */
	public function to_string()
	{
		$ticket=serialize($this->data)."|@@!@@|".(time()+20);

		$encrypter=new Encrypt();
		
		// encrypt the auth ticket and store it
		return $encrypter->encode($ticket);
	}
Beispiel #6
0
 /**
  *
  */
 public static function setToken($tokenName = "token")
 {
     $token = Encrypt::encode(time(), COOKIE_KEY);
     setcookie($tokenName, base64_encode($token), time() + 3600 * 24 * 7, "/");
 }
Beispiel #7
0
                    output_json(1, "验证码错误");
                }
                unset($_SESSION["admin_vcode"]);
            } else {
                output_json(2);
            }
        }
        if ($user["pwd"] == $pwd) {
            unset($user["pwd"]);
            $_SESSION["curr_user"] = $user;
            $user["err_login"] = 0;
            $id = $user["id"];
            unset($user["id"]);
            $db->query(SqlText::update("user", $user, "id = " . $id));
            if (isset($_REQUEST["remember"]) && $_REQUEST["remember"] == 1) {
                setcookie("curr_user_name", urlencode(Encrypt::encode($user["name"])), time() + 86400 * 7);
            }
            output_json(0, "登录成功");
        } else {
            $user["err_login"] += 1;
            $id = $user["id"];
            unset($user["id"]);
            unset($user["pwd"]);
            $db->query(SqlText::update("user", $user, "id = " . $id));
            output_json(1, "密码错误");
        }
    } else {
        output_json(1, "没有此用户");
    }
} else {
    exit("错误请求");