mirror of
https://github.com/1sept/oauth2-1sept.git
synced 2024-05-30 17:38:52 +03:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eca6845e85 | |||
| 601acfeae6 | |||
| 1fe3ca9cd9 | |||
| 7a7723a140 | |||
| 5ad486f920 | |||
| 927601d0e0 | |||
| 4d5db6e092 | |||
| 5a22804f38 | |||
| 7384e5aa50 |
12
README.md
12
README.md
@@ -5,15 +5,7 @@ This package provides [September First](https://api.1sept.ru) integration for [O
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Add to `composer.json`:
|
Just execute:
|
||||||
```
|
|
||||||
"repositories": [{
|
|
||||||
"type": "vcs",
|
|
||||||
"url": "https://github.com/1sept/oauth2-1sept"
|
|
||||||
}],
|
|
||||||
```
|
|
||||||
|
|
||||||
Then execute:
|
|
||||||
```sh
|
```sh
|
||||||
composer require 1sept/oauth2-1sept
|
composer require 1sept/oauth2-1sept
|
||||||
```
|
```
|
||||||
@@ -21,7 +13,7 @@ composer require 1sept/oauth2-1sept
|
|||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$provider = new Sept\OAuth2\Client\Provider\SeptemberFirst([
|
$provider = new \Sept\OAuth2\Client\Provider\SeptemberFirstProvider([
|
||||||
'clientId' => 'client_id',
|
'clientId' => 'client_id',
|
||||||
'clientSecret' => 'secret',
|
'clientSecret' => 'secret',
|
||||||
'redirectUri' => 'https://example.org/oauth-endpoint',
|
'redirectUri' => 'https://example.org/oauth-endpoint',
|
||||||
|
|||||||
@@ -13,11 +13,11 @@
|
|||||||
"oauth2",
|
"oauth2",
|
||||||
"client",
|
"client",
|
||||||
"authorization",
|
"authorization",
|
||||||
"authorisation",
|
"authorization",
|
||||||
"1sept"
|
"1sept"
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.0",
|
"php": "^7.3 || ^8",
|
||||||
"league/oauth2-client": "^2.0"
|
"league/oauth2-client": "^2.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Sept\OAuth2\Client\Provider;
|
namespace Sept\OAuth2\Client\Provider;
|
||||||
|
|
||||||
use League\OAuth2\Client\Provider\AbstractProvider;
|
use League\OAuth2\Client\Provider\AbstractProvider;
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Sept\OAuth2\Client\Provider;
|
namespace Sept\OAuth2\Client\Provider;
|
||||||
|
|
||||||
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
|
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
|
||||||
@@ -9,6 +11,8 @@ use League\OAuth2\Client\Provider\ResourceOwnerInterface;
|
|||||||
*/
|
*/
|
||||||
class SeptemberFirstUser implements ResourceOwnerInterface
|
class SeptemberFirstUser implements ResourceOwnerInterface
|
||||||
{
|
{
|
||||||
|
const AVATAR_BASE = 'https://avatar.1sept.ru';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array Массив с данными о пользователе
|
* @var array Массив с данными о пользователе
|
||||||
*/
|
*/
|
||||||
@@ -142,35 +146,101 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL картинки
|
* URL аватарки (150x150)
|
||||||
*
|
*
|
||||||
* @param bool $rejectEmptyAvatar Если true, то пустые аватарки (заглушки) не отдаются
|
* @param bool $addVersion Использовать версию аватарки для улучшенного кэширования
|
||||||
* @return string|null
|
* @return string|null
|
||||||
|
*
|
||||||
|
* @example https://avatar.1sept.ru/12121212-3456-7243-2134-432432144221.jpeg?v=12345
|
||||||
*/
|
*/
|
||||||
public function getAvatarUrl(bool $rejectEmptyAvatar = false): ?string
|
public function getAvatarUrl(bool $addVersion = true): ?string
|
||||||
{
|
{
|
||||||
if (empty($this->data['avatar']) or ((!isset($this->data['has_avatar']) or !$this->data['has_avatar']) and $rejectEmptyAvatar)) {
|
return $this->getField('avatar') . ($addVersion ? $this->getAvatarVersionQuery() : '');
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->getField('avatar');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Адрес аватарки 50x50
|
* URL аватарки определённого размера (<img src="…" width="size" height="size">)
|
||||||
*
|
*
|
||||||
* @param bool $rejectEmptyAvatar Если true, то пустые аватарки (заглушки) не отдаются
|
* @param int $size Размер от 1 до 1990 ($size x $size — квадрат)
|
||||||
|
* @param int $ratioMultiplier Множитель разрешения картинки: 1 (по умолчанию), 2 или 3
|
||||||
|
* @param bool $addVersion Использовать версию аватарки для улучшенного кэширования
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getAvatar50Url(bool $rejectEmptyAvatar = false): ?string
|
public function getAvatarSizeUrl(int $size, int $ratioMultiplier = 1, bool $addVersion = true): ?string
|
||||||
{
|
{
|
||||||
return $this->getAvatarUrl($rejectEmptyAvatar);
|
$ratio = ($ratioMultiplier > 1) ? '@' . $ratioMultiplier . 'x' : '';
|
||||||
|
$url = static::AVATAR_BASE .'/'. $this->getId() . ($size ? '.' : '') . $size . $ratio . '.jpeg';
|
||||||
|
return $url . ($addVersion ? $this->getAvatarVersionQuery() : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL аватарки для экранов разных разрешений (для <img srcset="…" width="size" height="size">)
|
||||||
|
*
|
||||||
|
* @param int $size Размер от 1 до 1990 ($size x $size — квадрат)
|
||||||
|
* @param bool $addVersion Использовать версию аватарки для улучшенного кэширования
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getAvatarSetSizeUrl(int $size, bool $addVersion = true): string
|
||||||
|
{
|
||||||
|
return $this->getAvatarSizeUrl($size, 1, $addVersion) . ' 1x, '
|
||||||
|
. $this->getAvatarSizeUrl($size, 2, $addVersion) . ' 2x, '
|
||||||
|
. $this->getAvatarSizeUrl($size, 3, $addVersion) . ' 3x';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL аватарки c максимальным размером
|
||||||
|
*
|
||||||
|
* @param bool $useVersion Использовать версию аватарки для улучшенного кэширования
|
||||||
|
* @return string|null
|
||||||
|
* @example https://avatar.1sept.ru/12121212-3456-7243-2134-432432144221.max.jpeg?v=12345
|
||||||
|
*/
|
||||||
|
public function getAvatarMaxUrl(bool $addVersion = false): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('avatar_max') . ($addVersion ? $this->getAvatarVersionQuery() : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Версия аватарки
|
||||||
|
* Изменение версии сигнализирует об обновлении аватарки.
|
||||||
|
*
|
||||||
|
* @return int|null
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function getAvatarVersion(): ?int
|
||||||
|
{
|
||||||
|
return $this->getField('avatar_version');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Является ли аватарка заглушкой
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function isDefaultAvatar(): bool
|
||||||
|
{
|
||||||
|
return (bool) $this->getField('avatar_default');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query строка c версией аватарки (улучшает кэширование)
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @example ?v=12345;
|
||||||
|
*/
|
||||||
|
public function getAvatarVersionQuery(): string
|
||||||
|
{
|
||||||
|
$query = '';
|
||||||
|
if ($version = $this->getField('avatar_version')) {
|
||||||
|
$query .= '?v=' . $version;
|
||||||
|
}
|
||||||
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL публичной страницы профиля
|
* URL публичной страницы профиля
|
||||||
*
|
*
|
||||||
* @return string|null
|
* @return string|null
|
||||||
|
* @example https://vk.com/hello
|
||||||
*/
|
*/
|
||||||
public function getProfileUrl(): ?string
|
public function getProfileUrl(): ?string
|
||||||
{
|
{
|
||||||
@@ -178,13 +248,32 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Номер телефона
|
* Номера телефонов
|
||||||
|
*
|
||||||
|
* @return array|null
|
||||||
|
* @example [
|
||||||
|
* [
|
||||||
|
* "canonical" => "+79161234567",
|
||||||
|
* "number" => "+7 (916) 123-45-67",
|
||||||
|
* "type" => "mobile"
|
||||||
|
* ],
|
||||||
|
* …
|
||||||
|
* ]
|
||||||
|
*/
|
||||||
|
public function getPhones(): ?array
|
||||||
|
{
|
||||||
|
return $this->getField('phones');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* СНИЛС
|
||||||
*
|
*
|
||||||
* @return string|null
|
* @return string|null
|
||||||
|
* @example 123-123-123 56
|
||||||
*/
|
*/
|
||||||
public function getPhone(): ?string
|
public function getSnils(): ?string
|
||||||
{
|
{
|
||||||
return $this->getField('phone');
|
return $this->getField('passport.snils');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -209,6 +298,227 @@ class SeptemberFirstUser implements ResourceOwnerInterface
|
|||||||
return $this->getField('timezone');
|
return $this->getField('timezone');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID адреса
|
||||||
|
*
|
||||||
|
* @return int|null
|
||||||
|
* @example 12345
|
||||||
|
*/
|
||||||
|
public function getAddressID(): ?int
|
||||||
|
{
|
||||||
|
$id = $this->getField('address.id');
|
||||||
|
return $id ? (int) $id : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID страны адреса
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example RU
|
||||||
|
*/
|
||||||
|
public function getAddressCountryID(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.country_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID региона страны адреса
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example MOW
|
||||||
|
*/
|
||||||
|
public function getAddressRegionID(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.region_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Почтовый индекс
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example 123456
|
||||||
|
*/
|
||||||
|
public function getAddressPostalcode(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.postal_code');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Район
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example Октябрьский район
|
||||||
|
*/
|
||||||
|
public function getAddressArea(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.area');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Город
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example Муром
|
||||||
|
*/
|
||||||
|
public function getAddressCity(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.city');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Улица
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example ул. Профсоюзная
|
||||||
|
*/
|
||||||
|
public function getAddressStreet(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.street');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Здание, сооружение, дом, владение, объект незавершенного строительства
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example д. 5
|
||||||
|
*/
|
||||||
|
public function getAddressHouse(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.house');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Строение
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example стр. 5
|
||||||
|
*/
|
||||||
|
public function getAddressBuilding(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.building');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Помещение в пределах здания, сооружения (Квартира, офис, помещение и т.д.)
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example кв. 1б | оф. 13 | помещ. 17
|
||||||
|
*/
|
||||||
|
public function getAddressFlat(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.flat');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* До востребования
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
* @example true
|
||||||
|
*/
|
||||||
|
public function isAddressGeneralDelivery(): bool
|
||||||
|
{
|
||||||
|
return (bool) $this->getField('address.general_delivery');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Абонентский ящик (А/Я)
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example а/я 123
|
||||||
|
*/
|
||||||
|
public function getAddressPostalBox(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.postal_box');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Организация по адресу
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example Школа №5
|
||||||
|
*/
|
||||||
|
public function getAddressOrganization(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.organization');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Почтовый адрес в строку (без индекса)
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example ул. Гагарина, д.5, кв. 21, Нижний Новгород
|
||||||
|
*/
|
||||||
|
public function getAddressInline(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('address.inline');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID страны (анкета)
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example RU
|
||||||
|
*/
|
||||||
|
public function getLocationCountryID(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('location.country_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Название страны (анкета)
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example Россия
|
||||||
|
*/
|
||||||
|
public function getLocationCountryName(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('location.country_name');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Название страны по английски (анкета)
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example Russia
|
||||||
|
*/
|
||||||
|
public function getLocationCountryNameEnglish(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('location.country_name_eng');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID региона страны (анкета)
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example MOW
|
||||||
|
*/
|
||||||
|
public function getLocationRegionID(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('location.region_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Название региона страны (анкета)
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example Москва
|
||||||
|
*/
|
||||||
|
public function getLocationRegionName(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('location.region_name');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Название региона страны по английски (анкета)
|
||||||
|
*
|
||||||
|
* @return string|null
|
||||||
|
* @example Moscow
|
||||||
|
*/
|
||||||
|
public function getLocationRegionNameEnglish(): ?string
|
||||||
|
{
|
||||||
|
return $this->getField('location.region_name_eng');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Элемент массива данных о пользователе
|
* Элемент массива данных о пользователе
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user