AuthController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace Apps\Controllers;
  3. use Cygnite\Common\Encrypt;
  4. use Cygnite\Common\Input\Input;
  5. use Cygnite\Common\SessionManager\Session;
  6. use Cygnite\Foundation\Application as App;
  7. use Application\Components\Authentication\Auth;
  8. use Cygnite\Mvc\Controller\AbstractBaseController;
  9. /**
  10. * This file is generated by Cygnite CLI
  11. * You may alter code to fit your needs
  12. */
  13. class AuthController extends AbstractBaseController
  14. {
  15. //protected $layout = 'layout.base';
  16. protected $templateEngine = false;
  17. private $auth;
  18. /**
  19. * Your constructor.
  20. *
  21. * @access public
  22. *
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. /*
  28. | User Model to authenticate user using
  29. | credentials
  30. */
  31. $this->auth = Auth::model('\Apps\Models\User');
  32. }
  33. /**
  34. * Default Action
  35. */
  36. public function indexAction()
  37. {
  38. }
  39. /**
  40. * Authenticate user and login into the system
  41. *
  42. */
  43. public function checkAction()
  44. {
  45. $input = Input::make();
  46. $post = $input->json();
  47. $crypt = new Encrypt();
  48. $credentials = array(
  49. 'email' => $post->email,
  50. 'password' => $crypt->encode($post->password)
  51. );
  52. if ($this->auth->verify($credentials)) {
  53. $this->auth->login();
  54. $userInfo = $this->auth->userInfo();
  55. echo json_encode(
  56. array('success' => true, 'flash' => 'Logged In Successfully!!', 'name' => $userInfo['name'])
  57. );
  58. } else {
  59. echo json_encode(array('success' => false, 'flash' => 'Invalid username or password', 'name' => ''));
  60. }
  61. }
  62. /**
  63. * Display specific information into the form to edit.
  64. *
  65. */
  66. public function logoutAction()
  67. {
  68. $this->auth->logout(false);
  69. echo json_encode(array('success' => true, 'flash' => 'Successfully Logged Out!'));
  70. }
  71. }//End of your LoginController