171 lines
6.5 KiB
PHP
171 lines
6.5 KiB
PHP
<?php
|
||
|
||
namespace app\services;
|
||
|
||
use app\models\Inquiries;
|
||
use app\models\register\PhplistUserUser;
|
||
use app\models\UserPublic;
|
||
use app\services\base\UserRequestBase;
|
||
use app\models\Ts;
|
||
use yii\base\BaseObject;
|
||
|
||
class UserRequest extends UserRequestBase
|
||
{
|
||
protected function signUp()
|
||
{
|
||
Ts::set([63, 64, 65, 66, 67, 68, 69, 70, 71]);
|
||
|
||
$this->isEmpty('full_name', Ts::get(63));
|
||
$this->isEmpty('email', Ts::get(64));
|
||
$this->isNotEmail('email', Ts::get(65));
|
||
$this->isExists('email', UserPublic::class, Ts::get(66));
|
||
$this->isNotSecurePassword('password', Ts::get(67));
|
||
$this->isNotMatch('cPassword', 'password', Ts::get(68));
|
||
$this->isNotChecked('has_terms', Ts::get(69));
|
||
$this->isNotChecked('has_privacy', Ts::get(197));
|
||
//$this->isNotChecked('has_cookies', Ts::get(70));
|
||
//$this->isEmpty('g-recaptcha-response', Ts::get(71));
|
||
//reCaptcha
|
||
//$secret = '6LcD2C4hAAAAAMZNC8E0XAoB2nbW29DrFlWPU5vJ';
|
||
//$response = $this->data->{'g-recaptcha-response'};
|
||
//$remoteip = $_SERVER['REMOTE_ADDR'];
|
||
//$url = "https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=$response&remoteip=$remoteip";
|
||
//$data = file_get_contents($url);
|
||
//$row = json_decode($data, true);
|
||
$full_name = explode(' ', $this->data->{'full_name'});
|
||
$firstName = $full_name[0];
|
||
$lastName = $full_name[1] ?? $firstName;
|
||
//if ($row['success'] == "true") {
|
||
|
||
//Create user into cms database
|
||
$user = new UserPublic();
|
||
$user->email = $this->data->{'email'};
|
||
$user->full_name = $this->data->{'full_name'};
|
||
|
||
//$user->password = $this->data->{'password'};
|
||
$user->setPasswordHash($this->data->{'password'});
|
||
if ($this->data->{'has_club_card'} == true)
|
||
$user->club_card = 1;
|
||
if (!empty($this->data->{'has_double_auth'}) && $this->data->{'has_double_auth'} == true)
|
||
$user->has_double_auth = 1;
|
||
if (!empty($this->data->{'has_newsletter'}) && $this->data->{'has_newsletter'} == true) {
|
||
$user->has_newsletter = 1;
|
||
PhplistUserUser::add($user->email);
|
||
}
|
||
$user->user_agent = $_SERVER['HTTP_USER_AGENT'];
|
||
if (!empty($_GET['device_id']))
|
||
$user->device_id = $_GET['device_id'];
|
||
$user->date_registered = date('Y-m-d H:i:s');
|
||
$user->save();
|
||
$requiredActions = [];
|
||
if (!empty($this->data->{'has_double_auth'}) && $this->data->{'has_double_auth'} == true) {
|
||
$requiredActions[] = 'CONFIGURE_TOTP';
|
||
}
|
||
$requiredActions[] = 'VERIFY_EMAIL';
|
||
|
||
//Create user into Identity server
|
||
$idServer = new IdServer();
|
||
$idsResponse = $idServer->customPostRequest('/users', [
|
||
'enabled' => true,
|
||
'username' => $this->data->{'email'},
|
||
'email' => $this->data->{'email'},
|
||
'firstName' => $firstName,
|
||
'lastName' => $lastName,
|
||
'credentials' => [
|
||
[
|
||
'type' => 'password',
|
||
'value' => $this->data->{'password'},
|
||
'temporary' => false
|
||
],
|
||
],
|
||
'requiredActions' => $requiredActions,
|
||
//'requiredActions' => [
|
||
// 'CONFIGURE_TOTP',
|
||
// 'VERIFY_EMAIL'
|
||
//],
|
||
'groups' => ['public_user'],
|
||
'attributes' => [
|
||
'locale' => 'bg'
|
||
]
|
||
]);
|
||
return ['recaptcha-validated' => 1, 'id-server-response' => $idsResponse];
|
||
//}
|
||
}
|
||
|
||
|
||
protected function contact()
|
||
{
|
||
|
||
Ts::set([63, 64, 65]);
|
||
$this->isEmpty('full_name', Ts::get(63));
|
||
$this->isEmpty('email', Ts::get(64));
|
||
$this->isNotEmail('email', Ts::get(65));
|
||
$html = "<div>Име: " . $this->data->{'full_name'} . "</div>";
|
||
$html .= "<div>Е-mail: " . $this->data->{'email'} . "</div>";
|
||
|
||
if ($this->data->{"koo"})
|
||
$html .= "<div>" . $this->data->{"koo"} . "</div>";
|
||
if ($this->data->{"wwr"})
|
||
$html .= "<div>" . $this->data->{"wwr"} . "</div>";
|
||
|
||
$inq = new Inquiries();
|
||
$inq->email = $this->data->{'email'};
|
||
$inq->name = $this->data->{'full_name'};
|
||
$inq->operation = $this->data->{'koo'};
|
||
$inq->error = $this->data->{'wwr'};
|
||
$inq->date_time = date('Y-m-d H:i:s');
|
||
$inq->save();
|
||
|
||
//MailService::mailer($this->data->{'email'}, "coe@nasledstvo.bg", $html, 'Heritage BG Inquiry');
|
||
|
||
}
|
||
|
||
protected function editProfile()
|
||
{
|
||
Ts::set([63]);
|
||
$this->isEmpty('full_name', Ts::get(63));
|
||
$user = Auth::getUser();
|
||
$user->full_name = $this->data->{'full_name'};
|
||
$user->save();
|
||
}
|
||
|
||
function changePassword()
|
||
{
|
||
$this->isEmpty('old_password', Ts::get(212));
|
||
$this->wrongOldPassword('old_password', Ts::get(215));
|
||
$this->isEmpty('password', Ts::get(213));
|
||
$this->isNotSecurePassword('password', Ts::get(67));
|
||
$this->isEmpty('password_confirm', Ts::get(216));
|
||
$this->isNotMatch('password_confirm', 'password', Ts::get(68));
|
||
$password = $this->data->{'password'};
|
||
$user = Auth::getUser();
|
||
$user->password = $password;
|
||
$user->password_hash = password_hash($password, PASSWORD_DEFAULT);
|
||
$idServer = new IdServer();
|
||
$result = $idServer->updatePassword($user->open_id, $password);
|
||
if (!empty($result['is_success']) && $result['is_success']) {
|
||
$user->save();
|
||
}
|
||
$this->sendSuccess(Ts::get(214));
|
||
}
|
||
|
||
|
||
protected function setInvoiceData()
|
||
{
|
||
switch ($this->data->invoice_data_type) {
|
||
case 1:
|
||
$this->isEmpty('first_name', 'Моля попълнете име');
|
||
$this->isEmpty('last_name', 'Моля попълнете фамилия');
|
||
$this->isEmpty('country', 'Моля попълнете страна');
|
||
$this->isEmpty('city', 'Моля попълнете град или село');
|
||
$this->isEmpty('address', 'Моля попълнете адрес');
|
||
break;
|
||
case 2:
|
||
$this->isEmpty('company_name', 'Моля попълнете име на фирма');
|
||
$this->isEmpty('eik', 'Моля попълнете ЕИК');
|
||
$this->isEmpty('mol', 'Моля попълнете МОЛ');
|
||
}
|
||
setcookie('invoice_data', json_encode($this->data), time() + (86400 * 30), "/");
|
||
}
|
||
}
|