Forum içeriğine ve tüm hizmetlerimize erişim sağlamak için foruma kayıt olmalı ya da giriş yapmalısınız. Foruma üye olmak tamamen ücretsizdir.
namespace XenGenTr\AndroidSystem\Service\AndroidApi;
use XF\Service\AbstractService;
class AndroidApi extends AbstractService
{
protected $AndroidApi = 'https://apiurl_gelecek';
protected $korumalibiristemcidegiskeni;
public function __construct(\XF\App $app)
{
parent::__construct($app);
$this->korumalibiristemcidegiskeni= $app->http()->korumalibiristemcidegiskeni();
}
......................
.....................................
....................................................
...........................................................devam eder gider.
}
<?php
namespace XF\Api\Controller;
use XF\Mvc\Entity\Entity;
use XF\Mvc\ParameterBag;
/**
* @api-group Auth
*/
class Auth extends AbstractController
{
protected function preDispatchController($action, ParameterBag $params)
{
$this->assertSuperUserKey();
$this->assertApiScope('auth');
}
/**
* @api-desc Tests a login and password for validity. Only available to super user keys.
*
* @api-in <req> str $login The username or email address of the user to test
* @api-in <req> str $password The password of the user
* @api-in str $limit_ip The IP that should be considered to be making the request. If provided, this will be used to prevent brute force attempts.
*
* @api-out User $user If successful, the user record of the matching user
*/
public function actionPost()
{
$this->assertRequiredApiInput(['login', 'password']);
$input = $this->filter([
'login' => 'str',
'password' => 'str',
'limit_ip' => 'str'
]);
/** @var \XF\Service\User\Login $loginService */
$loginService = $this->service('XF:User\Login', $input['login'], $input['limit_ip']);
if ($loginService->isLoginLimited($limitType))
{
return $this->error(\XF::phrase('your_account_has_temporarily_been_locked_due_to_failed_login_attempts'));
}
$user = $loginService->validate($input['password'], $error);
if (!$user)
{
return $this->error($error);
}
if ($user->security_lock)
{
return $this->error(\XF::phrase('your_account_is_currently_security_locked'));
}
return $this->apiSuccess([
'user' => $user->toApiResult(Entity::VERBOSITY_VERBOSE, ['full_profile' => true])
]);
}
/**
* @api-desc Looks up the active XenForo user based on session ID or remember cookie value.
* This can be used to help with seamless SSO with XF, assuming the session or remember cookies are
* available to your page. At least one of session_id and remember_cookie must be provided.
* Only available to super user keys.
*
* @api-in str $session_id If provided, checks for an active session with that ID.
* @api-in str $remember_cookie If provided, checks to see if this is an active "remember me" cookie value.
*
* @api-out bool $success If false, no session or remember cookie could be found
* @api-out User $user If successful, the user record of the matching user. May be a guest.
*/
public function actionPostFromSession()
{
$sessionId = $this->filter('session_id', 'str');
$rememberCookie = $this->filter('remember_cookie', 'str');
if (!$sessionId && !$rememberCookie)
{
$this->assertRequiredApiInput(['session_id', 'remember_cookie']);
}
if ($sessionId)
{
/** @var \XF\Session\StorageInterface $publicSessions */
$publicSessions = $this->app->get('session.public.storage');
$sessionData = $publicSessions->getSession($sessionId);
if (is_array($sessionData))
{
$sessionIpLimit = $this->filter('session_ip_limit', '?str');
if (is_string($sessionIpLimit))
{
$ipValidated = $this->validateIpAgainstSession($sessionData, $sessionIpLimit);
}
else
{
$ipValidated = true;
}
if ($ipValidated)
{
$user = $this->getUserFromSessionData($sessionData);
return $this->apiSuccess([
'user' => $user->toApiResult(Entity::VERBOSITY_VERBOSE, ['full_profile' => true])
]);
}
}
}
if ($rememberCookie)
{
/** @var \XF\Repository\UserRemember $rememberRepo */
$rememberRepo = $this->repository('XF:UserRemember');
if ($rememberRepo->validateByCookieValue($rememberCookie, $remember))
{
$user = $this->em()->find('XF:User', $remember->user_id, 'api');
return $this->apiSuccess([
'user' => $user->toApiResult(Entity::VERBOSITY_VERBOSE, ['full_profile' => true])
]);
}
}
return $this->apiBoolResult(false);
}
protected function validateIpAgainstSession(array $sessionData, string $expectedIp): bool
{
// this is basically copied out of the session class...
if (!isset($sessionData['_ip']) || empty($sessionData['_ip']) || empty($expectedIp))
{
return true; // no IP to check against
}
$expectedIp = \XF\Util\Ip::convertIpStringToBinary($expectedIp);
$cidr = strlen($expectedIp) == 4 ? 24 : 64;
if (empty($sessionData['userId']) || $cidr <= 0)
{
return true; // IP check disabled
}
return \XF\Util\Ip::ipMatchesCidrRange($expectedIp, $sessionData['_ip'], $cidr);
}
protected function getUserFromSessionData(array $sessionData): \XF\Entity\User
{
if (!empty($sessionData['userId']))
{
$user = $this->em()->find('XF:User', $sessionData['userId'], 'api');
if ($user)
{
$userPasswordDate = $user->Profile ? $user->Profile->password_date : 0;
if (!isset($sessionData['passwordDate']) || $sessionData['passwordDate'] == $userPasswordDate)
{
// we have a user and the password date matches, so we can consider them logged in
return $user;
}
}
}
return $this->repository('XF:User')->getGuestUser();
}
/**
* @api-desc Generates a token that can automatically log into a specific XenForo user when the login URL
* is visited. If the visitor is already logged into a XenForo account, they will not be logged into
* the specified account. Only available to super user keys.
*
* @api-in <req> int $user_id
* @api-in str $limit_ip If provided, locks the token to the specified IP for additional security
* @api-in str $return_url If provided, after logging the user will be returned to this URL. Otherwise they'll go to the XenForo index.
* @api-in bool $remember Controls whether the a "remember me" cookie will be set when the user logs in. Defaults to true.
*
* @api-out str $login_token
* @api-out str $login_url Direct user to this URL to trigger a login
* @api-out int $expiry_date Unix timestamp of when the token expires. An error will be displayed if the token is expired or invalid
*/
public function actionPostLoginToken()
{
$this->assertApiScope('auth:login_token');
$this->assertRequiredApiInput('user_id');
$userId = $this->filter('user_id', 'uint');
/** @var \XF\Entity\User $user */
$user = $this->assertRecordExists('XF:User', $userId, 'api');
/** @var \XF\Entity\ApiLoginToken $loginToken */
$loginToken = $this->em()->create('XF:ApiLoginToken');
$loginToken->user_id = $user->user_id;
$limitIp = $this->filter('limit_ip', 'str');
if ($limitIp)
{
$loginToken->limit_ip = $limitIp;
}
$loginToken->save();
$returnUrl = $this->filter('return_url', 'str');
$returnUrl = $returnUrl ? $this->request->convertToAbsoluteUri($returnUrl, true) : null;
$remember = $this->filter('remember', 'bool', true);
$publicRouter = $this->app->router('public');
return $this->apiResult([
'login_token' => $loginToken->login_token,
'login_url' => $publicRouter->buildLink(
'canonical:login/api-token',
null,
['token' => $loginToken->login_token, 'return_url' => $returnUrl, 'remember' => $remember ? 1 : 0]
),
'expiry_date' => $loginToken->expiry_date,
]);
}
}
Burda diyorki çekecegin api'yi bana komutla ben sana yönlendirme yapıcam ama seninde yönlendirme yapcagım dosyalara php koslarını girmen gerekiyorki çektiğin api anahtarını sana içerde izin verip çalıştırayım diyor.. he charismax bundan anlarmı anlar ama bakarken anlar yapamaz zor bu benim için çok zor senin için kolayArkadaşlar, xenforo yazılımı sıradan bir php yazılımı değil. Bazen kullanıcılar ya ben php biliyorum ama xenforo'a eklenti yazamıyorum gibi sorularla geliyor bizde bu konuda yeterlilik olmaz ise çaresiz kalıyoruz. Biz bile eklenti yazarken xenforo yapısını bir çok defa inceliyoruz, sınıflarının içerisinde kayboluyoruz. Yani çok gelişmiş bir yazılım ve gerçekten bir şeyler yapılmak isteniyorsa ileri seviye bir php bilgisinin olması gerekiyor. Çünkü adamlar çok çok ileri seviye de kodlama yapmışlar.
Api konusunda kaynak yok ama nasıl çekileceği ile alakalı dökümanları var onları da burada size attım ama onlar hakkında da bilgi sahibi olmanız gerekiyor en azından yazılımı çok iyi tanımanız gerekiyor.
Bak yukarıdaki kod alanında parent::__construct($app); olarak \XF\App sınıfını da dahil ettik. İşte olay buralarda dönüyor. Anlamadığınız noktalarda ne yapacaksanız ilgili sınıfa gideceksiniz bakacaksınız bu auth sınıfı benden ne istiyor aşağıdaki auth controller sınıfına bakıp orayı inceleyeceksiniz. Hangi fonksiyon sizden ne istiyor ona bakacaksınız.PHP:namespace XenGenTr\AndroidSystem\Service\AndroidApi; use XF\Service\AbstractService; class AndroidApi extends AbstractService { protected $api = 'https://apiurl_gelecek'; protected $korumalibiristemcidegiskeni; public function __construct(\XF\App $app) { parent::__construct($app); $this->korumalibiristemcidegiskeni= $app->http()->korumalibiristemcidegiskeni(); } ...................... ..................................... .................................................... ...........................................................devam eder gider. }
Burasıda diyorki .. yönlendirmeyi yaptık sana panel içinde bir panel açtık şimdi giriş loglarını kodlar diyorVe her fonksiyonun açıklamarı da ilgili dosyada yazmaktadır. Bu konular çok ileri seviye olduğu için xenforo.com'da bile ayrıntılı anlatan bir kişi bulamazsınız nedeni belli herkesin yapmak istediği farklı ve herkesin yazılımın ihtiyaçları farklı o yüzden xenforo'un kendi sınıflarını kendiniz inceleyeceksiniz. Koda baktığınız an kodun ne yaptığını anlayacaksınız yani ileri seviye de yazılmış bir kodu okuyup anlayacak bir düzeyde olmanız gerekiyor.PHP:<?php namespace XF\Api\Controller; use XF\Mvc\Entity\Entity; use XF\Mvc\ParameterBag; /** * @api-group Auth */ class Auth extends AbstractController { protected function preDispatchController($action, ParameterBag $params) { $this->assertSuperUserKey(); $this->assertApiScope('auth'); } /** * @api-desc Tests a login and password for validity. Only available to super user keys. * * @api-in <req> str $login The username or email address of the user to test * @api-in <req> str $password The password of the user * @api-in str $limit_ip The IP that should be considered to be making the request. If provided, this will be used to prevent brute force attempts. * * @api-out User $user If successful, the user record of the matching user */ public function actionPost() { $this->assertRequiredApiInput(['login', 'password']); $input = $this->filter([ 'login' => 'str', 'password' => 'str', 'limit_ip' => 'str' ]); /** @var \XF\Service\User\Login $loginService */ $loginService = $this->service('XF:User\Login', $input['login'], $input['limit_ip']); if ($loginService->isLoginLimited($limitType)) { return $this->error(\XF::phrase('your_account_has_temporarily_been_locked_due_to_failed_login_attempts')); } $user = $loginService->validate($input['password'], $error); if (!$user) { return $this->error($error); } if ($user->security_lock) { return $this->error(\XF::phrase('your_account_is_currently_security_locked')); } return $this->apiSuccess([ 'user' => $user->toApiResult(Entity::VERBOSITY_VERBOSE, ['full_profile' => true]) ]); } /** * @api-desc Looks up the active XenForo user based on session ID or remember cookie value. * This can be used to help with seamless SSO with XF, assuming the session or remember cookies are * available to your page. At least one of session_id and remember_cookie must be provided. * Only available to super user keys. * * @api-in str $session_id If provided, checks for an active session with that ID. * @api-in str $remember_cookie If provided, checks to see if this is an active "remember me" cookie value. * * @api-out bool $success If false, no session or remember cookie could be found * @api-out User $user If successful, the user record of the matching user. May be a guest. */ public function actionPostFromSession() { $sessionId = $this->filter('session_id', 'str'); $rememberCookie = $this->filter('remember_cookie', 'str'); if (!$sessionId && !$rememberCookie) { $this->assertRequiredApiInput(['session_id', 'remember_cookie']); } if ($sessionId) { /** @var \XF\Session\StorageInterface $publicSessions */ $publicSessions = $this->app->get('session.public.storage'); $sessionData = $publicSessions->getSession($sessionId); if (is_array($sessionData)) { $sessionIpLimit = $this->filter('session_ip_limit', '?str'); if (is_string($sessionIpLimit)) { $ipValidated = $this->validateIpAgainstSession($sessionData, $sessionIpLimit); } else { $ipValidated = true; } if ($ipValidated) { $user = $this->getUserFromSessionData($sessionData); return $this->apiSuccess([ 'user' => $user->toApiResult(Entity::VERBOSITY_VERBOSE, ['full_profile' => true]) ]); } } } if ($rememberCookie) { /** @var \XF\Repository\UserRemember $rememberRepo */ $rememberRepo = $this->repository('XF:UserRemember'); if ($rememberRepo->validateByCookieValue($rememberCookie, $remember)) { $user = $this->em()->find('XF:User', $remember->user_id, 'api'); return $this->apiSuccess([ 'user' => $user->toApiResult(Entity::VERBOSITY_VERBOSE, ['full_profile' => true]) ]); } } return $this->apiBoolResult(false); } protected function validateIpAgainstSession(array $sessionData, string $expectedIp): bool { // this is basically copied out of the session class... if (!isset($sessionData['_ip']) || empty($sessionData['_ip']) || empty($expectedIp)) { return true; // no IP to check against } $expectedIp = \XF\Util\Ip::convertIpStringToBinary($expectedIp); $cidr = strlen($expectedIp) == 4 ? 24 : 64; if (empty($sessionData['userId']) || $cidr <= 0) { return true; // IP check disabled } return \XF\Util\Ip::ipMatchesCidrRange($expectedIp, $sessionData['_ip'], $cidr); } protected function getUserFromSessionData(array $sessionData): \XF\Entity\User { if (!empty($sessionData['userId'])) { $user = $this->em()->find('XF:User', $sessionData['userId'], 'api'); if ($user) { $userPasswordDate = $user->Profile ? $user->Profile->password_date : 0; if (!isset($sessionData['passwordDate']) || $sessionData['passwordDate'] == $userPasswordDate) { // we have a user and the password date matches, so we can consider them logged in return $user; } } } return $this->repository('XF:User')->getGuestUser(); } /** * @api-desc Generates a token that can automatically log into a specific XenForo user when the login URL * is visited. If the visitor is already logged into a XenForo account, they will not be logged into * the specified account. Only available to super user keys. * * @api-in <req> int $user_id * @api-in str $limit_ip If provided, locks the token to the specified IP for additional security * @api-in str $return_url If provided, after logging the user will be returned to this URL. Otherwise they'll go to the XenForo index. * @api-in bool $remember Controls whether the a "remember me" cookie will be set when the user logs in. Defaults to true. * * @api-out str $login_token * @api-out str $login_url Direct user to this URL to trigger a login * @api-out int $expiry_date Unix timestamp of when the token expires. An error will be displayed if the token is expired or invalid */ public function actionPostLoginToken() { $this->assertApiScope('auth:login_token'); $this->assertRequiredApiInput('user_id'); $userId = $this->filter('user_id', 'uint'); /** @var \XF\Entity\User $user */ $user = $this->assertRecordExists('XF:User', $userId, 'api'); /** @var \XF\Entity\ApiLoginToken $loginToken */ $loginToken = $this->em()->create('XF:ApiLoginToken'); $loginToken->user_id = $user->user_id; $limitIp = $this->filter('limit_ip', 'str'); if ($limitIp) { $loginToken->limit_ip = $limitIp; } $loginToken->save(); $returnUrl = $this->filter('return_url', 'str'); $returnUrl = $returnUrl ? $this->request->convertToAbsoluteUri($returnUrl, true) : null; $remember = $this->filter('remember', 'bool', true); $publicRouter = $this->app->router('public'); return $this->apiResult([ 'login_token' => $loginToken->login_token, 'login_url' => $publicRouter->buildLink( 'canonical:login/api-token', null, ['token' => $loginToken->login_token, 'return_url' => $returnUrl, 'remember' => $remember ? 1 : 0] ), 'expiry_date' => $loginToken->expiry_date, ]); } }
Bu Açıklamanın Başa tutturulması lazım Teşekkürler Bilgilerin için..Yapılmayacak bir şey yok ama sisteme alışmak lazım. Yani bende bazen kendi mvc yapımla bir şeyler yapıyorum dökümantasyonunu vermesem bir framework olarak birinin çözmesi en az 1-2 yılını alır. Çok çok üst düzey kodlama yapanlara bakın xenforo.com'da hepsi birbirinden bir şeyler kırpar, yapamadıkları yerde xenforo yöneticilerinden yardım talep ederler. Bunlar normaldir. En zor işlemlerden bir tanesi bir başkasının yazdığı kodu çözmektir. Bu da azim ve çapa istemekte. Bu konuda ego yapılacak bir durum yok kardeşim, herkes bildiği kadarını anlatır bildiği kadarını yapar o yüzden fikir vermesi açısından neleri inceleyeceğinizi söylüyorum şunu da net söylim xenforo dökümantasyonuna bakarak bir şey öğrenmek gerçekten zor xenforo dosyalarını indirip XF klasörü içerisindekileri tek tek inceleyeceksiniz. Gerisi zaman kaybı.
Forum içeriğine ve tüm hizmetlerimize erişim sağlamak için foruma kayıt olmalı ya da giriş yapmalısınız. Foruma üye olmak tamamen ücretsizdir.
Bu sitenin çalışması için temel çerezleri ve deneyiminizi geliştirmek için isteğe bağlı çerezleri kullanıyoruz.