Wat heb jij vandaag geprogrammeerd? 2.0

Gestart doorNielsba792 reacties10.961 weergaven

793 berichten · pagina 7 van 53

Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Post extends Auth

^ dat klinkt niet correct
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Raoul schreef:
Post extends Auth

^ dat klinkt niet correct
ja naja...

$auth = new Auth();

Dan maar dit werkt ook prima.
0
Berichten
13.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dylan schreef:
Eerdere citaten tonen
Raoul schreef:
Post extends Auth
^ dat klinkt niet correct

ja naja...

$auth = new Auth();

Dan maar dit werkt ook prima.
Heh. Je gebruikt die Auth class toch statisch? Waar heb je die [c]$auth[/c] dan voor nodig?
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Sjoerd schreef:
Eerdere citaten tonen
Dylan schreef:
Eerdere citaten tonen
Raoul schreef:
Post extends Auth
^ dat klinkt niet correct

ja naja...

$auth = new Auth();

Dan maar dit werkt ook prima.
Heh. Je gebruikt die Auth class toch statisch? Waar heb je die [c]$auth[/c] dan voor nodig?
Auth is niet static

toevoeging op 20 juli 2015, 20:59:33:
Het is samen 1 object zeg maar (de functies in Auth zijn wel protected)

Weet niet of dit totaal verkeerd is maar ik zie het probleem niet.

toevoeging op 20 juli 2015, 21:07:06:

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]/*==========/
    One2xs Auth
/==========*/[/COLOR]

