示例#1
0
 /**
  * Checks a comma separated list of e-mails which should invited.
  * E-Mails needs to be valid and not already registered.
  *
  * @param string $attribute
  * @param array $params
  */
 public function checkEmails($attribute, $params)
 {
     if ($this->{$attribute} != "") {
         foreach ($this->getEmails() as $email) {
             $validator = new \yii\validators\EmailValidator();
             if (!$validator->validate($email)) {
                 $this->addError($attribute, Yii::t('UserModule.invite', '{email} is not valid!', array("{email}" => $email)));
                 continue;
             }
             if (User::findOne(['email' => $email]) != null) {
                 $this->addError($attribute, Yii::t('UserModule.invite', '{email} is already registered!', array("{email}" => $email)));
                 continue;
             }
         }
     }
 }
示例#2
0
 private function _validateParams()
 {
     // Email
     if (empty($this->email)) {
         throw new \yii\base\InvalidConfigException("`email` param is required");
     } else {
         $validator = new \yii\validators\EmailValidator();
         if (!$validator->validate($this->email, $error)) {
             throw new \yii\base\InvalidConfigException($error);
         }
     }
     // Size
     if (!empty($this->size)) {
         $validator = new \yii\validators\NumberValidator(["min" => 1, "max" => 2048]);
         if (!$validator->validate($this->size, $error)) {
             throw new \yii\base\InvalidConfigException($error);
         }
     }
     // Rating
     if (!empty($this->rating)) {
         $validator = new \yii\validators\RangeValidator(["range" => ["g", "pg", "r", "x"]]);
         if (!$validator->validate($this->rating, $error)) {
             throw new \yii\base\InvalidConfigException($error);
         }
     }
     // Default image
     if (!empty($this->defaultImage)) {
         $validator = new \yii\validators\UrlValidator();
         if (!$validator->validate($this->defaultImage, $error)) {
             $validator = new \yii\validators\RangeValidator(["range" => ["404", "mm", "identicon", "monsterid", "wavatar", "retro", "blank"]]);
             if (!$validator->validate($this->defaultImage, $error)) {
                 throw new \yii\base\InvalidConfigException($error);
             }
         }
     }
 }
示例#3
0
 private function judgeAccountType($account)
 {
     $numberValidator = new \yii\validators\NumberValidator();
     if ($numberValidator->validate($account)) {
         return static::ACCOUNT_TYPE_INTEGER;
     }
     $emailValidator = new \yii\validators\EmailValidator();
     if ($emailValidator->validate($account)) {
         return static::ACCOUNT_TYPE_EMAIL;
     }
     return static::ACCOUNT_TYPE_INVALID;
 }
