Exemplo n.º 1
0
 public function testSetupRecursively()
 {
     $handler = $this->getMock('\\PHPVS\\RuleSet');
     $handler->expects($this->atLeastOnce())->method('handle');
     RuleSet::filter(['array' => ['age' => -1, 'email' => 'not an email']], ['array' => RuleSet::setup(['age' => Validator::int()->prepare(), 'email' => Validator::email()->prepare()], $required = true)], "", $handler);
     // test not required
     $handler2 = $this->getMock('\\PHPVS\\RuleSet');
     $handler2->expects($this->never())->method('handle');
     RuleSet::filter(['array' => ['age' => "", 'email' => ""]], ['array' => RuleSet::setup(['age' => Validator::int()->required(false)->prepare(), 'email' => Validator::email()->required(false)->prepare()], $required = true)], "", $handler2);
 }
 public function testEmailValidation()
 {
     $validator = new Validator();
     $this->assertEquals('*****@*****.**', $validator->email('*****@*****.**'));
     $this->assertEquals('me@website.com,you@some-other-website.com', $validator->email('me@website.com,you@some-other-website.com'));
     $this->assertThrows('InvalidArgumentException', array($validator, 'email'), array('me@you'));
     $this->assertThrows('InvalidArgumentException', array($validator, 'email'), array('asdfasdf'));
     $this->assertThrows('InvalidArgumentException', array($validator, 'email'), array(42));
     $this->assertThrows('InvalidArgumentException', array($validator, 'email'), array('me@website.com,asdf'));
     // Extra whitespace is trimmed by default
     $this->assertEquals('*****@*****.**', $validator->email("\nsome.guy@www.some-website.com    "));
     $this->assertEquals('some.guy@www.some-website.com,mailer-daemon@yahoo.biz', $validator->email("\nsome.guy@www.some-website.com , mailer-daemon@yahoo.biz"));
     // This may be disabled
     $this->assertEquals("\nsome.guy@www.some-website.com    ", $validator->email("\nsome.guy@www.some-website.com    ", null, 0));
     $this->assertEquals("\nsome.guy@www.some-website.com    , mailer-daemon@yahoo.biz", $validator->email("\nsome.guy@www.some-website.com    , mailer-daemon@yahoo.biz", null, 0));
     // Filter to upper- or lowercase
     $this->assertEquals('*****@*****.**', $validator->email('hELLO@ME.COM  ', null, Validator::FILTER_DEFAULT | Validator::FILTER_LOWERCASE));
     $this->assertEquals('HELLO@ME.COM,HELLO@YOU.COM', $validator->email('hELLO@ME.COM , Hello@you.com', null, Validator::FILTER_DEFAULT | Validator::FILTER_UPPERCASE));
     // The default filtering trims and coerces empty values to null
     $this->assertNull($validator->email(null));
     $this->assertNull($validator->email(''));
     $this->assertNull($validator->email("   \n"));
     $this->assertThrows('InvalidArgumentException', array($validator, 'email'), array(null, null, 0));
     $this->assertThrows('InvalidArgumentException', array($validator, 'email'), array('', null, 0));
     $this->assertThrows('InvalidArgumentException', array($validator, 'email'), array("   \n", null, 0));
     /* By default, comma-delimited lists of email address are treated as
        valid. This may be disabled with an assertion. */
     $this->assertThrows('InvalidArgumentException', array($validator, 'email'), array('me@website.com,you@some-other-website.com', null, Validator::FILTER_DEFAULT | Validator::ASSERT_SINGLE_EMAIL));
     $this->assertThrows('InvalidArgumentException', array($validator, 'email'), array("\nsome.guy@www.some-website.com , mailer-daemon@yahoo.biz", null, Validator::FILTER_DEFAULT | Validator::ASSERT_SINGLE_EMAIL));
 }
Exemplo n.º 3
0
 public function testEmail()
 {
     $this->assertTrue(Validator::email('*****@*****.**'));
     $this->assertFalse(Validator::email('Some random garbage'));
     $this->assertFalse(Validator::email(array()));
 }
