$this->getConfig()->get('wargamingauth_api_key')
das funktioniert leider nicht
verwendete ilch Version: 2.x
betroffene Homepage: www.r1sing.de
Hier kann eine Notiz zum Merk-Eintrag hinzugefügt werden (optional)
| Geschlossen | ||

$this->getConfig()->get('wargamingauth_api_key')



$this->getConfig()->set('checkoutbasic_contact', $this->getRequest()->getPost('checkoutContact'));
$this->getConfig()->get('checkoutbasic_contact')





public function callbackAction()
{
var_dump($_POST,$_GET);
if (isset($_GET['status']) && isset($_GET['access_token']) && isset($_GET['nickname']) && isset($_GET['account_id']) && isset($_GET['expires_at']))
{
$data = $this->get_auth_data();
if($data['status'] == 'ok')
{
//echo '<pre>';
//print_r($data);
//echo '</pre>';
$access_token = $data['data']['access_token'];
$expires_at = $data['data']['expires_at'];
$account_id = $data['data']['account_id'];
//echo 'User id <b>'.$account_id.'</b><br />Token <b>'.$access_token.'</b>, is activated and expire <b>'.date("d.m.Y H:i:s",$expires_at).'</b>';
}
else
{
exit('access_token not confirmed');
}
}
else
{
$error_code = 500;
if (preg_match('/^[0-9]+$/u', $_GET['code']))
{
$error_code = $_GET['code'];
}
exit("Error!. Error: $error_code");
}
$PLAYER_INFO_URL = 'https://api.worldoftanks.eu/wot/account/info/?application_id='.$this->getConfig()->get('wargamingauth_api_key').'&account_id='.$account_id.'';
echo '<br>';
//var_dump($PLAYER_INFO_URL);
$get_data_player = file_get_contents($PLAYER_INFO_URL);
$json_player_decode = json_decode($get_data_player , true);
//print_r ($json_player_decode);
$clan_id = $json_player_decode['data'][$account_id]['clan_id'];
$nickname = $json_player_decode['data'][$account_id]['nickname'];
//echo '<br>';
//echo 'Nickname = '.$nickname.' and ClanID = '.$clan_id.'';
echo '<br>';
$CLAN_MEMBER_INFO_URL = 'https://api.worldoftanks.eu/wgn/clans/membersinfo/?application_id='.$this->getConfig()->get('wargamingauth_api_key').'&account_id='.$account_id.'';
$get_clan_member = file_get_contents($CLAN_MEMBER_INFO_URL);
$json_clan_member_decode = json_decode($get_clan_member , true);
$account_name = $json_clan_member_decode['data'][$account_id]['account_name'];
$role = $json_clan_member_decode['data'][$account_id]['role'];
$role_i18n = $json_clan_member_decode['data'][$account_id]['role_i18n'];
$clanname = $json_clan_member_decode['data'][$account_id]['clan']['name'];
$clantag = $json_clan_member_decode['data'][$account_id]['clan']['tag'];
/**
echo '
<div class="content">
<img source="'.$clanlogo.'">
<br>
Spielername = '.$account_name.'
<br>
Position = '.$role_i18n.'
<br>
Clanname = '.$clanname.'
<br>
ClanTag = '.$clantag.'
</div>
';
**/
$auth = new WargamingOAuth(
$this->getConfig()->get('wargamingauth_api_key')
);
try {
$wargamingUser = $auth->getResult();
$authProvider = new AuthProvider();
$existingLink = $authProvider->providerAccountIsLinked('wargaming', $wargamingUser[$account_id]);
if (loggedIn()) {
if ($authProvider->hasProviderLinked('wargaming', currentUser()->getId())) {
$this->dbLog()->info(
"User " . currentUser()->getName() . " had provider already linked.",
[
'userId' => currentUser()->getId(),
'userName' => currentUser()->getName(),
'wargamingAccount' => $wargamingUser
]
);
$this->addMessage('providerAlreadyLinked', 'danger');
$this->redirect(['module' => 'user', 'controller' => 'panel', 'action' => 'providers']);
}
if ($existingLink === true) {
$this->dbLog()->info(
"User " . currentUser()->getName() . " tried to link an already linked twitter account.",
[
'userId' => currentUser()->getId(),
'userName' => currentUser()->getName(),
'wargamingAccount' => $wargamingUser
]
);
$this->addMessage('accountAlreadyLinkedToDifferentUser', 'danger');
$this->redirect(['module' => 'user', 'controller' => 'panel', 'action' => 'providers']);
}
$authProviderUser = (new AuthProviderUser())
->setIdentifier($wargamingUser[$account_id])
->setProvider('wargaming')
->setOauthToken($wargamingUser[$access_token])
->setScreenName($wargamingUser[$account_name])
->setUserId(currentUser()->getId());
$link = $authProvider->linkProviderWithUser($authProviderUser);
if ($link === true) {
$this->dbLog()->info(
"User " . currentUser()->getName() . " has linked a Wargaming account.",
[
'userId' => currentUser()->getId(),
'userName' => currentUser()->getName(),
'wargamingAccount' => $wargamingUser
]
);
$this->addMessage('linkSuccess');
$this->redirect(['module' => 'user', 'controller' => 'panel', 'action' => 'providers']);
}
$this->dbLog()->error(
"User " . currentUser()->getName() . " could not link his twitter account.",
[
'userId' => currentUser()->getId(),
'userName' => currentUser()->getName(),
'wargamingAccount' => $wargamingUser
]
);
$this->addMessage('linkFailed', 'danger');
$this->redirect(['module' => 'user', 'controller' => 'panel', 'action' => 'providers']);
}
if ($existingLink === true) {
$userId = $authProvider->getUserIdByProvider('wargaming', $wargamingUser[$account_id]);
if (is_null($userId)) {
$this->addMessage('couldNotFindRequestedUser');
$this->redirect(['module' => 'user', 'controller' => 'login', 'action' => 'index']);
}
$_SESSION['user_id'] = $userId;
$this->addMessage('loginSuccess');
$this->redirect('/');
}
if ($existingLink === false && ! loggedIn() && ! $this->getConfig()->get('regist_accept')) {
$this->addMessage('wargamingauth.messages.registrationNotAllowed', 'danger');
$this->redirect(['module' => 'user', 'controller' => 'login', 'action' => 'index']);
}
array_dot_set($_SESSION, 'wargamingauth.login', $wargamingUser);
array_dot_set($_SESSION, 'wargamingauth.login.expires', strtotime('+5 minutes'));
$this->redirect(['action' => 'regist']);
} catch (\Exception $e) {
$this->addMessage('wargamingauth.authenticationfailure', 'danger');
if (loggedIn()) {
$this->redirect(['module' => 'user', 'controller' => 'panel', 'action' => 'providers']);
} else {
$this->redirect(['module' => 'user', 'controller' => 'login', 'action' => 'index']);
}
}
return $access_token;
return $account_id;
return $account_name;
return $clantag;
return $role;
return $expires_at;
}
$access_token; $account_id; $account_name; $clantag; $role; $expires_at;




<?php
namespace Modules\wargamingauth\Controllers;
use Ilch\Controller\Frontend;
use Modules\wargamingauth\Libs\WargamingOAuth;
use Modules\wargamingauth\Mappers\DbLog;
use Modules\User\Mappers\AuthProvider;
use Modules\User\Mappers\User as UserMapper;
use Modules\User\Mappers\Group;
use Modules\User\Models\AuthProviderUser;
use Modules\User\Models\User;
use Modules\User\Service\Password as PasswordService;
use Ilch\Validation;
class Auth extends Frontend
{
/**
* @var DbLog instance
*/
protected $dbLog;
public function call($params = array())
{
if (empty($params)) {
exit('Wrong params');
}
return $context = stream_context_create(
array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query($params)
)
)
);
}
/**
* Renders the register form.
*/
public function registAction()
{
if (! array_dot($_SESSION, 'wargamingauth.login') || array_dot($_SESSION, 'wargamingauth.login.expires') < time()) {
$this->addMessage('registExpired', 'danger');
$this->redirect(['module' => 'user', 'controller' => 'regist', 'action' => 'index']);
}
$oauth = array_dot($_SESSION, 'wargamingauth.login');
$this->getView()->set('rules', $this->getConfig()->get('regist_rules'));
$this->getView()->set('user', $oauth);
}
/**
* Saves the new user to the database.
*/
public function saveAction()
{
if (!$this->getRequest()->isPost()) {
$this->addMessage('badRequest');
$this->redirect('/');
}
if (! array_dot($_SESSION, 'wargamingauth.login') || array_dot($_SESSION, 'wargamingauth.login.expires') < time()) {
$this->addMessage('badRequest');
$this->redirect(['module' => 'user', 'controller' => 'login', 'action' => 'index']);
}
$input = [
'email' => trim($this->getRequest()->getPost('email')),
];
$validation = Validation::create($input, [
'email' => 'required|email|unique:users,email',
]);
if ($validation->isValid()) {
// register user
$registMapper = new UserMapper();
$groupMapper = new Group();
$userGroup = $groupMapper->getGroupByName($this->callbackAction(clantag));
var_dump($userGroup);
die();
$currentDate = new \Ilch\Date();
$user = (new User())
->setName($this->callbackAction(account_name))
->setPassword((new PasswordService())->hash(PasswordService::generateSecurePassword(32)))
->setEmail($input['email'])
->setDateCreated($currentDate->format('Y-m-d H:i:s', true))
->addGroup($userGroup)
->setDateConfirmed($currentDate->format('Y-m-d H:i:s', true));
$userId = $registMapper->save($user);
$oauth = array_dot($_SESSION, 'wargamingauth.login');
$authProviderUser = (new AuthProviderUser())
->setIdentifier($oauth[self::$account_id])
->setProvider('wargaming')
->setOauthToken($oauth[self::$access_token])
->setScreenName($oauth[self::$account_name])
->setUserId($userId);
$link = (new AuthProvider())->linkProviderWithUser($authProviderUser);
if ($link === true) {
$_SESSION['user_id'] = $userId;
$this->addMessage('wargamingauth.linksuccess');
$this->redirect(['module' => 'user', 'controller' => 'panel', 'action' => 'index']);
}
$this->addMessage('wargamingauth.linkfailed', 'danger');
$this->redirect('/');
}
$this->addMessage($validation->getErrorBag()->getErrorMessages(), 'danger', true);
$this->redirect()
->withInput()
->withErrors($validation->getErrorBag())
->to(['action' => 'regist']);
}
public function unlinkAction()
{
if (loggedIn()) {
if ($this->getRequest()->isPost()) {
$authProvider = new AuthProvider();
$res = $authProvider->unlinkUser('wargaming', currentUser()->getId());
if ($res > 0) {
$this->addMessage('wargamingauth.unlinkedsuccessfully');
$this->redirect(['module' => 'user', 'controller' => 'panel', 'action' => 'providers']);
}
$this->addMessage('wargamingauth.couldnotunlink', 'danger');
$this->redirect('/');
}
$this->addMessage('wargamingauth.badrequest', 'danger');
$this->redirect('/');
}
$this->addMessage('wargamingauth.notauthenticated', 'danger');
$this->redirect('/');
}
const AUTH_URL = 'https://api.worldoftanks.eu/wot/auth/login/';
const PROLONGATE = 'https://api.worldoftanks.eu/wot/auth/prolongate/';
const ACCESS_TOKEN_URL = 'https://api.worldoftanks.eu/wot/auth/login/?application_id={application_id}&expires_at={expires_at}&redirect_uri={redirect_uri}&nofollow={nofollow}&display={display}';
/**
* Initialize authentication.
*/
function indexAction()
{
$callbackUrl = $this->getLayout()->getUrl([
'module' => 'wargamingauth',
'controller' => 'auth',
'action' => 'callback',
]);
$params = array(
'application_id' => $this->getConfig()->get('wargamingauth_api_key'),
'redirect_uri' => $callbackUrl,
'display' => popup,
'nofollow'=> 1
);
if (empty($_GET['status'])){
$openId = self::AUTH_URL. '?' .http_build_query($params, '', '&');
//var_dump($openId);
//die();
$redirect = (json_decode(file_get_contents($openId)))->data->location;
$this->redirect($redirect);
}
}
function get_auth_data()
{
if($_GET['status'] != 'ok')
{
$error_code = 500;
if (preg_match('/^[0-9]+$/u', $_GET['code']))
{
$error_code = $_GET['code'];
}
exit("Authorisation Error. Error code: $error_code");
}
elseif($_GET['expires_at'] < time())
{
exit("Authorisation Error. Access_token expired.");
}
else
{
//confirm the validity of the parameters
$json = file_get_contents(self::PROLONGATE, false, $this->call(array(
'expires_at' => $_GET['expires_at'],
'access_token' => $_GET['access_token'],
'application_id' => $this->getConfig()->get('wargamingauth_api_key')
)));
return json_decode($json, true);
}
}
/**
* Callback action.
*/
public function callbackAction()
{
//var_dump($_POST,$_GET);
if (isset($_GET['status']) && isset($_GET['access_token']) && isset($_GET['nickname']) && isset($_GET['account_id']) && isset($_GET['expires_at']))
{
$data = $this->get_auth_data();
if($data['status'] == 'ok')
{
//echo '<pre>';
//print_r($data);
//echo '</pre>';
$access_token = $data['data']['access_token'];
$expires_at = $data['data']['expires_at'];
$account_id = $data['data']['account_id'];
//echo 'User id <b>'.$account_id.'</b><br />Token <b>'.$access_token.'</b>, is activated and expire <b>'.date("d.m.Y H:i:s",$expires_at).'</b>';
}
else
{
exit('access_token not confirmed');
}
}
else
{
$error_code = 500;
if (preg_match('/^[0-9]+$/u', $_GET['code']))
{
$error_code = $_GET['code'];
}
exit("Error!. Error: $error_code");
}
$PLAYER_INFO_URL = 'https://api.worldoftanks.eu/wot/account/info/?application_id='.$this->getConfig()->get('wargamingauth_api_key').'&account_id='.$account_id.'';
echo '<br>';
//var_dump($PLAYER_INFO_URL);
$get_data_player = file_get_contents($PLAYER_INFO_URL);
$json_player_decode = json_decode($get_data_player , true);
//print_r ($json_player_decode);
$clan_id = $json_player_decode['data'][$account_id]['clan_id'];
$nickname = $json_player_decode['data'][$account_id]['nickname'];
//echo '<br>';
//echo 'Nickname = '.$nickname.' and ClanID = '.$clan_id.'';
echo '<br>';
$CLAN_MEMBER_INFO_URL = 'https://api.worldoftanks.eu/wgn/clans/membersinfo/?application_id='.$this->getConfig()->get('wargamingauth_api_key').'&account_id='.$account_id.'';
$get_clan_member = file_get_contents($CLAN_MEMBER_INFO_URL);
$json_clan_member_decode = json_decode($get_clan_member , true);
$account_name = $json_clan_member_decode['data'][$account_id]['account_name'];
$role = $json_clan_member_decode['data'][$account_id]['role'];
$role_i18n = $json_clan_member_decode['data'][$account_id]['role_i18n'];
$clanname = $json_clan_member_decode['data'][$account_id]['clan']['name'];
$clantag = $json_clan_member_decode['data'][$account_id]['clan']['tag'];
/**
echo '
<div class="content">
<img source="'.$clanlogo.'">
<br>
Spielername = '.$account_name.'
<br>
Position = '.$role_i18n.'
<br>
Clanname = '.$clanname.'
<br>
ClanTag = '.$clantag.'
</div>
';
**/
$auth = new WargamingOAuth(
$this->getConfig()->get('wargamingauth_api_key')
);
try {
$wargamingUser = $auth->getResult();
$authProvider = new AuthProvider();
$existingLink = $authProvider->providerAccountIsLinked('wargaming', $wargamingUser[$account_id]);
if (loggedIn()) {
if ($authProvider->hasProviderLinked('wargaming', currentUser()->getId())) {
$this->dbLog()->info(
"User " . currentUser()->getName() . " had provider already linked.",
[
'userId' => currentUser()->getId(),
'userName' => currentUser()->getName(),
'wargamingAccount' => $wargamingUser
]
);
$this->addMessage('providerAlreadyLinked', 'danger');
$this->redirect(['module' => 'user', 'controller' => 'panel', 'action' => 'providers']);
}
if ($existingLink === true) {
$this->dbLog()->info(
"User " . currentUser()->getName() . " tried to link an already linked twitter account.",
[
'userId' => currentUser()->getId(),
'userName' => currentUser()->getName(),
'wargamingAccount' => $wargamingUser
]
);
$this->addMessage('accountAlreadyLinkedToDifferentUser', 'danger');
$this->redirect(['module' => 'user', 'controller' => 'panel', 'action' => 'providers']);
}
$authProviderUser = (new AuthProviderUser())
->setIdentifier($wargamingUser[$account_id])
->setProvider('wargaming')
->setOauthToken($wargamingUser[$access_token])
->setScreenName($wargamingUser[$account_name])
->setUserId(currentUser()->getId());
$link = $authProvider->linkProviderWithUser($authProviderUser);
if ($link === true) {
$this->dbLog()->info(
"User " . currentUser()->getName() . " has linked a Wargaming account.",
[
'userId' => currentUser()->getId(),
'userName' => currentUser()->getName(),
'wargamingAccount' => $wargamingUser
]
);
$this->addMessage('linkSuccess');
$this->redirect(['module' => 'user', 'controller' => 'panel', 'action' => 'providers']);
}
$this->dbLog()->error(
"User " . currentUser()->getName() . " could not link his wargaming account.",
[
'userId' => currentUser()->getId(),
'userName' => currentUser()->getName(),
'wargamingAccount' => $wargamingUser
]
);
$this->addMessage('linkFailed', 'danger');
$this->redirect(['module' => 'user', 'controller' => 'panel', 'action' => 'providers']);
}
if ($existingLink === true) {
$userId = $authProvider->getUserIdByProvider('wargaming', $wargamingUser[$account_id]);
if (is_null($userId)) {
$this->addMessage('couldNotFindRequestedUser');
$this->redirect(['module' => 'user', 'controller' => 'login', 'action' => 'index']);
}
$_SESSION['user_id'] = $userId;
$this->addMessage('loginSuccess');
$this->redirect('/');
}
if ($existingLink === false && ! loggedIn() && ! $this->getConfig()->get('regist_accept')) {
$this->addMessage('wargamingauth.messages.registrationNotAllowed', 'danger');
$this->redirect(['module' => 'user', 'controller' => 'login', 'action' => 'index']);
}
array_dot_set($_SESSION, 'wargamingauth.login', $wargamingUser);
array_dot_set($_SESSION, 'wargamingauth.login.expires', strtotime('+5 minutes'));
$this->redirect(['action' => 'regist']);
} catch (\Exception $e) {
$this->addMessage('wargamingauth.authenticationfailure', 'danger');
if (loggedIn()) {
$this->redirect(['module' => 'user', 'controller' => 'panel', 'action' => 'providers']);
} else {
$this->redirect(['module' => 'user', 'controller' => 'login', 'action' => 'index']);
}
}
}
/**
* @return DbLog
*/
protected function dbLog()
{
if ($this->dbLog instanceof DbLog) {
return $this->dbLog;
}
return $this->dbLog = new DbLog();
}
}

| Geschlossen | ||
![]() |
Zurück zu Module und Modifikationen | |