PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/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
23@import "CPNotificationCenter.j"
24@import "CPObject.j"
25@import "CPString.j"
26
27@typedef CPUserSessionStatus
28CPUserSessionUndeterminedStatus = 0;
29CPUserSessionLoggedInStatus     = 1;
30CPUserSessionLoggedOutStatus    = 2;
31
32CPUserSessionManagerStatusDidChangeNotification         = @"CPUserSessionManagerStatusDidChangeNotification";
33CPUserSessionManagerUserIdentifierDidChangeNotification = @"CPUserSessionManagerUserIdentifierDidChangeNotification";
34
35var CPDefaultUserSessionManager = nil;
36
37@implementation CPUserSessionManager : CPObject
38{
39    CPUserSessionStatus _status;
40
41    CPString            _userIdentifier;
42}
43
44+ (id)defaultManager
45{
46    if (!CPDefaultUserSessionManager)
47        CPDefaultUserSessionManager = [[CPUserSessionManager alloc] init];
48
49    return CPDefaultUserSessionManager;
50}
51
52- (id)init
53{
54    self = [super init];
55
56    if (self)
57        _status = CPUserSessionUndeterminedStatus;
58
59    return self;
60}
61
62- (CPUserSessionStatus)status
63{
64    return _status;
65}
66
67- (void)setStatus:(CPUserSessionStatus)aStatus
68{
69    if (_status == aStatus)
70        return;
71
72    _status = aStatus;
73
74    [[CPNotificationCenter defaultCenter]
75        postNotificationName:CPUserSessionManagerStatusDidChangeNotification
76                      object:self];
77
78    if (_status != CPUserSessionLoggedInStatus)
79        [self setUserIdentifier:nil];
80}
81
82- (CPString)userIdentifier
83{
84    return _userIdentifier;
85}
86
87- (void)setUserIdentifier:(CPString)anIdentifier
88{
89    if (_userIdentifier == anIdentifier)
90        return;
91
92    _userIdentifier = anIdentifier;
93
94    [[CPNotificationCenter defaultCenter]
95        postNotificationName:CPUserSessionManagerUserIdentifierDidChangeNotification
96                      object:self];
97}
98
99@end