public static function validators() { return ['userSearch' => function ($activeForm, $request) { if (empty($request['userSearch'])) { throw new \Exception('Не указан получатель'); } if (!(int) $request['userSearch']) { throw new \Exception('Не указан получатель'); } $user = \Users\User::get((int) $request['userSearch']); if (!$user) { throw new \Exception('Такой пользователь не найден'); } if ($user->id == \Users\User::$cur->id) { throw new \Exception('Нельзя выбрать себя в качестве получателя'); } return true; }, 'amount' => function ($activeForm, $request) { if (empty($request['amount'])) { throw new \Exception('Не указана сумма'); } if (!(double) $request['amount']) { throw new \Exception('Не указана сумма'); } $amount = (double) $request['amount']; if (empty($request['wallets'])) { throw new \Exception('Не указан кошелек'); } if (!(int) $request['wallets']) { throw new \Exception('Не указан кошелек'); } $wallets = \App::$cur->money->getUserWallets(); if (empty($wallets[(int) $request['wallets']])) { throw new \Exception('У вас нет такого кошелька'); } $wallet = $wallets[(int) $request['wallets']]; if (!$wallet->currency->transfer) { throw new \Exception('Вы не можете переводить эту валюту'); } if ($wallet->amount < $amount) { throw new \Exception('У вас недостаточно средств на кошельке'); } return true; }, 'commentClean' => function ($activeForm, &$request) { $request['comment'] = trim(htmlspecialchars(urldecode($request['comment']))); }]; }
public function resendActivationAction($userId = 0) { $user = \Users\User::get((int) $userId); if (!$user) { Tools::redirect('/', 'Не указан пользователь', 'danger'); } if (!$user->activation) { Tools::redirect('/', 'Пользователь уже активирован'); } $from = 'noreply@' . INJI_DOMAIN_NAME; $to = $user->mail; $subject = 'Активация аккаунта на сайте ' . idn_to_utf8(INJI_DOMAIN_NAME); $text = 'Для активации вашего аккаунта перейдите по ссылке <a href = "http://' . INJI_DOMAIN_NAME . '/users/activation/' . $user->id . '/' . $user->activation . '">http://' . idn_to_utf8(INJI_DOMAIN_NAME) . '/users/activation/' . $user->id . '/' . $user->activation . '</a>'; Tools::sendMail($from, $to, $subject, $text); Tools::redirect('/', 'На указанный почтовый ящик была выслана ваша ссылка для подтверждения E-Mail', 'success'); }
public function parseDeliveryFields($data, $cart, $fields) { $name = ''; foreach ($fields as $field) { if ($field->save && !empty($data[$field->id])) { $name .= htmlspecialchars($data[$field->id]) . ' '; } } $name = trim($name); $save = Ecommerce\Delivery\Save::get([['user_id', $cart->user->id], ['name', $name]]); if (!$save) { $save = new Ecommerce\Delivery\Save(); $save->user_id = $cart->user->id; $save->name = $name; $save->save(); foreach ($fields as $field) { if (!$field->save) { continue; } $saveValue = new Ecommerce\Delivery\Value(); $saveValue->value = htmlspecialchars($data[$field->id]); $saveValue->delivery_field_id = $field->id; $saveValue->delivery_save_id = $save->id; $saveValue->save(); } } $user = \Users\User::get($cart->user_id); foreach ($fields as $field) { $info = new \Ecommerce\Cart\DeliveryInfo(); $info->name = $field->name; $info->value = htmlspecialchars($data[$field->id]); $info->delivery_field_id = $field->id; $info->cart_id = $cart->id; $info->save(); $relations = []; if ($field->userfield) { if (strpos($field->userfield, ':')) { $path = explode(':', $field->userfield); if (!$user->{$path[0]}->{$path[1]}) { $user->{$path[0]}->{$path[1]} = $info->value; $relations[$path[0]] = $path[0]; } } else { if (!$user->{$field->userfield}) { $user->{$field->userfield} = $info->value; } } } foreach ($relations as $rel) { $user->{$rel}->save(); } $user->save(); } return $save; }
public static function auth() { $config = static::getConfig(); if (empty($_GET['code']) && empty($_GET['error'])) { $query = ['client_id' => $config['appId'], 'scope' => 'email', 'response_type' => 'code', 'display' => 'page', 'redirect_uri' => 'http://' . INJI_DOMAIN_NAME . '/users/social/auth/vk']; \Tools::redirect("https://oauth.vk.com/authorize?" . http_build_query($query)); } if (empty($_GET['code']) && !empty($_GET['error'])) { \Tools::redirect('/', 'Произошла ошибка во время авторизации через соц. сеть: ' . $_GET['error_description']); } $query = ['client_id' => $config['appId'], 'client_secret' => $config['secret'], 'code' => $_GET['code'], 'redirect_uri' => 'http://' . INJI_DOMAIN_NAME . '/users/social/auth/vk']; $result = @file_get_contents("https://oauth.vk.com/access_token?" . http_build_query($query)); if ($result === false) { \Tools::redirect('/', 'Во время авторизации произошли ошибки', 'danger'); } $result = json_decode($result, true); if (empty($result['user_id'])) { \Tools::redirect('/', 'Во время авторизации произошли ошибки', 'danger'); } $userQuery = ['user_id' => $result['user_id'], 'fields' => 'sex, bdate, photo_max_orig, home_town', 'access_token' => $result['access_token']]; $userResult = @file_get_contents("https://api.vk.com/method/users.get?" . http_build_query($userQuery)); if (!$userResult) { \Tools::redirect('/', 'Во время авторизации произошли ошибки', 'danger'); } $userDetail = json_decode($userResult, true); if (empty($userDetail['response'][0])) { \Tools::redirect('/', 'Во время авторизации произошли ошибки', 'danger'); } $social = static::getObject(); $userSocial = \Users\User\Social::get([['uid', $result['user_id']], ['social_id', $social->id]]); if ($userSocial && $userSocial->user) { \App::$cur->users->newSession($userSocial->user); if (!empty(\App::$cur->users->config['loginUrl'][\App::$cur->type])) { \Tools::redirect(\App::$cur->users->config['loginUrl'][\App::$cur->type]); } } else { if ($userSocial && !$userSocial->user) { $userSocial->delete(); } if (!\Users\User::$cur->id) { $user = false; if (!empty($result['email'])) { $user = \Users\User::get($result['email'], 'mail'); } if (!$user) { $user = new \Users\User(); $user->group_id = 2; $user->role_id = 2; if (!empty($result['email'])) { $user->login = $user->mail = $result['email']; } $invite_code = !empty($_POST['invite_code']) ? $_POST['invite_code'] : (!empty($_COOKIE['invite_code']) ? $_COOKIE['invite_code'] : (!empty($_GET['invite_code']) ? $_GET['invite_code'] : '')); if (!empty($invite_code)) { $invite = \Users\User\Invite::get($invite_code, 'code'); $inveiteError = false; if (!$invite) { Msg::add('Такой код пришлашения не найден', 'danger'); $inveiteError = true; } if ($invite->limit && !($invite->limit - $invite->count)) { Msg::add('Лимит приглашений для данного кода исчерпан', 'danger'); $inveiteError = true; } if (!$inveiteError) { $user->parent_id = $invite->user_id; $invite->count++; $invite->save(); } } if (!$user->parent_id && !empty(\App::$cur->Users->config['defaultPartner'])) { $user->parent_id = \App::$cur->Users->config['defaultPartner']; } $user->save(); $userInfo = new \Users\User\Info(); $userInfo->user_id = $user->id; $userInfo->save(); } } else { $user = \Users\User::$cur; } if (!$user->info->photo_file_id && !empty($userDetail['response'][0]['photo_max_orig'])) { $user->info->photo_file_id = \App::$cur->files->uploadFromUrl($userDetail['response'][0]['photo_max_orig']); } if (!$user->info->first_name && !empty($userDetail['response'][0]['first_name'])) { $user->info->first_name = $userDetail['response'][0]['first_name']; } if (!$user->info->last_name && !empty($userDetail['response'][0]['last_name'])) { $user->info->last_name = $userDetail['response'][0]['last_name']; } if (!$user->info->city && !empty($userDetail['response'][0]['home_town'])) { $user->info->city = $userDetail['response'][0]['home_town']; } if (!$user->info->sex && !empty($userDetail['response'][0]['sex'])) { $user->info->sex = $userDetail['response'][0]['sex'] == 2 ? 1 : ($userDetail['response'][0]['sex'] == 1 ? 2 : 0); } if ($user->info->bday == '0000-00-00' && !empty($userDetail['response'][0]['bdate'])) { $user->info->bday = substr_count($userDetail['response'][0]['bdate'], '.') == 2 ? \DateTime::createFromFormat('d.m.Y', $userDetail['response'][0]['bdate'])->format('Y-m-d') : (substr_count($userDetail['response'][0]['bdate'], '.') == 1 ? \DateTime::createFromFormat('d.m', $userDetail['response'][0]['bdate'])->format('Y-m-1') : '0000-00-00'); } $user->info->save(); $userSocial = new \Users\User\Social(); $userSocial->uid = $result['user_id']; $userSocial->social_id = $social->id; $userSocial->user_id = $user->id; $userSocial->save(); \App::$cur->users->newSession($user); \Tools::redirect(\App::$cur->users->config['loginUrl'][\App::$cur->type], 'Вы успешно зарегистрировались через ВКонтакте', 'success'); } }
public static function auth() { $config = static::getConfig(); if (empty($_GET['code']) && empty($_GET['error'])) { $query = ['client_id' => $config['appId'], 'scope' => 'email', 'response_type' => 'code', 'redirect_uri' => 'http://' . INJI_DOMAIN_NAME . '/users/social/auth/facebook']; \Tools::redirect("https://www.facebook.com/dialog/oauth?" . http_build_query($query)); } if (empty($_GET['code']) && !empty($_GET['error'])) { \Tools::redirect('/', 'Произошла ошибка во время авторизации через соц. сеть: ' . $_GET['error_description']); } $query = ['client_id' => $config['appId'], 'redirect_uri' => 'http://' . INJI_DOMAIN_NAME . '/users/social/auth/facebook', 'client_secret' => $config['secret'], 'code' => urldecode($_GET['code'])]; $result = @file_get_contents("https://graph.facebook.com/oauth/access_token?" . http_build_query($query)); if ($result === false) { \Tools::redirect('/', 'Во время авторизации произошли ошибки', 'danger'); } parse_str($result, $output); if (empty($output['access_token'])) { \Tools::redirect('/', 'Во время авторизации произошли ошибки', 'danger'); } $userQuery = ['access_token' => $output['access_token'], 'fields' => 'first_name,middle_name,last_name,email,gender,location,picture']; $userResult = @file_get_contents("https://graph.facebook.com/me?" . http_build_query($userQuery)); if (!$userResult) { \Tools::redirect('/', 'Во время авторизации произошли ошибки', 'danger'); } $userDetail = json_decode($userResult, true); if (empty($userDetail['id'])) { \Tools::redirect('/', 'Во время авторизации произошли ошибки', 'danger'); } $social = static::getObject(); $userSocial = \Users\User\Social::get([['uid', $userDetail['id']], ['social_id', $social->id]]); if ($userSocial && $userSocial->user) { \App::$cur->users->newSession($userSocial->user); if (!empty(\App::$cur->users->config['loginUrl'][\App::$cur->type])) { \Tools::redirect(\App::$cur->users->config['loginUrl'][\App::$cur->type]); } } else { if ($userSocial && !$userSocial->user) { $userSocial->delete(); } if (!\Users\User::$cur->id) { $user = false; if (!empty($userDetail['email'])) { $user = \Users\User::get($userDetail['email'], 'mail'); } if (!$user) { $user = new \Users\User(); $user->group_id = 2; $user->role_id = 2; if (!empty($userDetail['email'])) { $user->login = $user->mail = $userDetail['email']; } $invite_code = !empty($_POST['invite_code']) ? $_POST['invite_code'] : (!empty($_COOKIE['invite_code']) ? $_COOKIE['invite_code'] : (!empty($_GET['invite_code']) ? $_GET['invite_code'] : '')); if (!empty($invite_code)) { $invite = \Users\User\Invite::get($invite_code, 'code'); $inveiteError = false; if (!$invite) { Msg::add('Такой код пришлашения не найден', 'danger'); $inveiteError = true; } if ($invite->limit && !($invite->limit - $invite->count)) { Msg::add('Лимит приглашений для данного кода исчерпан', 'danger'); $inveiteError = true; } if (!$inveiteError) { $user->parent_id = $invite->user_id; $invite->count++; $invite->save(); } } if (!$user->parent_id && !empty(\App::$cur->Users->config['defaultPartner'])) { $user->parent_id = \App::$cur->Users->config['defaultPartner']; } $user->save(); $userInfo = new \Users\User\Info(); $userInfo->user_id = $user->id; $userInfo->save(); } } else { $user = \Users\User::$cur; } if (!$user->info->photo_file_id && !empty($userDetail['picture']['data']['url'])) { $user->info->photo_file_id = \App::$cur->files->uploadFromUrl($userDetail['picture']['data']['url']); } if (!$user->info->first_name && !empty($userDetail['first_name'])) { $user->info->first_name = $userDetail['first_name']; } if (!$user->info->last_name && !empty($userDetail['last_name'])) { $user->info->last_name = $userDetail['last_name']; } if (!$user->info->middle_name && !empty($userDetail['middle_name'])) { $user->info->middle_name = $userDetail['middle_name']; } if (!$user->info->city && !empty($userDetail['location'])) { $user->info->city = $userDetail['location']; } if (!$user->info->sex && !empty($userDetail['gender'])) { $user->info->sex = $userDetail['gender'] == 'male' ? 1 : ($userDetail['gender'] == 'female' ? 2 : 0); } $user->info->save(); $userSocial = new \Users\User\Social(); $userSocial->uid = $userDetail['id']; $userSocial->social_id = $social->id; $userSocial->user_id = $user->id; $userSocial->save(); \App::$cur->users->newSession($user); if (!empty(\App::$cur->users->config['loginUrl'][\App::$cur->type])) { \Tools::redirect(\App::$cur->users->config['loginUrl'][\App::$cur->type], 'Вы успешно зарегистрировались через Facebook', 'success'); } else { \Tools::redirect('/users/cabinet/profile', 'Вы успешно зарегистрировались через Facebook', 'success'); } } }
public static function auth() { $config = static::getConfig(); if (empty($_GET['code']) && empty($_GET['error'])) { $query = ['client_id' => $config['client_id'], 'scope' => 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile', 'response_type' => 'code', 'redirect_uri' => 'http://' . INJI_DOMAIN_NAME . '/users/social/auth/google']; \Tools::redirect("https://accounts.google.com/o/oauth2/auth?" . http_build_query($query)); } if (empty($_GET['code']) && !empty($_GET['error'])) { \Tools::redirect('/', 'Произошла ошибка во время авторизации через соц. сеть: ' . $_GET['error_description']); } $query = ['client_id' => $config['client_id'], 'client_secret' => $config['secret'], 'code' => $_GET['code'], 'grant_type' => 'authorization_code', 'redirect_uri' => 'http://' . INJI_DOMAIN_NAME . '/users/social/auth/google']; $result = false; if ($curl = curl_init()) { curl_setopt($curl, CURLOPT_URL, 'https://accounts.google.com/o/oauth2/token'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($query)); $result = curl_exec($curl); curl_close($curl); } if ($result === false) { \Tools::redirect('/', 'Во время авторизации произошли ошибки', 'danger'); } $result = json_decode($result, true); if (empty($result['access_token'])) { \Tools::redirect('/', 'Во время авторизации произошли ошибки', 'danger'); } $userQuery = ['access_token' => $result['access_token']]; $userResult = @file_get_contents("https://www.googleapis.com/oauth2/v1/userinfo?" . http_build_query($userQuery)); if (!$userResult) { \Tools::redirect('/', 'Во время авторизации произошли ошибки', 'danger'); } $userDetail = json_decode($userResult, true); if (empty($userDetail['id'])) { \Tools::redirect('/', 'Во время авторизации произошли ошибки', 'danger'); } $social = static::getObject(); $userSocial = \Users\User\Social::get([['uid', $userDetail['id']], ['social_id', $social->id]]); if ($userSocial && $userSocial->user) { \App::$cur->users->newSession($userSocial->user); if (!empty(\App::$cur->users->config['loginUrl'][\App::$cur->type])) { \Tools::redirect(\App::$cur->users->config['loginUrl'][\App::$cur->type]); } } else { if ($userSocial && !$userSocial->user) { $userSocial->delete(); } if (!\Users\User::$cur->id) { $user = false; if (!empty($userDetail['email']) && !empty($userDetail['verified_email'])) { $user = \Users\User::get($userDetail['email'], 'mail'); } if (!$user) { $user = new \Users\User(); $user->group_id = 2; $user->role_id = 2; if (!empty($userDetail['email']) && !empty($userDetail['verified_email'])) { $user->login = $user->mail = $userDetail['email']; } $invite_code = !empty($_POST['invite_code']) ? $_POST['invite_code'] : (!empty($_COOKIE['invite_code']) ? $_COOKIE['invite_code'] : (!empty($_GET['invite_code']) ? $_GET['invite_code'] : '')); if (!empty($invite_code)) { $invite = \Users\User\Invite::get($invite_code, 'code'); $inveiteError = false; if (!$invite) { Msg::add('Такой код пришлашения не найден', 'danger'); $inveiteError = true; } if ($invite->limit && !($invite->limit - $invite->count)) { Msg::add('Лимит приглашений для данного кода исчерпан', 'danger'); $inveiteError = true; } if (!$inveiteError) { $user->parent_id = $invite->user_id; $invite->count++; $invite->save(); } } if (!$user->parent_id && !empty(\App::$cur->Users->config['defaultPartner'])) { $user->parent_id = \App::$cur->Users->config['defaultPartner']; } $user->save(); $userInfo = new \Users\User\Info(); $userInfo->user_id = $user->id; $userInfo->save(); } } else { $user = \Users\User::$cur; } if (!$user->info->photo_file_id && !empty($userDetail['picture'])) { $user->info->photo_file_id = \App::$cur->files->uploadFromUrl($userDetail['picture']); } if (!$user->info->first_name && !empty($userDetail['given_name'])) { $user->info->first_name = $userDetail['given_name']; } if (!$user->info->last_name && !empty($userDetail['family_name'])) { $user->info->last_name = $userDetail['family_name']; } if (!$user->info->sex && !empty($userDetail['gender'])) { $user->info->sex = $userDetail['gender'] == 'male' ? 1 : ($userDetail['gender'] == 'female' ? 2 : 0); } $user->info->save(); $userSocial = new \Users\User\Social(); $userSocial->uid = $userDetail['id']; $userSocial->social_id = $social->id; $userSocial->user_id = $user->id; $userSocial->save(); \App::$cur->users->newSession($user); \Tools::redirect('/users/cabinet/profile', 'Вы успешно зарегистрировались через Google+', 'success'); } }