示例#4
0
 public function actionAddorderexc()
 {
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $data = ['status' => 'OK', 'message' => ''];
     $request = Yii::$app->request;
     $excId = $request->post('excId', false);
     $excursion = false;
     if (!$excId) {
         $countryId = $request->post('country', false);
         $cityId = $request->post('city', false);
         if (!$countryId || !$cityId) {
             $data['status'] = 'Err';
             $data['message'] = 'не переданы параметры экскурсии или страны и города!';
             return $data;
         }
     } else {
         $excursion = Excursion::getExcursion($excId);
         if (!$excursion) {
             $data['status'] = 'Err';
             $data['message'] = 'не найдена экскурсия!';
             return $data;
         }
     }
     $excDate = $request->post('excDate', false);
     $price = $request->post('price', false);
     $countBig = $request->post('countBig', false);
     $countSmall = $request->post('countSmall', false);
     $excComment = $request->post('excComment', false);
     $name = $request->post('name', false);
     $phone = $request->post('phone', false);
     $email = $request->post('email', false);
     if (!$excDate || !$excComment || !$name || !$phone || !$email) {
         $data['status'] = 'Err';
         $data['message'] = 'не заполнены обязательные поля!';
         return $data;
     }
     $validator = new \yii\validators\EmailValidator();
     if (!$validator->validate($email)) {
         $data['status'] = 'Err';
         $data['message'] = 'не корректный e-mail!';
         return $data;
     }
     if (!$excursion) {
         $country = Country::getCountry($countryId);
         if (!$country) {
             $data['status'] = 'Err';
             $data['message'] = 'страна не найдена!';
             return $data;
         }
         $city = City::getCity($cityId);
         if (!$city) {
             $data['status'] = 'Err';
             $data['message'] = 'город не найден!';
             return $data;
         }
         $text = $country['name'] . ', ' . $city['name'] . '<br />';
         $text .= 'Дата проведения экскурсии: ' . $excDate . '<br />';
         $text .= $countBig ? 'Количество взрослых: ' . $countBig . '<br />' : '';
         $text .= $countSmall ? 'Количество детей: ' . $countSmall . '<br />' : '';
         $text .= $price ? 'Цена до: ' . $price . '<br />' : '';
         $text .= '<br /><br />' . $excComment;
         $orderTbl = new AgencyOrder();
         $orderTbl->manager_id = User::getCurrentGuideId();
         $orderTbl->country_id = $countryId;
         $orderTbl->user_name = $name;
         $orderTbl->user_email = $email;
         $orderTbl->user_phone = $phone;
         $orderTbl->user_params = $text;
         $orderTbl->user_id = 0;
         $orderTbl->excursion_id = 0;
         $orderTbl->save();
     } else {
         $text = 'Дата проведения экскурсии: ' . $excDate . '<br />';
         if ($price) {
             $text .= 'Стоимость до: ' . $price . '<br />';
         }
         $text .= $countBig ? 'Количество взрослых: ' . $countBig . '<br />' : '';
         $text .= $countSmall ? 'Количество детей: ' . $countSmall . '<br />' : '';
         $text .= '<br /><br />' . $excComment;
         $orderTbl = new AgencyOrder();
         $orderTbl->manager_id = User::getCurrentGuideId();
         $orderTbl->country_id = $excursion['country_id'];
         $orderTbl->user_name = $name;
         $orderTbl->user_email = $email;
         $orderTbl->user_phone = $phone;
         $orderTbl->user_params = $text;
         $orderTbl->user_id = 0;
         $orderTbl->excursion_id = $excursion['id'];
         $orderTbl->save();
     }
     /**
      * @todo
      * добавить отправку заявки на e-mail
      */
     return $data;
 }
 /**
  * Invites a not registered member to this space
  *
  * @param type $email
  * @param type $originatorUserId
  */
 public function inviteMemberByEMail($email, $originatorUserId)
 {
     // Invalid E-Mail
     $validator = new \yii\validators\EmailValidator();
     if (!$validator->validate($email)) {
         return false;
     }
     // User already registered
     $user = User::findOne(['email' => $email]);
     if ($user != null) {
         return false;
     }
     $userInvite = Invite::findOne(['email' => $email]);
     // No invite yet
     if ($userInvite == null) {
         // Invite EXTERNAL user
         $userInvite = new Invite();
         $userInvite->email = $email;
         $userInvite->source = Invite::SOURCE_INVITE;
         $userInvite->user_originator_id = $originatorUserId;
         $userInvite->space_invite_id = $this->owner->id;
         $userInvite->save();
         $userInvite->sendInviteMail();
         // There is a pending registration
         // Steal it und send mail again
         // Unfortunately there a no multiple workspace invites supported
         // so we take the last one
     } else {
         $userInvite->user_originator_id = $originatorUserId;
         $userInvite->space_invite_id = $this->owner->id;
         $userInvite->save();
         $userInvite->sendInviteMail();
     }
     return true;
 }
示例#6
0
 /**
  * Checks a comma separated list of e-mails which should invited to space.
  * E-Mails needs to be valid and not already registered.
  *
  * @param type $attribute
  * @param type $params
  */
 public function checkInviteExternal($attribute, $params)
 {
     // Check if email field is not empty
     if ($this->{$attribute} != "") {
         $emails = explode(",", $this->{$attribute});
         // Loop over each given e-mail
         foreach ($emails as $email) {
             $email = trim($email);
             $validator = new \yii\validators\EmailValidator();
             if (!$validator->validate($email)) {
                 $this->addError($attribute, Yii::t('SpaceModule.forms_SpaceInviteForm', "{email} is not valid!", array("{email}" => $email)));
                 continue;
             }
             $user = User::findOne(['email' => $email]);
             if ($user != null) {
                 $this->addError($attribute, Yii::t('SpaceModule.forms_SpaceInviteForm', "{email} is already registered!", array("{email}" => $email)));
                 continue;
             }
             $this->invitesExternal[] = $email;
         }
     }
 }
示例#7
0
文件: Adm.php 项目: kutsanov/med
 public function set()
 {
     $this->id = $this->id > 0 ? $this->id : null;
     $this->role = $this->role != '' ? $this->role : null;
     if ($this->email == '') {
         Core::error("Поле <strong>E-mail</strong> обязательно к заполнению", 'email');
     } else {
         $sql = 'Select count(*) from auth_adm where email=:email and (auth_id<>:id or :id is null)';
         $params = [];
         $params['email'] = $this->email;
         $params['id'] = $this->id;
         $cnt = \yii::$app->db->createCommand($sql, $params)->queryScalar();
         if ($cnt > 0) {
             Core::error('E-mail <strong>"' . $this->email . '"</strong> уже есть в базе', 'email');
         } else {
             $EmailValidator = new \yii\validators\EmailValidator();
             if (!$EmailValidator->validate($this->email)) {
                 Core::error('Некорректное поле <strong>"E-mail"</strong>', 'email');
             }
         }
     }
     if ($this->pw == '') {
         Core::error("Поле <strong>Пароль</strong> обязательно к заполнению", 'pw');
     }
     if ($this->name_f == '') {
         Core::error("Поле <strong>ФАМИЛИЯ</strong> обязательно к заполнению", 'name_f');
     }
     if ($this->name_i == '') {
         Core::error("Поле <strong>ИМЯ</strong> обязательно к заполнению", 'name_i');
     }
     if (Core::hasError() === true) {
         return;
     }
     $transaction = \yii::$app->db->getTransaction();
     if (!$transaction) {
         $transaction = \Yii::$app->db->beginTransaction();
     }
     try {
         if ($this->id === null) {
             $fld = [];
             $fld['t'] = 'adm';
             $fld['role'] = $this->role;
             \yii::$app->db->createCommand()->insert('auth', $fld)->execute();
             $this->id = \yii::$app->db->getLastInsertID('auth_id_seq');
             $fld = [];
             $fld['auth_id'] = $this->id;
             $fld['email'] = $this->email;
             $fld['pw'] = $this->pw;
             $fld['name_f'] = $this->name_f;
             $fld['name_i'] = $this->name_i;
             $fld['name_o'] = $this->name_o;
             \yii::$app->db->createCommand()->insert('auth_adm', $fld)->execute();
         } else {
             $this->upd_role($this->id, $this->role);
             $fld = $params = [];
             $fld['pw'] = $this->pw;
             $fld['name_f'] = $this->name_f;
             $fld['name_i'] = $this->name_i;
             $fld['name_o'] = $this->name_o;
             $params['auth_id'] = $this->id;
             $where = 'auth_id=:auth_id';
             \yii::$app->db->createCommand()->update('auth_adm', $fld, $where, $params)->execute();
         }
         $this->upd_perm($this->id, $this->perm);
         if (\app\component\Core::hasError() === false) {
             $transaction->commit();
         } else {
             $transaction->rollBack();
         }
     } catch (Exception $e) {
         $transaction->rollBack();
     }
 }
示例#8
0
 private function judgeUsernameType($username)
 {
     $emailValidator = new \yii\validators\EmailValidator();
     if ($emailValidator->validate($username)) {
         return static::ACCOUNT_TYPE_EMAIL;
     }
     if (is_string($username) && strlen($username) >= 3 && strlen($username) < 32) {
         return static::ACCOUNT_TYPE_STRING;
     }
     return static::ACCOUNT_TYPE_INVALID;
 }