Advertisement
Guest User

Untitled

a guest
Feb 26th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. if(trim($username) != "" and trim($password) != ""){
  2. // Load lexicons to show proper error messages
  3. if (!isset($modx->lexicon) || !is_object($modx->lexicon)) {
  4. $modx->getService('lexicon','modLexicon');
  5. }
  6. $modx->lexicon->load('login');
  7.  
  8. $loginContext= isset ($scriptProperties['login_context']) ? $scriptProperties['login_context'] :
  9. $modx->context->get('key');
  10.  
  11. $addContexts= isset ($scriptProperties['add_contexts']) && !empty($scriptProperties['add_contexts']) ? explode(',', $scriptProperties['add_contexts']) : array();
  12.  
  13. $mgrEvents = ($loginContext == 'mgr');
  14.  
  15. $givenPassword = $password;
  16.  
  17. /** @var $user modUser */
  18. $user= $modx->getObjectGraph('modUser', '{"Profile":{},"UserSettings":{}}', array ('modUser.username' => $username));
  19.  
  20. if (!$user) {
  21. $ru = $modx->invokeEvent("OnUserNotFound", array(
  22. 'user' => &$user,
  23. 'username' => $username,
  24. 'password' => $password,
  25. 'attributes' => array(
  26. 'loginContext' => $loginContext,
  27. )
  28. ));
  29.  
  30. if (!empty($ru)) {
  31. foreach ($ru as $obj) {
  32. if (is_object($obj) && $obj instanceof modUser) {
  33. $user = $obj;
  34. break;
  35. }
  36. }
  37. }
  38.  
  39. if (!is_object($user) || !($user instanceof modUser)) {
  40. echo json_encode(array("error" => "1", "code" => "5", "msg" => "Cannot find user"));
  41. exit;
  42. }
  43. }
  44.  
  45. if (!$user->get('active')) {
  46. echo json_encode(array("error" => "1", "code" => "4", "msg" => "Account not activated"));
  47. exit;
  48. }
  49.  
  50. if (!$user->passwordMatches($givenPassword)) {
  51. if (!array_key_exists('login_failed', $_SESSION)) {
  52. $_SESSION['login_failed'] = 0;
  53. }
  54. if ($_SESSION['login_failed'] == 0) {
  55. $flc = ((integer) $user->Profile->get('failedlogincount')) + 1;
  56. $user->Profile->set('failedlogincount', $flc);
  57. $user->Profile->save();
  58. $_SESSION['login_failed']++;
  59. } else {
  60. $_SESSION['login_failed'] = 0;
  61. }
  62. $app->response->setStatus(200);
  63. $app->response()->headers->set('Content-Type', 'applic ation/json');
  64. echo json_encode(array("error" => "1", "code" => "2", "msg" => "User not found"));
  65. exit;
  66. }
  67.  
  68. //$info['id'] = $row['id'];
  69. $info['id'] = $user->Profile->get('id');
  70. $info['fullname'] = $user->Profile->get('fullname');
  71. $info['email'] = $user->Profile->get('email');
  72.  
  73. echo json_encode(array("error" => "0", "code" => "3", "msg" => json_encode($info) ));
  74. }else{
  75. echo '{"error":"0","code" => "1", "msg":"Insufficiant data"}';
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement