| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Craft; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Class ApiAuthController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * Api authentication using user keys | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @author    Nerds & Company | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @copyright Copyright (c) 2015, Nerds & Company | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @license   MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @link      http://www.nerds.company | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | class ApiAuthController extends BaseController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     /** @var bool */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     protected $allowAnonymous = array('authenticate', 'resetPassword'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * Set cors headers and check for options request | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 23 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     public function init() | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |         craft()->apiAuth->setCorsHeaders(); | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |         if (craft()->apiAuth->isOptionsRequest()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |             craft()->end(); | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * Authenticate action. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 4 |  |     public function actionAuthenticate() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 4 |  |             $this->requirePostRequest(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 3 |  |             $username = craft()->request->getRequiredPost('username'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 3 |  |             $password = craft()->request->getRequiredPost('password'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 3 |  |             if (craft()->userSession->login($username, $password)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 2 |  |                 $key = craft()->apiAuth->generateKey(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 2 |  |                 $user = craft()->userSession->getUser(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 2 |  |                 if (craft()->apiAuth->saveKey($user, $key)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 1 |  |                     $this->returnJson(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 1 |  |                         'key' => $key, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 1 |  |                     )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 1 |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 1 |  |                     HeaderHelper::setHeader('HTTP/ 500 Internal server error'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 1 |  |                     $this->returnErrorJson(Craft::t('Something went wrong')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 2 |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 1 |  |                 HeaderHelper::setHeader('HTTP/ 401 Bad Credentials'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 1 |  |                 $this->returnErrorJson(Craft::t('Invalid username or password')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 4 |  |         } catch (HttpException $e) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 1 |  |             HeaderHelper::setHeader('HTTP/ ' . $e->statusCode); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 1 |  |             $this->returnErrorJson($e->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 4 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * Forgot password action | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 3 |  |     public function actionResetPassword() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 3 |  |             $this->requirePostRequest(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 2 |  |             $username = craft()->request->getRequiredPost('username'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 2 |  |             $user = craft()->users->getUserByUsernameOrEmail($username); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 2 |  |             if ($user) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 1 |  |                 craft()->users->sendPasswordResetEmail($user); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 1 |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 2 |  |             $this->returnJson(array('message' => Craft::t('Email has been sent if address exists'))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 3 |  |         } catch (HttpException $e) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 1 |  |             HeaderHelper::setHeader('HTTP/ ' . $e->statusCode); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 | 1 |  |             $this->returnErrorJson($e->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 3 |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 90 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 91 |  |  |  | 
            
                        
Scrutinizer analyzes your
composer.json/composer.lockfile if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.