| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | class UserProfileController extends AuthController { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |     | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 5 |  | View Code Duplication |     public function userProfile() { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |         if (Auth::user()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |             //   $email = Auth::user()->email; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |             $userDetails = DB::table('users')->select('*')->where('id', Auth::user()->id)->get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |             foreach ($userDetails as $key => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |                 $userDetailsArray = array(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |                 $userDetailsArray = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |            // print_r($userDetailsArray); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |              $data['userDetailsArray']=$userDetailsArray; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |             return View::make('layouts/profile')->with("userDetailsArray", $userDetailsArray); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         return Redirect::route('main'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 22 |  | View Code Duplication |     public function viewProfile($userId) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |         if (Auth::user()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |             //   $email = Auth::user()->email; | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |             $userDetails = DB::table('users')->select('*')->where('id', $userId)->get(); | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |             foreach ($userDetails as $key => $value) { | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |                 $userDetailsArray = array(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |                 $userDetailsArray = $value; | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |             // print_r($userDetailsArray); | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |             // $data['userDetailsArray']=$userDetailsArray; | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |             return View::make('layouts/profile')->with("userDetailsArray", $userDetailsArray); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |         return Redirect::route('main'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     public function updateProfile() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         DB::table('users')->where('id', Auth::user()->id)->update(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             'summary' => Input::get('summary'), 'first_name' => Input::get('first_name'), 'birthday' => Input::get('birthday'), 'gender' => Input::get('gender') | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             , 'last_name' => Input::get('last_name'), 'email' => Input::get('email'), 'contact' => Input::get('contact') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                 ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |           return Redirect::to('/view_profile/'.Auth::user()->id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     public function updateProfilePicture() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $userProfile = DB::table('users')->select('profile_pic')->where('id', Auth::user()->id)->get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         foreach ($userProfile as $key => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                 $userDetailsArray = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             @unlink('fusionmate/public/plugins/profile_pics/'.$userDetailsArray['profile_pic']); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         // Build the input for our validation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $input = array('image' => Input::file('avatar')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         // Within the ruleset, make sure we let the validator know that this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         // file should be an image | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $rules = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             'image' => 'image|required' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         // Now pass the input and rules into the validator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $validator = Validator::make($input, $rules); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         // Check to see if validation fails or passes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         if ($validator->fails()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             // Redirect with a helpful message to inform the user that  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             // the provided file was not an adequate type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | //            return Redirect::back()->withErrors(['Error: The provided file was not an image', 'Error: The provided file was not an image']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |              return Redirect::back()->withErrors($validator); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             //print_r('Error: The provided file was not an image'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             // return Redirect::to('/')->with('message', 'Error: The provided file was not an image'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             $file = Input::file('avatar'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |              | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             $file->move('fusionmate/public/plugins/profile_pics', $file->getClientOriginalName()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             $imgPath = $file->getClientOriginalName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             $imagePath = $imgPath; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             DB::table('users')->where('id', Auth::user()->id)->update(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |                 'profile_pic' => $imagePath | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                     ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             return Redirect::to('/view_profile/'.Auth::user()->id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             // Actually go and store the file now, then inform  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             // the user we successfully uploaded the file they chose | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             //return Redirect::to('/')->with('message', 'Success: File upload was successful'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     public function settings() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         if (Auth::user()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             return View::make('templates/settings/password_settings'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         return Redirect::route('main'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      public function updatePassword() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |           $input = Input::all(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |            $rules = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                        'current_password' => 'required', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |              'password' => 'required|min:6|regex:/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{1,}$/', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         'password_confirm' => 'required|same:password' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |             | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         // Now pass the input and rules into the validator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         $validator = Validator::make($input, $rules); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         // Check to see if validation fails or passes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         if ($validator->fails()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |           | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |              return Redirect::back()->withErrors($validator); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |          $password=  Hash::make(Input::get('new_password')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         DB::table('users')->where('id', Auth::user()->id)->update(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |                 'password' => $password | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |                     ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |           return Redirect::to('/settings/'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     function deactivateAccount(){ | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |          if (Auth::user()) {             | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         $loggedInUser=Auth::user()->id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         $userProfile = DB::table('users')->select('profile_pic')->where('id', Auth::user()->id)->get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         foreach ($userProfile as $key => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |                 $userDetailsArray = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         @unlink('fusionmate/public/plugins/profile_pics/'.$userDetailsArray['profile_pic']); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         DB::table('team_channel_users')->where('user_id', '=', $loggedInUser)->delete(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         DB::table('team_conversations')->where('user_id', '=', $loggedInUser)->delete(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         DB::table('team_conversations_read_status')->where('user_id', '=', $loggedInUser)->delete(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |         DB::table('team_heads')->where('user_id', '=', $loggedInUser)->delete(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         DB::table('login_status')->where('user_id', '=', $loggedInUser)->delete(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         DB::table('user_roles')->where('user_id', '=', $loggedInUser)->delete(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         $affected = DB::table('users')->where('id', '=', $loggedInUser)->delete(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | //        @unlink('fusionmate/public/plugins/userUploads/' . $userDetailsArray['profile_pic']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |             return Redirect::route('main'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |          } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |                   | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |               | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 147 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 148 |  |  |  | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.