Mercurial > pub > Impl
comparison Lib/ObjectStore/CDBI/Users.pm @ 0:03e58a454b20
Создан репозитарий
author | Sergey |
---|---|
date | Tue, 14 Jul 2009 12:54:37 +0400 |
parents | |
children | 16ada169ca75 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:03e58a454b20 |
---|---|
1 #!/usr/bin/perl -w | |
2 use strict; | |
3 | |
4 package ObjectStore::CDBI::Users; | |
5 use Common; | |
6 use Digest::MD5 qw(md5_hex); | |
7 our @ISA = qw(Object); | |
8 | |
9 our $Namespace; | |
10 our $DataModule; | |
11 | |
12 our $Prefix = $Namespace ? $Namespace.'::' : ''; | |
13 | |
14 if ($DataModule) { | |
15 $DataModule =~ s/::/\//g; | |
16 $DataModule .= '.pm'; | |
17 require $DataModule; | |
18 } | |
19 | |
20 BEGIN { | |
21 DeclareProperty DSNamespace => ACCESS_NONE; | |
22 } | |
23 | |
24 sub CTOR { | |
25 my ($this,%args) = @_; | |
26 | |
27 $this->{$DSNamespace} = $args{'DSNamespace'}; | |
28 } | |
29 | |
30 sub ClassName { | |
31 return $_[0]->{$DSNamespace} ? $_[0]->{$DSNamespace}. $_[1] : $_[1]; | |
32 } | |
33 | |
34 sub FindUser { | |
35 my ($this,$uname) = @_; | |
36 | |
37 my @Users = $this->ClassName('Principal')->search(Name => $uname); | |
38 return shift @Users; | |
39 } | |
40 | |
41 sub CreateUser { | |
42 my ($this,$uname,$description,$active) = @_; | |
43 | |
44 if (my $user = $this->FindUser($uname)) { | |
45 die new Exception("The user is already exists",$uname); | |
46 } else { | |
47 return $this->ClassName('Principal')->insert({Name => $uname, Description => $description, Active => $active}); | |
48 } | |
49 } | |
50 | |
51 sub DeleteUser { | |
52 my ($this,$objUser) = @_; | |
53 | |
54 $objUser->delete; | |
55 } | |
56 | |
57 sub GetUserAuthData { | |
58 my ($this,$objUser,$objSecPackage) = @_; | |
59 | |
60 my @Data = $this->ClassName('AuthData')->search(User => $objUser,Package => $objSecPackage->Name); | |
61 return $Data[0]; | |
62 } | |
63 | |
64 sub SetUserAuthData { | |
65 my ($this,$objUser,$objSecPackage,$objAuthData) = @_; | |
66 | |
67 if (my $AuthData = $this->GetUserAuthData($objUser,$objSecPackage)) { | |
68 $AuthData->AuthData(objAuthData->SessionAuthData); | |
69 $AuthData->update; | |
70 } else { | |
71 $this->ClassName('AuthData')->insert({ User => $objUser, Package => $objSecPackage->Name, AuthData => $objAuthData->SessionAuthData}); | |
72 } | |
73 } | |
74 | |
75 sub CreateSession { | |
76 my ($this,$SSID,$objUser,$objAuthData) = @_; | |
77 | |
78 my $session = $this->ClassName('Session')->insert({SSID => $SSID, User => $objUser, SecData => $objAuthData->SessionAuthData, LastUsage => DateTime->now() }); | |
79 $session->autoupdate(1); | |
80 return $session; | |
81 } | |
82 | |
83 sub CloseSession { | |
84 my ($this,$objSession) = @_; | |
85 | |
86 $objSession->delete; | |
87 } | |
88 | |
89 sub LoadSession { | |
90 my ($this,$SSID) = @_; | |
91 my @Data = $this->ClassName('Session')->search(SSID => $SSID); | |
92 if ($Data[0]) { | |
93 $Data[0]->autoupdate(1); | |
94 return $Data[0]; | |
95 } | |
96 } | |
97 | |
98 sub construct { | |
99 return __PACKAGE__->new(DSNamespace => $Prefix); | |
100 } |