/Foundation/CPUserSessionManager.j

http://github.com/cacaodev/cappuccino · Unknown · 99 lines · 78 code · 21 blank · 0 comment · 0 complexity · f18e1d4edc834b600eeccb5c85179e75 MD5 · raw file

  1. /*
  2. * CPUserSessionManager.j
  3. * Foundation
  4. *
  5. * Created by Francisco Tolmasky.
  6. * Copyright 2008, 280 North, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. @import "CPNotificationCenter.j"
  23. @import "CPObject.j"
  24. @import "CPString.j"
  25. @typedef CPUserSessionStatus
  26. CPUserSessionUndeterminedStatus = 0;
  27. CPUserSessionLoggedInStatus = 1;
  28. CPUserSessionLoggedOutStatus = 2;
  29. CPUserSessionManagerStatusDidChangeNotification = @"CPUserSessionManagerStatusDidChangeNotification";
  30. CPUserSessionManagerUserIdentifierDidChangeNotification = @"CPUserSessionManagerUserIdentifierDidChangeNotification";
  31. var CPDefaultUserSessionManager = nil;
  32. @implementation CPUserSessionManager : CPObject
  33. {
  34. CPUserSessionStatus _status;
  35. CPString _userIdentifier;
  36. }
  37. + (id)defaultManager
  38. {
  39. if (!CPDefaultUserSessionManager)
  40. CPDefaultUserSessionManager = [[CPUserSessionManager alloc] init];
  41. return CPDefaultUserSessionManager;
  42. }
  43. - (id)init
  44. {
  45. self = [super init];
  46. if (self)
  47. _status = CPUserSessionUndeterminedStatus;
  48. return self;
  49. }
  50. - (CPUserSessionStatus)status
  51. {
  52. return _status;
  53. }
  54. - (void)setStatus:(CPUserSessionStatus)aStatus
  55. {
  56. if (_status == aStatus)
  57. return;
  58. _status = aStatus;
  59. [[CPNotificationCenter defaultCenter]
  60. postNotificationName:CPUserSessionManagerStatusDidChangeNotification
  61. object:self];
  62. if (_status != CPUserSessionLoggedInStatus)
  63. [self setUserIdentifier:nil];
  64. }
  65. - (CPString)userIdentifier
  66. {
  67. return _userIdentifier;
  68. }
  69. - (void)setUserIdentifier:(CPString)anIdentifier
  70. {
  71. if (_userIdentifier == anIdentifier)
  72. return;
  73. _userIdentifier = anIdentifier;
  74. [[CPNotificationCenter defaultCenter]
  75. postNotificationName:CPUserSessionManagerUserIdentifierDidChangeNotification
  76. object:self];
  77. }
  78. @end