@@ -159,7 +159,6 @@ public function login($args)
159
159
*/
160
160
public function userApikeyDefault ($ args )
161
161
{
162
-
163
162
/** @var ApihelperComponent $apihelperComponent */
164
163
$ apihelperComponent = MidasLoader::loadComponent ('Apihelper ' );
165
164
$ apihelperComponent ->validateParams ($ args , array ('email ' , 'password ' ));
@@ -178,41 +177,44 @@ public function userApikeyDefault($args)
178
177
} catch (Zend_Exception $ exc ) {
179
178
throw new Exception ('Login failed ' , MIDAS_INVALID_PARAMETER );
180
179
}
181
- $ authModule = false ;
182
- foreach ($ notifications as $ user ) {
183
- if ($ user ) {
184
- $ userDao = $ user ;
185
- $ authModule = true ;
180
+ $ userDao = false ;
181
+ foreach ($ notifications as $ notification ) {
182
+ if ($ notification ) {
183
+ $ userDao = $ notification ;
186
184
break ;
187
185
}
188
186
}
187
+ $ hasAuthenticationModule = $ userDao !== false ;
189
188
190
189
/** @var UserModel $userModel */
191
190
$ userModel = MidasLoader::loadModel ('User ' );
192
191
193
192
/** @var UserapiModel $userApiModel */
194
193
$ userApiModel = MidasLoader::loadModel ('Userapi ' );
195
- if (! $ authModule ) {
194
+ if ($ userDao === false ) {
196
195
$ userDao = $ userModel ->getByEmail ($ email );
197
- if (! $ userDao ) {
196
+ if ($ userDao === false ) {
198
197
throw new Exception ('Login failed ' , MIDAS_INVALID_PARAMETER );
199
198
}
200
199
}
201
200
202
- $ instanceSalt = Zend_Registry::get ('configGlobal ' )->password ->prefix ;
203
- if ($ authModule || $ userModel ->hashExists (
204
- hash ($ userDao ->getHashAlg (), $ instanceSalt .$ userDao ->getSalt ().$ password )
201
+ $ prefix = Zend_Registry::get ('configGlobal ' )->password ->prefix ;
202
+ if ($ hasAuthenticationModule || $ userModel ->hashExists (
203
+ hash ($ userDao ->getHashAlg (), $ prefix .$ userDao ->getSalt ().$ password )
205
204
)
206
205
) {
207
206
if ($ userDao ->getSalt () == '' ) {
208
207
$ userModel ->convertLegacyPasswordHash ($ userDao , $ password );
209
208
}
210
- $ defaultApiKey = $ userApiModel ->getByAppAndEmail ('Default ' , $ email )->getApikey ();
209
+ $ userApiDao = $ userApiModel ->getByAppAndEmail ('Default ' , $ email );
210
+ if ($ userApiDao === false ) {
211
+ throw new Exception ('User has no default API key ' , MIDAS_INVALID_PARAMETER );
212
+ }
211
213
212
- return array ('apikey ' => $ defaultApiKey );
213
- } else {
214
- throw new Exception ('Login failed ' , MIDAS_INVALID_PARAMETER );
214
+ return array ('apikey ' => $ userApiDao ->getApikey ());
215
215
}
216
+
217
+ throw new Exception ('Login failed ' , MIDAS_INVALID_PARAMETER );
216
218
}
217
219
218
220
/**
0 commit comments