Exemplo n.º 4
0
 public function subscribeNewsletter()
 {
     $validator = new Validator();
     $req = array('subscriber_email' => t("Email is required"));
     $req_email = array('subscriber_email' => t("Email address seems invalid"));
     $validator->required($req, $this->data);
     $validator->email($req_email, $this->data);
     if (Yii::app()->functions->getSubsriberEmail($this->data['subscriber_email'])) {
         $validator->msg[] = t("Sorry your Email address is already exist in our records.");
     }
     if ($validator->validate()) {
         $params = array('email_address' => $this->data['subscriber_email'], 'date_created' => date('c'), 'ip_address' => $_SERVER['REMOTE_ADDR']);
         if ($this->insertData("{{newsletter}}", $params)) {
             $this->code = 1;
             $this->msg = t("Thank you for subscribing to our mailing list!");
         } else {
             $this->msg = t("Sorry there is error while we saving your information.");
         }
     } else {
         $this->msg = $validator->getErrorAsHTML();
     }
 }
Exemplo n.º 5
0
<?php

namespace Project\Validation;

include_once '../autoloader.php';
// Test data
$v = new Validator(['name' => 'asdfsdf', 'age' => '20', 'phone' => '123123', 'email' => '*****@*****.**', 'password' => 'wang1@']);
// Validate one field with multiple rules
$v->validate('name', ['notEmpty', ['greaterThan', 100], ['between', 0, 20]]);
$v->validate('age', ['notEmpty', ['between', 0, 100]]);
//length validation
//equal validation
$v->validate('name', [['length', 7]]);
$v->validate('name', [['equal', true]]);
// Email
$v->email()->validate('age', [['EmailValidator', '123.com']]);
// Call additional validator
echo $v->address()->street(3) . '<br>';
// Use getKey method to validate key value
echo $v->phone()->phoneNumber('12345') . '<br>';
echo $v->phone()->phoneNumber($v->getKey('phone')) . '<br>';
echo 'street', $v->address()->validate('email', ['street']) . '<br>';
//password validation
echo $v->password()->password($v->getKey('password')) . '<br>';
// Errors
echo '<hr/>';
if ($v->isValid()) {
    echo 'all valid';
} else {
    echo 'error on age field: ';
    $v->displayError('age');
 function register($params)
 {
     global $App, $Database;
     // if logged in, waste time no longer..
     if ($this->Auth->isLoggedIn()) {
         $User = $this->Auth->getUser();
         $this->redirect(array('controller' => 'users', 'action' => 'profile', 'params' => array($User->id)), array('success' => array('You were already logged in! ;)')));
     }
     if (($submitdata = $App->Form->get_submit_data('user_register')) == true) {
         $error = false;
         // check name
         if (strlen(trim($submitdata['name'])) > 50) {
             $App->setFlash(array('error' => array('Your name must be shorter than 50 characters')));
             $App->Form->set_error_input(array('group' => 'user_register', 'name' => 'name'));
             $error = true;
         }
         if (strlen(trim($submitdata['name'])) == 0) {
             $App->setFlash(array('error' => array("Don't you have a name? How should we address you?")));
             $App->Form->set_error_input(array('group' => 'user_register', 'name' => 'name'));
             $error = true;
         }
         $users = $Database->fetchObjects('User', "\r\n\t\t\t\tSELECT `id` FROM `users` WHERE `name` = '" . trim($submitdata['name']) . "'\r\n\t\t\t");
         if (count($users) != 0) {
             $App->setFlash(array('news' => array('A user already exists with this name. Could this be you?<br />' . 'Maybe you just <a href="' . $App->ml(array('controller' => 'users', 'action' => 'forgot_password')) . '">forgot your password</a>?')));
             $App->Form->set_error_input(array('group' => 'user_register', 'name' => 'name'));
             $error = true;
         }
         // check password
         if (!Validator::password(trim($submitdata['password']))) {
             $App->setFlash(array('error' => array('Your password is empty! Please do choose a password.')));
             $App->Form->set_error_input(array('group' => 'user_register', 'name' => 'password'));
             $error = true;
         }
         // check email
         if (!Validator::email(trim($submitdata['email']))) {
             $App->setFlash(array('error' => array('Please check your email address; the system validates it as false..')));
             $App->Form->set_error_input(array('group' => 'user_register', 'name' => 'email'));
             $error = true;
         } else {
             $users = $Database->fetchObjects('User', "\r\n\t\t\t\t\tSELECT `id` FROM `users` WHERE `email` = '" . trim($submitdata['email']) . "'\r\n\t\t\t\t");
             if (!empty($users)) {
                 $App->setFlash(array('news' => array('A user already exists with this email address! Is this you?<br />' . 'His or her name is ' . $users[0]->data['name'] . '.<br />' . 'Go to the <a href="' . $App->ml(array('controller' => 'users', 'action' => 'login')) . '">log in</a> page?<br />' . '.. or maybe you just <a href="' . $App->ml(array('controller' => 'users', 'action' => 'forgot_password')) . '">forgot your password</a>?')));
                 $error = true;
             }
         }
         if (!$error) {
             // checking done,
             // REGISTER
             $key = '';
             $chars = '1234567890qwertyuiopasdfghjklzxcvbnm';
             for ($i = 0; $i <= 30; $i++) {
                 $key .= substr($chars, rand(0, strlen($chars) - 1), 1);
             }
             $sql = "\r\n\t\t\t\t\tINSERT INTO `users` (`name`, `password`, `email`, `key`) VALUES\r\n\t\t\t\t\t('" . trim($submitdata['name']) . "', '" . trim($submitdata['password']) . "', '" . trim($submitdata['email']) . "', '{$key}')\r\n\t\t\t\t";
             mysql_query($sql) or die('lw3uhgksdnh,snd,h <pre>' . $sql . '</pre> ' . mysql_error());
             $id = mysql_insert_id();
             $users = $Database->fetchObjects('User', "SELECT {$id}");
             $User = $users[0];
             // send confirmation email
             $mail_sent = @mail($User->data['name'] . ' <' . $User->data['email'] . '>', 'PHPScrabble - Confirm your email address', 'Please follow this link to confirm your email address: ' . $App->ml(array('controller' => 'users', 'action' => 'confirm_email', 'params' => array($key))), 'From: info@phpscrabble.com' . "\r\n" . 'Reply-To: info@phpscrabble.com');
             $this->redirect(array('controller' => 'users', 'action' => 'login'), array('success' => array('You have successfully registered!<br />' . 'Please check your email for a comfirmation link.<br />' . 'After you\'ve comfirmed your email address you van log in and start playing scrabble.')));
         }
     }
 }
Exemplo n.º 7
0
 /**
  * 绑定用户Action
  */
 public function oauth_bind_act()
 {
     $userinfo = Session::get('oauth_user_info');
     if ($userinfo) {
         $email = Filter::sql(Req::args('email'));
         $passWord = Req::post('password');
         $rePassWord = Req::post('repassword');
         if (!Validator::email($email)) {
             $info = array('field' => 'email', 'msg' => '邮箱不能为空!');
         } elseif (strlen($passWord) < 6) {
             $info = array('field' => 'password', 'msg' => '密码长度必需大于6位!');
         } else {
             $model = $this->model->table("user as us");
             $obj = $model->join("left join customer as cu on us.id = cu.user_id")->fields("us.*,cu.group_id,cu.login_time")->where("us.email='{$email}'")->find();
             if ($obj) {
                 if ($obj['password'] == CHash::md5($passWord, $obj['validcode'])) {
                     $test = $this->model->table('oauth_user')->where("oauth_type='{$userinfo['oauth_type']}' and open_id='{$userinfo['open_id']}'")->data(array('user_id' => $obj['id']))->update();
                     $this->safebox->set('user', $obj, 1800);
                     $this->redirect("/ucenter/index");
                 } else {
                     $info = array('field' => 'password', 'msg' => '密码与用户名是不匹配的,无法绑定!');
                 }
             } else {
                 if ($passWord == $rePassWord) {
                     $model = $this->model->table("user");
                     $validcode = CHash::random(8);
                     $last_id = $model->data(array('email' => $email, 'name' => $userinfo['open_name'], 'password' => CHash::md5($passWord, $validcode), 'validcode' => $validcode))->insert();
                     $time = date('Y-m-d H:i:s');
                     $model->table("customer")->data(array('user_id' => $last_id, 'reg_time' => $time, 'login_time' => $time))->insert();
                     //记录登录信息
                     $obj = $model->table("user as us")->join("left join customer as cu on us.id = cu.user_id")->fields("us.*,cu.group_id,cu.login_time")->where("us.email='{$email}'")->find();
                     $this->safebox->set('user', $obj, 1800);
                     $this->model->table('oauth_user')->where("oauth_type='{$userinfo['oauth_type']}' and open_id='{$userinfo['open_id']}'")->data(array('user_id' => $last_id))->update();
                     $this->redirect("/ucenter/index");
                 } else {
                     $info = array('field' => 'repassword', 'msg' => '两次密码输入不一致!');
                 }
             }
         }
         $this->assign("invalid", $info);
         $this->redirect("/simple/oauth_bind", false, Req::args());
     } else {
         $this->redirect("/index/index");
     }
 }
Exemplo n.º 8
0
 /**
  * Creates a Validator object that checks against each of the function arguemnts
  *
  * @param integer ...
  * @return Validator
  */
 public function createValidator()
 {
     $validator = new Validator($this);
     foreach (func_get_args() as $ruleCode) {
         switch ($ruleCode) {
             case self::ANYTHING:
                 $validator->forceResult(TRUE);
                 break;
             case self::ANYTHING_COLLECTION:
                 $validator->orValidator($this->createValidator()->isEmpty(), $this->createValidator()->collectionValidator($this->createValidator()->forceResult(TRUE)));
                 break;
             case self::USERNAME_COLLECTION:
                 $validator->orValidator($this->createValidator()->isEmpty(), $this->createValidator()->collectionValidator($this->createValidator()->username()));
                 break;
             case self::SERVICESTATUS:
                 $validator->memberOf('enabled', 'disabled');
                 break;
             case self::USERNAME:
                 $validator->username();
                 break;
             case self::HOSTNAME:
                 $validator->hostname();
                 break;
             case self::HOSTNAME_FQDN:
                 $validator->hostname(1);
                 break;
             case self::HOSTNAME_SIMPLE:
                 $validator->hostname(0, 0);
                 break;
             case self::HOSTADDRESS:
                 $validator->orValidator($this->createValidator()->ipV4Address(), $this->createValidator()->hostname());
                 break;
             case self::NOTEMPTY:
                 $validator->notEmpty();
                 break;
             case self::DATE:
                 $validator->date();
                 break;
             case self::TIME:
                 $validator->time();
                 break;
             case self::IP:
             case self::IPv4:
                 $validator->ipV4Address();
                 break;
             case self::NETMASK:
             case self::IPv4_NETMASK:
                 $validator->ipV4Netmask();
                 break;
             case self::MACADDRESS:
                 $validator->macAddress();
                 break;
             case self::POSITIVE_INTEGER:
                 $validator->integer()->positive();
                 break;
             case self::NONNEGATIVE_INTEGER:
                 $validator->integer()->greatThan(-1);
                 break;
             case self::PORTNUMBER:
                 $validator->integer()->greatThan(0)->lessThan(65535);
                 break;
             case self::BOOLEAN:
                 $validator->memberOf('1', 'yes', '0', '');
                 break;
             case self::IP_OR_EMPTY:
             case self::IPv4_OR_EMPTY:
                 $validator->orValidator($this->createValidator()->ipV4Address(), $this->createValidator()->isEmpty());
                 break;
             case self::NETMASK_OR_EMPTY:
             case self::IPv4_NETMASK_OR_EMPTY:
                 $validator->orValidator($this->createValidator()->ipV4Netmask(), $this->createValidator()->isEmpty());
                 break;
             case self::YES_NO:
                 $validator->memberOf('yes', 'no');
                 break;
             case self::EMAIL:
                 $validator->email();
                 break;
             case self::EMPTYSTRING:
                 $validator->maxLength(0);
                 break;
             case self::CIDR_BLOCK:
                 $validator->cidrBlock();
                 break;
             case NULL:
                 continue;
             default:
                 throw new \InvalidArgumentException(sprintf('%s: Unknown validator code: %s', get_class($this), $ruleCode), 1326380984);
         }
     }
     return $validator;
 }
Exemplo n.º 9
0
 public function send_email_test()
 {
     $test_email = Req::args('email');
     if (Validator::email($test_email)) {
         $mail = new Mail();
         try {
             $flag = $mail->send_email($test_email, 'TinyShop电子商务系统,邮箱验证测试', "<div><h3>亲爱的TinyShop用户您好:</h3><p style='text-indent:2em;'>当您收到这封邮件时,说明您的信息配制正确,邮件系统可以正常工作。</p></div>");
             $info = array('status' => 'success', 'msg' => '测试成功,邮件已发送');
             if (!$flag) {
                 $info = array('status' => 'fail', 'msg' => '测试失败,请检测配制信息');
             }
             echo JSON::encode($info);
         } catch (Exception $e) {
             $msg = $e->errorMessage();
             $info = array('status' => 'fail', 'msg' => $msg);
             echo JSON::encode($info);
         }
     } else {
         $info = array('status' => 'fail', 'msg' => '测试邮箱地址格式不正确,核实后再测试');
         echo JSON::encode($info);
     }
 }
Exemplo n.º 10
0
 static function validateArray(&$array, &$rules)
 {
     // Workaround for non Fancy-URL user.
     $cropArray = array();
     foreach ($array as $name => $value) {
         $doesHaveRequest = strpos($name, '?');
         if ($doesHaveRequest !== false) {
             $name = substr($name, $doesHaveRequest + 1);
         }
         $cropArray[$name] = $value;
     }
     $array = $cropArray;
     foreach ($rules as $key => $rule) {
         if (!isset($rule[0])) {
             trigger_error("Validator: The type of '{$key}' is not defined", E_USER_WARNING);
             continue;
         }
         if (isset($array[$key]) && ($rule[0] == 'file' || strlen($array[$key]) > 0)) {
             $value =& $array[$key];
             if (isset($rule['min'])) {
                 $rule[1] = $rule['min'];
             }
             if (isset($rule['max'])) {
                 $rule[2] = $rule['max'];
             }
             if (isset($rule['bypass'])) {
                 $rule[3] = $rule['bypass'];
             }
             switch ($rule[0]) {
                 case 'any':
                     if (isset($rule[1]) && strlen($value) < $rule[1]) {
                         return false;
                     }
                     if (isset($rule[2]) && strlen($value) > $rule[2]) {
                         return false;
                     }
                     break;
                 case 'bit':
                     $array[$key] = Validator::getBit($value);
                     break;
                 case 'bool':
                     $array[$key] = Validator::getBool($value);
                     break;
                 case 'number':
                     if (!Validator::number($value, isset($rule[1]) ? $rule[1] : null, isset($rule[2]) ? $rule[2] : null, isset($rule[3]) ? $rule[3] : false)) {
                         return false;
                     }
                     break;
                 case 'int':
                     if (!Validator::isInteger($value, isset($rule[1]) ? $rule[1] : -2147483648.0, isset($rule[2]) ? $rule[2] : 2147483647, isset($rule[3]) ? $rule[3] : false)) {
                         return false;
                     }
                     break;
                 case 'id':
                     if (!Validator::id($value, isset($rule[1]) ? $rule[1] : 1, isset($rule[2]) ? $rule[2] : 2147483647)) {
                         return false;
                     }
                     break;
                 case 'url':
                 case 'string':
                     if (!Utils_Unicode::validate($value)) {
                         $value = Utils_Unicode::bring($value);
                         if (!Utils_Unicode::validate($value)) {
                             return false;
                         }
                     }
                     $value = $array[$key] = Utils_Unicode::correct($value);
                     if (isset($rule[1]) && Utils_Unicode::length($value) < $rule[1]) {
                         return false;
                     }
                     if (isset($rule[2]) && Utils_Unicode::length($value) > $rule[2]) {
                         return false;
                     }
                     break;
                 case 'list':
                     if (!Validator::isList($value)) {
                         return false;
                     }
                     break;
                 case 'timestamp':
                     if (!Validator::timestamp($value)) {
                         return false;
                     }
                     break;
                 case 'period':
                     if (!Validator::period($value)) {
                         return false;
                     }
                     break;
                 case 'ip':
                     if (!Validator::ip($value)) {
                         return false;
                     }
                     break;
                 case 'domain':
                     if (!Validator::domain($value)) {
                         return false;
                     }
                     break;
                 case 'email':
                     if (!Validator::email($value)) {
                         return false;
                     }
                     break;
                 case 'language':
                     if (!Validator::language($value)) {
                         return false;
                     }
                     break;
                 case 'filename':
                     if (!Validator::filename($value)) {
                         return false;
                     }
                     break;
                 case 'directory':
                     if (!Validator::directory($value)) {
                         return false;
                     }
                     break;
                 case 'path':
                     if (!Validator::path($value)) {
                         return false;
                     }
                     break;
                 case 'file':
                     if (!isset($value['name']) || preg_match('@[/\\\\]@', $value['name'])) {
                         return false;
                     }
                     break;
                 default:
                     if (is_array($rule[0])) {
                         if (!in_array($value, $rule[0])) {
                             return false;
                         }
                     } else {
                         trigger_error("Validator: The type of '{$key}' is unknown", E_USER_WARNING);
                     }
                     break;
             }
             if (isset($rule['check'])) {
                 $rule[5] = $rule['check'];
             }
             if (isset($rule[5])) {
                 if (function_exists($rule[5])) {
                     if (!call_user_func($rule[5], $value)) {
                         return false;
                     }
                 } else {
                     trigger_error("Validator: The check function of '{$key}' is not defined", E_USER_WARNING);
                 }
             }
         } else {
             if (array_key_exists(3, $rule)) {
                 $array[$key] = $rule[3];
             } else {
                 if (array_key_exists('default', $rule)) {
                     $array[$key] = $rule['default'];
                 } else {
                     if ((!isset($rule[4]) || $rule[4]) && (!isset($rule['mandatory']) || $rule['mandatory'])) {
                         return false;
                     }
                 }
             }
         }
     }
     return true;
 }
Exemplo n.º 11
0
        $method = $methods[$i];
        $tocheck = $_GET[$methods[$i]];
    }
}
switch ($method) {
    case 'username':
        $user = new User($tocheck);
        if ($user->FetchData()) {
            echo "0";
        } else {
            echo "1";
        }
        break;
    case 'email':
        $valid = new Validator($tocheck);
        if ($valid->email()) {
            echo 1;
        } else {
            echo 0;
        }
        break;
    case 'queryUsernames':
        //there are should be check for admin rights
        //echo User::getInstance()->FetchNamesLike($tocheck);
        $names = User::getInstance()->FetchNamesLike($tocheck);
        $ret['query'] = $method;
        for ($i = 0; $i < count($names); $i++) {
            $ret['suggestions'] = $names[$i]['username'];
        }
        echo json_encode($ret);
        break;
Exemplo n.º 12
0
 /**
  * Generated from @assert ('admin@ไทย') [==] true.
  *
  * @covers Validator::email
  */
 public function testEmail4()
 {
     $this->assertTrue(\Validator::email('admin@ไทย'));
 }
Exemplo n.º 13
0
 public function testEmail()
 {
     $this->assertFalse(Validator::email()->valid("not an email"));
     $this->assertTrue(Validator::email()->valid("*****@*****.**"));
 }
Exemplo n.º 14
0
 public function join()
 {
     if (!empty($_POST)) {
         $valid = true;
         if (empty($_POST['username'])) {
             $this->message->put(Language::gettext('login-empty-required-field', 'login-form-username'));
             $valid = false;
         }
         if (empty($_POST['password'])) {
             $this->message->put(Language::gettext('login-empty-required-field', 'login-form-password'));
             $valid = false;
         }
         if (empty($_POST['repassword']) || $_POST['password'] != $_POST['repassword']) {
             $this->message->put(Language::gettext('login-empty-required-field', 'login-form-password-confirm'));
             $valid = false;
         } else {
             if ($valid) {
                 if ($_POST['password'] != $_POST['repassword']) {
                     $this->message->put(Language::gettext('login-required-password-confirm'));
                     $valid = false;
                 }
             }
         }
         if (empty($_POST['full_name'])) {
             $this->message->put(Language::gettext('login-empty-required-field', 'login-form-username'));
             $valid = false;
         }
         if (empty($_POST['gender'])) {
             $this->message->put(Language::gettext('login-empty-required-field', 'login-form-gender'));
             $valid = false;
         }
         if (empty($_POST['dob'])) {
             $this->message->put(Language::gettext('login-empty-required-field', 'login-form-dob'));
             $valid = false;
         }
         if (empty($_POST['sin'])) {
             $this->message->put(Language::gettext('login-empty-required-field', 'login-form-sin'));
             $valid = false;
         }
         if (empty($_POST['email']) || !Validator::email($_POST['email'])) {
             $this->message->put(Language::gettext('login-empty-required-field', 'login-form-email'));
             $valid = false;
         }
         if (empty($_POST['phone_home']) && empty($_POST['phone_cell']) && empty($_POST['phone_work'])) {
             $this->message->put(Language::gettext('login-required-contact-info'));
             $valid = false;
         }
         if ($valid) {
             $session_user = Session::get(Session::USER);
             $user = new User($_POST);
             $user->created = $session_user->created;
             $user->last = time();
             $user->access = User::MEMBER;
             $user->password = User::encryptPassword($_POST['password'], $_POST['username']);
             $user->update();
         }
         if (!empty($user->user_id)) {
             Session::set(Session::USER, $user);
         }
     }
     if (!empty($user->user_id) && Session::isLoggedIn()) {
         $this->followup();
     } else {
         unset($_POST['username']);
         unset($_POST['password']);
         $this->login();
     }
 }
 /**
  * Validates the high-level arguments (not the arguments related to
  * queries) and sets the appropriate properties.
  *
  * @param array &$args
  */
 private function _validateArgs(array &$args)
 {
     if (isset($args['formatter'])) {
         if (class_exists($args['formatter']) && (is_subclass_of($args['formatter'], 'Google\\Analytics\\ReportFormatter') || $args['formatter'] == 'Google\\Analytics\\ReportFormatter')) {
             $this->_formatter = new $args['formatter']();
         } else {
             throw new InvalidArgumentException('Invalid report formatter class name.');
         }
     } else {
         $this->_formatter = new ReportFormatter();
     }
     if (isset($args['email'])) {
         $v = new \Validator(__NAMESPACE__);
         $email = $v->email($args['email'], '"' . $args['email'] . '" is not a valid email address.', \Validator::FILTER_TRIM | \Validator::ASSERT_TRUTH);
         $this->_email = new \Email($email);
     }
     if (isset($args['file'])) {
         $this->_fileName = $args['file'];
     }
     if (!$this->_email && !$this->_fileName) {
         throw new InvalidArgumentException('An email address and/or an output file must be specified.');
     }
 }
Exemplo n.º 16
0
 public function requestPayout()
 {
     $mtid = Yii::app()->functions->getMerchantID();
     $wd_paypal_minimum = yii::app()->functions->getOptionAdmin('wd_paypal_minimum');
     $wd_bank_minimum = yii::app()->functions->getOptionAdmin('wd_bank_minimum');
     $wd_paypal_minimum = standardPrettyFormat($wd_paypal_minimum);
     $wd_bank_minimum = standardPrettyFormat($wd_bank_minimum);
     $current_balance = Yii::app()->functions->getMerchantBalance($mtid);
     $this->data['current_balance'] = $current_balance;
     $validator = new Validator();
     $req = array('payment_type' => t("Payment type is required"), 'payment_method' => t("Payment Method is required"));
     if ($this->data['payment_method'] == "paypal") {
         $req2 = array('account' => t("Email account not valid"), 'account_confirm' => t("Confirm email account not valid"));
         $validator->email($req2, $this->data);
         $req['amount'] = t("Amount is required");
         if ($this->data['account'] != $this->data['account_confirm']) {
             $validator->msg[] = t("Confirm email does not match");
         }
     } elseif ($this->data['payment_method'] == "bank") {
     }
     if ($this->data['payment_type'] == "single") {
         if ($this->data['minimum_amount'] > $this->data['amount']) {
             $validator->msg[] = t("Sorry but minimum amount is") . " " . displayPrice(baseCurrency(), $this->data['minimum_amount']);
         }
         if ($current_balance < $this->data['amount']) {
             $validator->msg[] = t("Amount is greater than your balance");
         }
     } elseif ($this->data['payment_type'] == "all-earnings") {
         $this->data['amount'] = $current_balance;
         if ($this->data['minimum_amount'] > $this->data['amount']) {
             $validator->msg[] = t("Sorry but minimum amount is") . " " . displayPrice(baseCurrency(), $this->data['minimum_amount']);
         }
         if ($this->data['minimum_amount'] > $current_balance) {
             $validator->msg[] = t("Sorry but minimum amount is") . " " . displayPrice(baseCurrency(), $this->data['minimum_amount']);
         }
     } else {
     }
     $validator->required($req, $this->data);
     if ($validator->validate()) {
         if ($this->data['payment_type'] == "single") {
             /*if  ( $wd_paypal_minimum>$this->data['amount']){
             			$this->msg=t("Sorry but minimum amount is")." ".displayPrice(baseCurrency(),$wd_paypal_minimum);
             		} else {*/
             $resp = Yii::app()->functions->payoutRequest($this->data['payment_method'], $this->data);
             if ($resp) {
                 $this->details = $resp['id'];
                 $this->code = 1;
                 $this->msg = t("Successful");
             } else {
                 $this->msg = t("ERROR: Something went wrong");
             }
             //}
         } else {
             //echo 'all earning';
             $resp = Yii::app()->functions->payoutRequest($this->data['payment_method'], $this->data);
             if ($resp) {
                 $this->details = $resp['id'];
                 $this->code = 1;
                 $this->msg = t("Successful");
             } else {
                 $this->msg = t("ERROR: Something went wrong");
             }
         }
     } else {
         $this->msg = $validator->getErrorAsHTML();
     }
     if ($this->code == 1) {
         if (isset($this->data['default_account_paypal'])) {
             if ($this->data['default_account_paypal'] == 2) {
                 Yii::app()->functions->updateOption("merchant_payout_account", isset($this->data['account']) ? $this->data['account'] : '', $mtid);
             }
         }
         if (isset($this->data['default_account_bank'])) {
             if ($this->data['default_account_bank'] == 2) {
                 $bank_info = array('swift_code' => isset($this->data['swift_code']) ? $this->data['swift_code'] : '', 'bank_account_number' => isset($this->data['bank_account_number']) ? $this->data['bank_account_number'] : '', 'account_name' => isset($this->data['account_name']) ? $this->data['account_name'] : '', 'bank_account_number' => isset($this->data['bank_account_number']) ? $this->data['bank_account_number'] : '', 'swift_code' => isset($this->data['swift_code']) ? $this->data['swift_code'] : '', 'bank_name' => isset($this->data['bank_name']) ? $this->data['bank_name'] : '', 'bank_branch' => isset($this->data['bank_branch']) ? $this->data['bank_branch'] : '');
                 Yii::app()->functions->updateOption("merchant_payout_bank_account", json_encode($bank_info), $mtid);
             }
         }
         // send email
         $merchant_email = '';
         $tpl = '';
         $wd_days_process = Yii::app()->functions->getOptionAdmin("wd_days_process");
         if (empty($wd_days_process)) {
             $wd_days_process = 5;
         }
         $cancel_date = $wd_days_process - 2;
         $cancel_date = date("F d Y", strtotime(" +{$cancel_date} days"));
         $process_date = date("F d Y", strtotime(" +{$wd_days_process} days"));
         if ($merchant_info = Yii::app()->functions->getMerchant($mtid)) {
             $merchant_email = $merchant_info['contact_email'];
             $cancel_link = websiteUrl() . "/store/cancelwithdrawal/id/" . $resp['token'];
             $tpl = yii::app()->functions->getOptionAdmin('wd_template_payout');
             $tpl = smarty("merchant-name", $merchant_email['restaurant_name'], $tpl);
             $tpl = smarty("payout-amount", standardPrettyFormat($this->data['amount']), $tpl);
             $tpl = smarty("payment-method", $this->data['payment_method'], $tpl);
             $tpl = smarty("account", $this->data['account'], $tpl);
             $tpl = smarty("cancel-date", $cancel_date, $tpl);
             $tpl = smarty("cancel-link", $cancel_link, $tpl);
             $tpl = smarty("process-date", $process_date, $tpl);
         }
         if (!empty($tpl)) {
             $wd_template_payout_subject = yii::app()->functions->getOptionAdmin('wd_template_payout_subject');
             if (empty($wd_template_payout_subject)) {
                 $wd_template_payout_subject = t("Your Request for Withdrawal was Received");
             }
             sendEmail($merchant_email, '', $wd_template_payout_subject, $tpl);
         }
     }
     /*end code = 1*/
 }