1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10: class Folks_Application extends Horde_Registry_Application
11: {
12: 13:
14: public $auth = array(
15: 'add',
16: 'authenticate',
17: 'exists',
18: 'list',
19: 'remove',
20: 'resetpassword',
21: 'transparent'
22: );
23:
24: 25:
26: public $version = 'H4 (0.1-git)';
27:
28: 29: 30: 31:
32: protected function _init()
33: {
34: $links = array(Folks::getUrlFor('feed', 'online') => _("Online users"));
35: if ($GLOBALS['registry']->isAuthenticated()) {
36: $links[Folks::getUrlFor('feed', 'friends')] = _("Online friends");
37: $links[Folks::getUrlFor('feed', 'activity')] = _("Friends activity");
38: $links[Folks::getUrlFor('feed', 'know')] = _("People you might know");
39: }
40:
41: $GLOBALS['linkTags'] = array();
42: foreach ($links as $url => $label) {
43: $GLOBALS['linkTags'][] = '<link rel="alternate" type="application/rss+xml" href="' . $url . '" title="' . $label . '" />';
44: }
45: }
46:
47: 48:
49: public function ($menu)
50: {
51: return Folks::getMenu();
52: }
53:
54: 55: 56:
57: public function authAuthenticate($userID, $credentials)
58: {
59: require_once dirname(__FILE__) . '/base.php';
60:
61: $result = $GLOBALS['folks_driver']->comparePassword($userID, $credentials['password']);
62: if ($result !== true) {
63: throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN);
64: }
65: }
66:
67: 68:
69: public function authTransparent($auth_ob)
70: {
71: if (empty($_COOKIE['folks_login_code']) ||
72: empty($_COOKIE['folks_login_user'])) {
73: return false;
74: }
75:
76: require_once dirname(__FILE__) . '/base.php';
77: $GLOBALS['folks_driver'] = Folks_Driver::factory();
78: if ($_COOKIE['folks_login_code'] == $GLOBALS['folks_driver']->getCookie($_COOKIE['folks_login_user'])) {
79: $GLOBALS['registry']->setAuth($_COOKIE['folks_login_user']);
80: $auth_ob->setCredential('userId', $_COOKIE['folks_login_user']);
81: $GLOBALS['folks_driver']->resetOnlineUsers();
82: return true;
83: } else {
84: return false;
85: }
86: }
87:
88: 89:
90: public function authUserExists($userId)
91: {
92: require_once dirname(__FILE__) . '/base.php';
93:
94: return $GLOBALS['folks_driver']->userExists($userId);
95: }
96:
97: 98:
99: public function authUserList()
100: {
101: require_once dirname(__FILE__) . '/base.php';
102:
103: $users = array();
104: foreach ($GLOBALS['folks_driver']->getUsers() as $user) {
105: $users[] = $user['user_uid'];
106: }
107:
108: return $users;
109: }
110:
111: 112:
113: public function authAddUser($userId, $credentials)
114: {
115: require_once dirname(__FILE__) . '/base.php';
116:
117: $result = $GLOBALS['folks_driver']->addUser($userId, $credentials);
118: if ($result instanceof PEAR_Error) {
119: throw new Horde_Exception_Wrapped($result);
120: }
121: }
122:
123: 124:
125: public function authResetPassword($userId)
126: {
127:
128: $password = Horde_Auth::genRandomPassword();
129:
130:
131: require_once dirname(__FILE__) . '/base.php';
132: $result = $GLOBALS['folks_driver']->changePassword($password, $userId);
133: if ($result instanceof PEAR_Error) {
134: throw new Horde_Auth_Exception($result);
135: }
136:
137: return $password;
138: }
139:
140: 141:
142: public function authRemoveUser($userId)
143: {
144: require_once dirname(__FILE__) . '/base.php';
145:
146: return $GLOBALS['folks_driver']->deleteUser($userId);
147: }
148:
149: 150:
151: public function removeUserData($user = null)
152: {
153: return $this->authRemoveUser($user);
154: }
155:
156: }
157: