ilch Forum » Ilch CMS 2.X » Module und Modifikationen » Arbeit an ein einem Modul und viele Frag

Geschlossen
  1. #1
    User Pic
    MonkeyOnKeyboard Moderator
    Registriert seit
    10.02.2014
    Beiträge
    437
    Beitragswertungen
    20 Beitragspunkte
    eine frage hab ich noch. wie kann ich in einer datei in ner libery ein elemt aus der datenbank aufrufen?



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



    das funktioniert leider nicht


    verwendete ilch Version: 2.x

    betroffene Homepage: www.r1sing.de
    0 Mitglieder finden den Beitrag gut.
  2. #2
    User Pic
    Siggi Hall Of Fame
    Registriert seit
    08.02.2007
    Beiträge
    6.558
    Beitragswertungen
    327 Beitragspunkte
    Öhm wie hast du es den in der Datenbank eingefügt bzw wo steht es?

    Eigentlich muss es durch eine Funktion im Mappers abgefragt und anschließend vom Controller an die View übergeben werden
    0 Mitglieder finden den Beitrag gut.
  3. #3
    User Pic
    MonkeyOnKeyboard Moderator
    Registriert seit
    10.02.2014
    Beiträge
    437
    Beitragswertungen
    20 Beitragspunkte
    ZitatZitat geschrieben von Siggi
    Öhm wie hast du es den in der Datenbank eingefügt bzw wo steht es?

    Eigentlich muss es durch eine Funktion im Mappers abgefragt und anschließend vom Controller an die View übergeben werden



    wargamingauth_api_key steht in der config drin. es wurde über ein admin modul eingefügt.

    NUn versuch ich es in eine Libery zu integrieren. nur mit dem befehl da geht es nicht bekomme da fehler
    0 Mitglieder finden den Beitrag gut.
  4. #4
    User Pic
    blackcoder Entwickler
    Registriert seit
    22.05.2014
    Beiträge
    2.278
    Beitragswertungen
    356 Beitragspunkte
    Habe deine PN gelesen und es ist unklar was du genau machst.
    Vielleicht hilft dir dieses Beispiel.

    Beispiel Kassen-Modul:

    Im Admincenter unter Module und dort das Kassen-Modul. Dieses Kassen-Modul hat Einstellungen. Für diese Einstellungen gibt es eine Settings-Action (settingsAction())im Index-Controller unter Admin.
    application/modules/checkoutbasic/controllers/admin/Index.php
    github.com/IlchCMS/Ilch-2.0/blob/v2.1.14/application/modules/checkoutbasic/controllers/admin/Index.php#L113

    Die "Oberfläche" (View) hierzu ist hier zu finden:
    application/modules/checkoutbasic/views/admin/index/settings.php
    github.com/IlchCMS/Ilch-2.0/blob/v2.1.14/application/modules/checkoutbasic/views/admin/index/settings.php

    Wenn also die Einstellungen dann gespeichert werden, kommt dies bei der Settings-Action an (settingsAction()).

    Hier werden die Eingaben "entgegen genommen" und in der Datenbank gespeichert (Tabelle [prefix]_config):
    github.com/IlchCMS/Ilch-2.0/blob/v2.1.14/application/modules/checkoutbasic/controllers/admin/Index.php#L128
    $this->getConfig()->set('checkoutbasic_contact', $this->getRequest()->getPost('checkoutContact'));

    Hier wird der entsprechende Wert abgefragt:
    github.com/IlchCMS/Ilch-2.0/blob/v2.1.14/application/modules/checkoutbasic/controllers/admin/Index.php#L141
    $this->getConfig()->get('checkoutbasic_contact')


    So sehen die Einträge in phpMyAdmin in der Tabelle [prefix]_config dann aus:
    0 Mitglieder finden den Beitrag gut.
  5. #5
    User Pic
    MonkeyOnKeyboard Moderator
    Registriert seit
    10.02.2014
    Beiträge
    437
    Beitragswertungen
    20 Beitragspunkte
    Also hab mir das nun angeschaut. Das Problem. ich arbeite in einer Liberybibliotek . Da kann ich kein extend machen in der classe.

    gibt es ein befehl so auf die config Tabelle oder die funktion getconfig() zuzugreifen. Diese wird ja im Base controler erstellt und and Frontend weitergegeben.
    0 Mitglieder finden den Beitrag gut.
  6. #6
    User Pic
    blackcoder Entwickler
    Registriert seit
    22.05.2014
    Beiträge
    2.278
    Beitragswertungen
    356 Beitragspunkte
    Keine Ahnung was mit Liberybibliotek gemeint ist. nachdenken
    0 Mitglieder finden den Beitrag gut.
  7. #7
    User Pic
    MonkeyOnKeyboard Moderator
    Registriert seit
    10.02.2014
    Beiträge
    437
    Beitragswertungen
    20 Beitragspunkte
    ZitatZitat geschrieben von blackcoder
    Keine Ahnung was mit Liberybibliotek gemeint ist. nachdenken


    Eine Bibliothek für ein modul wo verschiedene funktionen drin sind. die in dem medul benötigt werden.

    die class dadrin soll aber nicht extendet werden.

    ich möchte in dieser php datei. einfach über eine funktion auf die config tabelle von ilch zugreifen.
    da ich über den im modul hinterlegten admin zugang ein api schlüssel in die config tabelle gespeichert habe.
    0 Mitglieder finden den Beitrag gut.
  8. #8
    User Pic
    Siggi Hall Of Fame
    Registriert seit
    08.02.2007
    Beiträge
    6.558
    Beitragswertungen
    327 Beitragspunkte
    Ich denke dafür muss du schon ein wenig Code mehr offen legen damit wir wissen wie du was meinst oder was genau du mit einer Bibliothek meinst.

    Eine PHP Bibliothek von ein anderes Game/Programm?
    0 Mitglieder finden den Beitrag gut.
  9. #9
    User Pic
    MonkeyOnKeyboard Moderator
    Registriert seit
    10.02.2014
    Beiträge
    437
    Beitragswertungen
    20 Beitragspunkte
    Das eine hat sich erledigt. ich habe das wichtigste nun im eigentlichen controller drin. so dass ich die lib nicht mehr brauche.


    nun mal eine dumme frage.

    ich habe mehere public functions. möchte aus einer fuction variablen in eine andere übergeben. wie mach ich das.

    Beispiel.


    
    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;
            
        }



    nun brauche ich die variablen (wehrte) in einer anderen funktion in der selben datei. wi emach ich das.

    die variablen lauten

    
    $access_token;
    $account_id;
    $account_name;
    $clantag;
    $role;
    $expires_at;
    0 Mitglieder finden den Beitrag gut.
  10. #10
    User Pic
    Siggi Hall Of Fame
    Registriert seit
    08.02.2007
    Beiträge
    6.558
    Beitragswertungen
    327 Beitragspunkte
    Du musst die Funktion entsprechend schreiben aber innerhalb eines Controllers kannst du andere Funktionen mit $this->funktionsname(Parameter); ansprechen
    0 Mitglieder finden den Beitrag gut.
  11. #11
    User Pic
    MonkeyOnKeyboard Moderator
    Registriert seit
    10.02.2014
    Beiträge
    437
    Beitragswertungen
    20 Beitragspunkte
    ZitatZitat geschrieben von Siggi
    Du musst die Funktion entsprechend schreiben aber innerhalb eines Controllers kannst du andere Funktionen mit $this->funktionsname(Parameter); ansprechen


    ok. nur das ich die variablen ja in dieser funktion über get erhalte. in der anderen funktion, die erst später ausgeführt wird. zwischenzeitlich kommt eine neue seite. die eingabemaske für emailadresse. erst wenn diese abgeschickt wird. kommt wieder der aufruf der anderen funktion.

    ich arbeite gerade an nem api login.
    und möchte nicht alle funktionen hier aus schutz gründen offen legen.
    0 Mitglieder finden den Beitrag gut.
  12. #12
    User Pic
    blackcoder Entwickler
    Registriert seit
    22.05.2014
    Beiträge
    2.278
    Beitragswertungen
    356 Beitragspunkte
    Dann kann man dir dort nicht wirklich helfen.

    Wenn die "Sicherheit" deiner API vermeintlich davon abhängt, dass niemand den Quellcode kennt, machst du etwas falsch.
    0 Mitglieder finden den Beitrag gut.
  13. #13
    User Pic
    MonkeyOnKeyboard Moderator
    Registriert seit
    10.02.2014
    Beiträge
    437
    Beitragswertungen
    20 Beitragspunkte
    ZitatZitat geschrieben von blackcoder
    Dann kann man dir dort nicht wirklich helfen.

    Wenn die "Sicherheit" deiner API vermeintlich davon abhängt, dass niemand den Quellcode kennt, machst du etwas falsch.


    ich geb euch hier mal den Quellcode des controllers

    <?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();
        }
    }



    EDIT:

    Gibt es eine möglichkeit in der funktion die whrte auch gleich in eine tabelle. die ich beim installieren des moduls angelegtt habe zu speichern?

    wenn ja wie..


    Zuletzt modifiziert von magicmarkus am 12.10.2018 - 19:02:23
    0 Mitglieder finden den Beitrag gut.
  14. #14
    User Pic
    MonkeyOnKeyboard Moderator
    Registriert seit
    10.02.2014
    Beiträge
    437
    Beitragswertungen
    20 Beitragspunkte
    Thema kann geschlossen werden. da das Problem soweit gelöst ist.
    0 Mitglieder finden den Beitrag gut.
Geschlossen

Zurück zu Module und Modifikationen

Optionen: Bei einer Antwort zu diesem Thema eine eMail erhalten