Advertisement
Guest User

Untitled

a guest
Mar 17th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. <?php
  2. namespace MageplazaHelloWorldControllerIndex;
  3.  
  4. class Display extends MagentoFrameworkAppActionAction
  5. {
  6. protected $accountManagement;
  7. protected $session;
  8.  
  9. public function __construct(
  10. MagentoFrameworkAppActionContext $context,
  11. MagentoCustomerModelAccountManagement $acm,
  12. MagentoCustomerModelSession $ses
  13. )
  14. {
  15. $this->accountManagement = $acm;
  16. $this->session = $ses;
  17. return parent::__construct($context);
  18. }
  19.  
  20. public function execute()
  21. {
  22. //se la richiesta avviene in post
  23. if($_SERVER['REQUEST_METHOD'] == "POST") {
  24. //recupero i campi della richiesta
  25. $username = $_POST['username'];
  26. $password = $_POST['password'];
  27. //autentico l'utente
  28. try {
  29. $customer = $this->accountManagement->authenticate($username, $password);
  30. }
  31. catch(Exception $e) {
  32. echo "Credenziali errate";
  33. return;
  34. }
  35. //log in del cliente
  36. echo $customer->getId();
  37. $this->session->loginById($customer->getId());
  38. die;
  39. }
  40.  
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement