/** * Finds the Post model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Post the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Setting::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionTest() { $setting = \common\models\Setting::findOne(1); $number = $setting->whatsappNumber; $app = Yii::$app->name; $password = $setting->whatsappPassword; $phone = '6281575068530'; $message = 'this is just test, please dont remain'; $w = new WhatsApp($number, $app, $password); echo $w->send($phone, $message); }
/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { /* @var $user User */ $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]); if ($user) { if (!User::isPasswordResetTokenValid($user->password_reset_token)) { $user->generatePasswordResetToken(); } if ($user->save()) { $setting = Setting::findOne(1); return \Yii::$app->mailer->compose('passwordResetToken', ['user' => $user])->setFrom([$setting->emailAdmin => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Password reset for ' . \Yii::$app->name)->send(); } } return false; }
/** * Sends an email with a link, for resetting the password. * * @return boolean whether the email was send */ public function sendEmail() { /* @var $user User */ $user = Member::findOne(['status' => Member::STATUS_ACTIVE, 'email' => $this->email]); if ($user) { if (!User::isPasswordResetTokenValid($user->password_reset_token)) { $user->generatePasswordResetToken(); } $setting = Setting::findOne(1); $from = $setting->emailSupport; if ($user->save()) { return \Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user])->setFrom([$from => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Password reset for ' . \Yii::$app->name)->send(); } } return false; }
/** * insert settings */ protected function insertSettings() { $s = [['key' => 'languageUrlCode', 'value' => '0', 'title' => 'Language URL', 'description' => 'Include language code in URL', 'group' => 'SEO', 'type' => 'dropDownList', 'data' => json_encode(Core::getYesNoOption()), 'default' => '0', 'rules' => json_encode(['required' => [], 'boolean' => []])]]; foreach ($s as $i => $setting) { $conf = Setting::findOne($setting['key']); if (!$conf) { $conf = new Setting(); $conf->key = $setting['key']; $conf->value = $setting['value']; } $conf->title = $setting['title']; $conf->description = $setting['description']; $conf->group = $setting['group']; $conf->type = $setting['type']; $conf->data = $setting['data']; $conf->default = $setting['default']; $conf->rules = $setting['rules']; $conf->key_order = $i; $conf->save(); } //return $this->redirect(['index']); }
protected function insertSettings() { $s = [['key' => 'language', 'value' => 'en-US', 'title' => 'Language', 'description' => 'Site language', 'group' => 'General', 'type' => 'dropDownList', 'data' => '{LOCALE}', 'default' => 'en-US', 'rules' => json_encode(['required' => []])], ['key' => 'timezone', 'value' => 'Asia/Ho_Chi_Minh', 'title' => 'Timezone', 'description' => 'Server Timezone', 'group' => 'General', 'type' => 'dropDownList', 'data' => '{TIMEZONE}', 'default' => 'Asia/Ho_Chi_Minh', 'rules' => json_encode(['required' => []])], ['key' => 'maxNameChange', 'value' => '1', 'title' => 'Max Name Change', 'description' => 'Max name change allowed', 'group' => 'Account', 'type' => 'textInput', 'data' => '[]', 'default' => '1', 'rules' => json_encode(['required' => [], 'number' => ['min' => -1]])], ['key' => 'tokenExpiryTime', 'value' => '3600', 'title' => 'Token Expiry Time', 'description' => 'Expiration time in seconds', 'group' => 'Account', 'type' => 'textInput', 'data' => '[]', 'default' => '3600', 'rules' => json_encode(['required' => [], 'number' => ['min' => 3600]])], ['key' => 'rememberMeDuration', 'value' => '2592000', 'title' => 'Remember Me Duration', 'description' => 'Customize the duration of the Remember Me in seconds', 'group' => 'Account', 'type' => 'textInput', 'data' => '[]', 'default' => '2592000', 'rules' => json_encode(['required' => [], 'number' => ['min' => 86400]])], ['key' => 'title', 'value' => 'Yii2 Skeleton', 'title' => 'Title', 'description' => 'Homepage title', 'group' => 'SEO', 'type' => 'textInput', 'data' => '[]', 'default' => 'Yii2 Skeleton', 'rules' => json_encode(['required' => []])], ['key' => 'keywords', 'value' => 'Yii2, Skeleton', 'title' => 'Keywords', 'description' => 'Homepage keywords', 'group' => 'SEO', 'type' => 'textInput', 'data' => '[]', 'default' => 'Yii2, Skeleton', 'rules' => json_encode(['required' => []])], ['key' => 'description', 'value' => 'Skeleton for Yii Framework', 'title' => 'Description', 'description' => 'Homepage description', 'group' => 'SEO', 'type' => 'textInput', 'data' => '[]', 'default' => 'Skeleton for Yii Framework', 'rules' => json_encode(['required' => []])], ['key' => 'outgoingMail', 'value' => '*****@*****.**', 'title' => 'Outgoing Mail', 'description' => 'Outgoing email address', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['required' => [], 'email' => []])], ['key' => 'mailProtocol', 'value' => 'php', 'title' => 'Mail Protocol', 'description' => 'Outgoing email protocol', 'group' => 'Mail', 'type' => 'dropDownList', 'data' => json_encode(['php' => 'php', 'smtp' => 'smtp']), 'default' => 'php', 'rules' => json_encode(['required' => []])], ['key' => 'smtpHost', 'value' => '', 'title' => 'SMTP Host', 'description' => 'SMTP host', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'smtpUsername', 'value' => '', 'title' => 'SMTP Username', 'description' => 'SMTP username', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'smtpPassword', 'value' => '', 'title' => 'SMTP Password', 'description' => 'SMTP password', 'group' => 'Mail', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'smtpPort', 'value' => '', 'title' => 'SMTP Port', 'description' => 'SMTP port', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => '25', 'rules' => json_encode(['safe' => []])], ['key' => 'smtpEncryption', 'value' => '', 'title' => 'SMTP Encryption', 'description' => 'SMTP port', 'group' => 'Mail', 'type' => 'textInput', 'data' => '[]', 'default' => 'ssl', 'rules' => json_encode(['safe' => []])], ['key' => 'reCaptchaKey', 'value' => '', 'title' => 'reCaptcha Site Key', 'description' => 'reCaptcha Site Key', 'group' => 'API', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'reCaptchaSecret', 'value' => '', 'title' => 'reCaptcha Secret', 'description' => 'reCaptcha Secret', 'group' => 'API', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'facebookAppId', 'value' => '', 'title' => 'Facebook App ID', 'description' => 'Facebook App ID', 'group' => 'API', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'facebookAppSecret', 'value' => '', 'title' => 'Facebook App Secret', 'description' => 'Facebook App Secret', 'group' => 'API', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'googleClientId', 'value' => '', 'title' => 'Google Client ID', 'description' => 'Google Client ID', 'group' => 'API', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'googleClientSecret', 'value' => '', 'title' => 'Google Client Secret', 'description' => 'Google Client Secret', 'group' => 'API', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'flickrClientKey', 'value' => '', 'title' => 'Flickr Client Key', 'description' => 'Flickr Client Key', 'group' => 'API', 'type' => 'textInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'flickrClientSecret', 'value' => '', 'title' => 'Flickr Client Secret', 'description' => 'Flickr Client Secret', 'group' => 'API', 'type' => 'passwordInput', 'data' => '[]', 'default' => '', 'rules' => json_encode(['safe' => []])], ['key' => 'debug', 'value' => '0', 'title' => 'Debug Mode', 'description' => 'Turn on debug mode', 'group' => 'System', 'type' => 'dropDownList', 'data' => json_encode(Core::getYesNoOption()), 'default' => '0', 'rules' => json_encode(['required' => []])]]; foreach ($s as $i => $setting) { $conf = Setting::findOne($setting['key']); if (!$conf) { $conf = new Setting(); $conf->key = $setting['key']; $conf->value = $setting['value']; } $conf->title = $setting['title']; $conf->description = $setting['description']; $conf->group = $setting['group']; $conf->type = $setting['type']; $conf->data = $setting['data']; $conf->default = $setting['default']; $conf->rules = $setting['rules']; $conf->key_order = $i; $conf->save(); } //return $this->redirect(['index']); }
public function actionSetting() { $model = Setting::findOne(['active' => Setting::STATUS_ACTIVE]); $parse['model'] = $model; //post action $posts = Yii::$app->request->post(); if (!empty($posts)) { $model->setServerIP($posts['server_ip']); $model->setServerPort($posts['server_port']); $model->save(); Yii::$app->session->setFlash('update_success', 'Cập nhật thành công'); //update root password if (isset($posts['password_root']) && $posts['password_root'] != '******') { $root = $model->_getRoot(); $uiModel = new UpdateInfo(); $uiModel->username = $root->username; $uiModel->password = $posts['password_root']; $uiModel->fullname = $root->fullname; $uiModel->mobile = $root->mobile; $uiModel->email = $root->email; $uiModel->type = $root->type; if ($uiModel->validate()) { $uiModel->updateInfo($root->id); $this->actionLogout(); } else { $parse['errors'] = $uiModel->getErrors(); } } } return $this->render('setting', $parse); }
public function save() { $setting = Setting::findOne(['id' => $this->id]); if (empty($setting)) { $setting = new Setting(); $setting->name = $this->name; $setting->value = SettingForm::encodeValue($this->value); $oldRules = $this->_value_rules; $this->_value_rules = [[['value'], 'string']]; Yii::getLogger()->log('save:', YII_DEBUG); if ($setting->save()) { $this->_value_rules = $oldRules; $this->id = $setting->id; return $setting; } else { $this->_value_rules = $oldRules; Yii::getLogger()->log('save error', YII_DEBUG); } } else { $setting->name = $this->name; $setting->value = SettingForm::encodeValue($this->value); $oldRules = $this->_value_rules; $this->_value_rules = [[['value'], 'string']]; Yii::getLogger()->log('update:', YII_DEBUG); if ($setting->update()) { $this->_value_rules = $oldRules; return $setting; } else { $this->_value_rules = $oldRules; Yii::getLogger()->log('update error:' . print_r($setting, true), YII_DEBUG); } } return null; }
public function actionParsingLog($id) { $mod = LogUpload::findOne($id); $type = $mod->type; $params = \yii\helpers\Json::decode($mod->params); $values = \yii\helpers\Json::decode($mod->values); $modelAttribute = new Setting(); $not = Util::excelNot(); foreach ($modelAttribute->attributeLabels() as $k => $v) { if (!in_array($k, $not)) { $attr[] = $k; } } foreach ($values as $value) { if ($type == LogUpload::TYPE_INSERT) { $model = new Setting(); } else { $model = Setting::findOne($value['id']); } foreach ($attr as $at) { if (isset($value[$at])) { if ($value[$at]) { $model->{$at} = trim($value[$at]); } } } $e = 0; if ($model->save()) { $model = NULL; $pos = NULL; } else { $error[] = \yii\helpers\Json::encode($model->getErrors()); $e = 1; } } if ($error) { foreach ($error as $err) { if ($err) { $er[] = $err; $e += 1; } } if ($e) { $mod->warning = \yii\helpers\Json::encode($er); $mod->save(); echo '<pre>'; print_r($er); } } }