namespace One2xs[COLOR= #007700];[/COLOR]

abstract [URL="http://www.php.net/class"]class[/URL] Auth extends Request [COLOR= #007700]{[/COLOR]

  [URL="http://www.php.net/protected"]protected[/URL] [COLOR= #0000BB]$csrfToken[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700];[/COLOR]
  [URL="http://www.php.net/protected"]protected[/URL] [COLOR= #007700]function[/COLOR] login[COLOR= #007700]([/COLOR][COLOR= #0000BB]$username[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$password[/COLOR][COLOR= #007700]) {[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/strlen"]strlen[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$username[/COLOR][COLOR= #007700]) ==[/COLOR] [COLOR= #0000BB]0[/COLOR] [COLOR= #007700]||[/COLOR] [URL="http://www.php.net/strlen"]strlen[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$password[/COLOR][COLOR= #007700]) ==[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]) {[/COLOR]
      throw [COLOR= #007700]new[/COLOR] Exception[COLOR= #007700]([/COLOR][COLOR= #DD0000]"Username and/or password is invalid."[/COLOR][COLOR= #007700]);[/COLOR]
      [URL="http://www.php.net/return"]return[/URL][COLOR= #007700];
    }[/COLOR]

    [COLOR= #0000BB]$request[/COLOR] [COLOR= #007700]=[/COLOR] Request[COLOR= #007700]::[/COLOR]request[COLOR= #007700]([/COLOR][URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR]
      CURLOPT_URL             [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]"http://www.one2xs.com/login.php"[/COLOR][COLOR= #007700],[/COLOR]
      CURLOPT_POST            [COLOR= #007700]=>[/COLOR] true[COLOR= #007700],[/COLOR]
      CURLOPT_POSTFIELDS      [COLOR= #007700]=>[/COLOR] http_build_query[COLOR= #007700]([/COLOR][URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR]
            [COLOR= #DD0000]"gebruikersnaam"[/COLOR]    [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]$username[/COLOR][COLOR= #007700],[/COLOR]
            [COLOR= #DD0000]"wachtwoord"[/COLOR]        [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]$password[/COLOR]
      [COLOR= #007700]))
    ));[/COLOR]

    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]( ([/COLOR]boolean[COLOR= #007700])[/COLOR] [URL="http://www.php.net/preg_match"]preg_match[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"/Je bent ingelogd als "[/COLOR][COLOR= #007700].[/COLOR] [COLOR= #0000BB]$username[/COLOR] [COLOR= #007700].[/COLOR][COLOR= #DD0000]"/"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$request[/COLOR][COLOR= #007700]) ===[/COLOR] true[COLOR= #007700]) {[/COLOR]
      [URL="http://www.php.net/preg_match"]preg_match[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]/<a href="http://www.one2xs.com/loguit?c=(.+)" title="Uitloggen">Uitloggen</a>/[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$request[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$token[/COLOR][COLOR= #007700]);[/COLOR]
      [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]csrfToken [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$token[/COLOR][COLOR= #007700][[/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700]];[/COLOR]

      [URL="http://www.php.net/return"]return[/URL] true[COLOR= #007700];
    }[/COLOR]

    [URL="http://www.php.net/return"]return[/URL] false[COLOR= #007700];
  }[/COLOR]

  [URL="http://www.php.net/protected"]protected[/URL] [COLOR= #007700]function[/COLOR] logout[COLOR= #007700]() {[/COLOR]
    [COLOR= #0000BB]$request[/COLOR] [COLOR= #007700]=[/COLOR] Request[COLOR= #007700]::[/COLOR]request[COLOR= #007700]([/COLOR][URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR]
      CURLOPT_URL [COLOR= #007700]=>[/COLOR] [COLOR= #DD0000]"http://www.one2xs.com/loguit?c="[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$this[/COLOR][COLOR= #007700]->[/COLOR]csrfToken
    [COLOR= #007700]));
  }
}[/COLOR]
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
je dient de auth class te injecteren (niet de extenden) in de post class.

ook, Post dient PostRequest te heten.

zoiets:

[COLOR= #0000BB]<?php
  $auth[/COLOR] [COLOR= #007700]= new[/COLOR] Authentication[COLOR= #007700]([/COLOR][COLOR= #DD0000]Raoul[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]Hoi[/COLOR][COLOR= #007700]);[/COLOR]

  try [COLOR= #007700]{[/COLOR]
    [COLOR= #0000BB]$auth[/COLOR][COLOR= #007700]->[/COLOR]login[COLOR= #007700]();
  }[/COLOR] catch [COLOR= #007700]([/COLOR]AuthException [COLOR= #0000BB]$e[/COLOR][COLOR= #007700]) {[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Kon niet aanmelden![/COLOR][COLOR= #007700];
  }[/COLOR]

  [COLOR= #0000BB]$postRequest[/COLOR] [COLOR= #007700]= new[/COLOR] PostRequest[COLOR= #007700]([/COLOR][COLOR= #0000BB]$auth[/COLOR][COLOR= #007700]);[/COLOR]
  [COLOR= #0000BB]$post[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$postRequest[/COLOR][COLOR= #007700]->[/COLOR]execute[COLOR= #007700]();[/COLOR]

  [COLOR= #FF8000]// $post->getUser()
  // $post->getMessage()[/COLOR]

  [COLOR= #0000BB]$auth[/COLOR][COLOR= #007700]->[/COLOR]logout[COLOR= #007700]();[/COLOR]
?>


en zo zie je, door dependency injection te gebruiken wordt je hele systeem 10x netter.
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
X
Raoul schreef:
je dient de auth class te injecteren (niet de extenden) in de post class.

ook, Post dient PostRequest te heten.

zoiets:

[COLOR= #0000BB]<?php
  $auth[/COLOR] [COLOR= #007700]= new[/COLOR] Authentication[COLOR= #007700]([/COLOR][COLOR= #DD0000]Raoul[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]Hoi[/COLOR][COLOR= #007700]);[/COLOR]

  try [COLOR= #007700]{[/COLOR]
    [COLOR= #0000BB]$auth[/COLOR][COLOR= #007700]->[/COLOR]login[COLOR= #007700]();
  }[/COLOR] catch [COLOR= #007700]([/COLOR]AuthException [COLOR= #0000BB]$e[/COLOR][COLOR= #007700]) {[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Kon niet aanmelden![/COLOR][COLOR= #007700];
  }[/COLOR]

  [COLOR= #0000BB]$postRequest[/COLOR] [COLOR= #007700]= new[/COLOR] PostRequest[COLOR= #007700]([/COLOR][COLOR= #0000BB]$auth[/COLOR][COLOR= #007700]);[/COLOR]
  [COLOR= #0000BB]$post[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$postRequest[/COLOR][COLOR= #007700]->[/COLOR]execute[COLOR= #007700]();[/COLOR]

  [COLOR= #FF8000]// $post->getUser()
  // $post->getMessage()[/COLOR]

  [COLOR= #0000BB]$auth[/COLOR][COLOR= #007700]->[/COLOR]logout[COLOR= #007700]();[/COLOR]
?>
en zo zie je, door dependency injection te gebruiken wordt je hele systeem 10x netter.

Zo dan..

Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42


/*==========/
One2xs Auth
/==========*/


namespace One2xs;

class Auth {

public $csrfToken = "";
public function login($username, $password) {
if(strlen($username) == 0 || strlen($password) == 0) {
throw new Exception("Username and/or password is invalid.");
return;
}

$this->request = new Request();

$login = $this->request->post(array(
CURLOPT_URL => "http://www.one2xs.com/login.php",
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query(array(
"gebruikersnaam" => $username,
"wachtwoord" => $password
))
));


if( (boolean) preg_match("/Je bent ingelogd als ". $username ."/", $login) === true) {
preg_match(/Uitloggen/, $login, $token);
$this->csrfToken = $token[1];

return true;
}


throw new Exception("Login at one2xs.com failed frown");
}


public function logout() {
$this->request->post(array(
CURLOPT_URL => "http://www.one2xs.com/loguit?c=" . $this->csrfToken
));
}
}


Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53


/*==========/
One2xs Post API
/==========*/


namespace One2xs;

final class PostRequest {
protected $auth;
public function __construct($config = array()) {
if(count($config) == 0 || !isset($config["loginDetails"]["username"])
|| !
isset($config["loginDetails"]["password"])
|| !
isset($config["postsInfo"])) {
throw new Exception("Config not valid");
return;
}


$this->auth = new Auth();
try {
$auth->login($config["loginDetails"]["username"],
$config["loginDetails"]["password"]);
}
catch(Exception $e) {
echo $e->getMessage();
return;
}


$this->config = $config;
}


public function execute() {
/*foreach($this->config["postsInfo"] as $post) {
var_dump($post);
}
Request::request(array(
CURLOPT_URL => "http://www.one2xs.com/includes/ajaxfuncties.php",
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query(array(
"s" => 20,
"t" => 59163,
"b" => "test",
"p" => 109,
"c" => $this->csrfToken,
"dubbelpost" => true,
"ding" => false
))
));*/

}

public function __destruct() {
// $this->auth->logout();
}

}
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
alsnog fout, je maakt een nieuwe auth instance aan in de post request class.

je moet de auth injecteren (= meegeven in een constructor) in de post request. Dit zodat je dezelfde auth instance kan hergebruiken overal.
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Raoul schreef:
alsnog fout, je maakt een nieuwe auth instance aan in de post request class.

je moet de auth injecteren (= meegeven in een constructor) in de post request. Dit zodat je dezelfde auth instance kan hergebruiken overal.
Dan kan ik toch beter de request class injecteren?
0
Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Bezig om in mijn vrije tijd een MMOCC game te maken en java te leren.

Ik probeerde tiles naast elkaar te zetten maar gaat niet echt lekker. Maar ik ben blij dat ik iets op mijn window heb gekregen.
Afbeelding
0
Berichten
518
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Shahiem schreef:
Bezig om in mijn vrije tijd een MMOCC game te maken en java te leren.

Ik probeerde tiles naast elkaar te zetten maar gaat niet echt lekker. Maar ik ben blij dat ik iets op mijn window heb gekregen.

Afbeelding
Als je de y iets verhoogt en je zorgt dat de transparantie werkt dan kan het er wel leuk uitzien denk ik yummie. Zou graag meer screens zien van je vooruitgang biggrin
0
Berichten
5.957
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Shahiem schreef:
Bezig om in mijn vrije tijd een MMOCC game te maken en java te leren.

Ik probeerde tiles naast elkaar te zetten maar gaat niet echt lekker. Maar ik ben blij dat ik iets op mijn window heb gekregen.

Afbeelding
Waarom gebruik je geen library die isometric rendered?
0
Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Alemaalte schreef:
Eerdere citaten tonen
Shahiem schreef:
Bezig om in mijn vrije tijd een MMOCC game te maken en java te leren.
Ik probeerde tiles naast elkaar te zetten maar gaat niet echt lekker. Maar ik ben blij dat ik iets op mijn window heb gekregen.

Afbeelding

Waarom gebruik je geen library die isometric rendered?
Ik gebruik op het moment LWJGL 3. Geen idee of die optie er gewoon in zit.
0
Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Afbeelding

Nog niet helemaal goed, maar transparantie is weg. Ik heb nu wel het probleem, dat als ik de windows sluit mijn computer heel langzaam gaat doen. Ik heb nog geen idee waar dat aan ligt.
0
Berichten
518
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Shahiem schreef:
Afbeelding

Nog niet helemaal goed, maar transparantie is weg. Ik heb nu wel het probleem, dat als ik de windows sluit mijn computer heel langzaam gaat doen. Ik heb nog geen idee waar dat aan ligt.
Kijk (eventueel met process hacker) naar het geheugen- en cpuverbruik van je programma.
0
Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Kitnkiller schreef:
Eerdere citaten tonen
Shahiem schreef:
Nog niet helemaal goed, maar transparantie is weg. Ik heb nu wel het probleem, dat als ik de windows sluit mijn computer heel langzaam gaat doen. Ik heb nog geen idee waar dat aan ligt.

Kijk (eventueel met process hacker) naar het geheugen- en cpuverbruik van je programma.
Thanks, ik zal even kijken smile
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren