Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 1498cb2

Browse files
committed
ENH: refs #237. Create default web api key for new users
1 parent 119d181 commit 1498cb2

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

core/models/base/UserModelBase.php

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public function __construct()
2929
'password' => array('type' => MIDAS_DATA),
3030
'creation' => array('type' => MIDAS_DATA),
3131
'folder_id' => array('type' => MIDAS_DATA),
32-
'admin' => array('type' => MIDAS_DATA),
33-
'privacy' => array('type' => MIDAS_DATA),
32+
'admin' => array('type' => MIDAS_DATA),
33+
'privacy' => array('type' => MIDAS_DATA),
3434
'publicfolder_id' => array('type' => MIDAS_DATA),
3535
'privatefolder_id' => array('type' => MIDAS_DATA),
3636
'view' => array('type' => MIDAS_DATA),
@@ -46,10 +46,10 @@ public function __construct()
4646
'invitations' => array('type' => MIDAS_ONE_TO_MANY, 'model' => 'CommunityInvitation', 'parent_column' => 'user_id', 'child_column' => 'user_id'),
4747
'folderpolicyuser' => array('type' => MIDAS_ONE_TO_MANY, 'model' => 'Folderpolicyuser', 'parent_column' => 'user_id', 'child_column' => 'user_id'),
4848
'feeds' => array('type' => MIDAS_ONE_TO_MANY, 'model' => 'Feed', 'parent_column' => 'user_id', 'child_column' => 'user_id'),
49-
);
49+
);
5050
$this->initialize(); // required
5151
} // end __construct()
52-
52+
5353
/** Abstract functions */
5454
abstract function getByEmail($email);
5555
abstract function getByUser_id($userid);
@@ -59,7 +59,7 @@ abstract function getByUuid($uuid);
5959
abstract function getByFolder($folder);
6060
/** Returns all the users */
6161
abstract function getAll($onlyPublic = false, $limit = 20, $order = 'lastname', $offset = null);
62-
62+
6363
/** save */
6464
public function save($dao)
6565
{
@@ -68,23 +68,23 @@ public function save($dao)
6868
$dao->setUuid(uniqid() . md5(mt_rand()));
6969
}
7070
parent::save($dao);
71-
}
72-
71+
}
72+
7373
/** delete*/
7474
public function delete($dao)
7575
{
7676
//TODO
77-
$modelLoad = new MIDAS_ModelLoader();
77+
$modelLoad = new MIDAS_ModelLoader();
7878
$ciModel = $modelLoad->loadModel('CommunityInvitation');
7979
$invitations = $dao->getInvitations();
8080
foreach($invitations as $invitation)
8181
{
8282
$ciModel->delete($invitation);
8383
}
84-
84+
8585
parent::delete($dao);
8686
}// delete
87-
87+
8888
/** plus one view*/
8989
function incrementViewCount($userDao)
9090
{
@@ -107,10 +107,10 @@ function incrementViewCount($userDao)
107107
$userDao->view++;
108108
$this->save($userDao);
109109
}//end incrementViewCount
110-
110+
111111
/** create user */
112112
public function createUser($email, $password, $firstname, $lastname, $admin = 0)
113-
{
113+
{
114114
if(!is_string($email) || empty($email) || !is_string($password) || empty($password) || !is_string($firstname)
115115
|| empty($firstname) || !is_string($lastname) || empty($lastname) || !is_numeric($admin))
116116
{
@@ -122,7 +122,7 @@ public function createUser($email, $password, $firstname, $lastname, $admin = 0)
122122
{
123123
throw new Zend_Exception("User already exists.");
124124
}
125-
125+
126126
Zend_Loader::loadClass('UserDao', BASE_PATH.'/core/models/dao');
127127
$passwordPrefix = Zend_Registry::get('configGlobal')->password->prefix;
128128
if(isset($passwordPrefix) && !empty($passwordPrefix))
@@ -136,14 +136,14 @@ public function createUser($email, $password, $firstname, $lastname, $admin = 0)
136136
$userDao->setCreation(date('c'));
137137
$userDao->setPassword(md5($password));
138138
$userDao->setAdmin($admin);
139-
139+
140140
// check gravatar
141141
$gravatarUrl = $this->getGravatarUrl($email);
142142
if($gravatarUrl != false)
143143
{
144144
$userDao->setThumbnail($gravatarUrl);
145145
}
146-
146+
147147
parent::save($userDao);
148148

149149
$this->ModelLoader = new MIDAS_ModelLoader();
@@ -155,13 +155,13 @@ public function createUser($email, $password, $firstname, $lastname, $admin = 0)
155155
$feedpolicygroupModel = $this->ModelLoader->loadModel('Feedpolicygroup');
156156
$feedpolicyuserModel = $this->ModelLoader->loadModel('Feedpolicyuser');
157157
$anonymousGroup = $groupModel->load(MIDAS_GROUP_ANONYMOUS_KEY);
158-
158+
159159
$folderGlobal = $folderModel->createFolder('user_' . $userDao->getKey(), '', MIDAS_FOLDER_USERPARENT);
160160
$folderPrivate = $folderModel->createFolder('Private', '', $folderGlobal);
161161
$folderPublic = $folderModel->createFolder('Public', '', $folderGlobal);
162162

163163
$folderpolicygroupModel->createPolicy($anonymousGroup, $folderPublic, MIDAS_POLICY_READ);
164-
164+
165165
$folderpolicyuserModel->createPolicy($userDao, $folderPrivate, MIDAS_POLICY_ADMIN);
166166
$folderpolicyuserModel->createPolicy($userDao, $folderGlobal, MIDAS_POLICY_ADMIN);
167167
$folderpolicyuserModel->createPolicy($userDao, $folderPublic, MIDAS_POLICY_ADMIN);
@@ -175,12 +175,14 @@ public function createUser($email, $password, $firstname, $lastname, $admin = 0)
175175

176176
$feed = $feedModel->createFeed($userDao, MIDAS_FEED_CREATE_USER, $userDao);
177177
$feedpolicygroupModel->createPolicy($anonymousGroup, $feed, MIDAS_POLICY_READ);
178-
$feedpolicyuserModel->createPolicy($userDao, $feed, MIDAS_POLICY_ADMIN);
178+
$feedpolicyuserModel->createPolicy($userDao, $feed, MIDAS_POLICY_ADMIN);
179+
180+
Zend_Registry::get('notifier')->callback('CALLBACK_CORE_NEW_USER_ADDED', array('userDao' => $userDao));
179181

180182
return $userDao;
181183
}
182-
183-
184+
185+
184186
/**
185187
* Get either a Gravatar URL or complete image tag for a specified email address.
186188
*
@@ -198,7 +200,7 @@ public function getGravatarUrl($email, $s = 32, $d = '404', $r = 'g', $img = fal
198200
$url = 'http://www.gravatar.com/avatar/';
199201
$url .= md5(strtolower(trim($email)));
200202
$url .= "?s=".$s."&d=".$d."&r=".$r;
201-
if($img)
203+
if($img)
202204
{
203205
$url = '<img src="' . $url . '"';
204206
foreach($atts as $key => $val)
@@ -207,7 +209,7 @@ public function getGravatarUrl($email, $s = 32, $d = '404', $r = 'g', $img = fal
207209
}
208210
$url .= ' />';
209211
}
210-
212+
211213
$header = get_headers($url, 1);
212214
if(strpos($header[0], '404 Not Found') != false)
213215
{

0 commit comments

Comments
 (0)