/** * API - send mail to user with new password & update to database * @param array $email * @return array $messages */ public function forgotPassword($email) { $rules = array('email_id' => 'required|email'); $messages = array('email_id.required' => 'parameter_missing', 'email_id.email' => 'invalid_email_format'); $validation = Validator::make(array('email_id' => $email), $rules, $messages); if ($validation->fails()) { $emailMessages = $validation->messages(); if ($emailMessages->has('email_id')) { $this->messages['error'] = Config::get('constants.errorMessages.' . $emailMessages->first('email_id')); } } else { $userData = $this->modelObjectUser->getUserByEmail($email); if ($userData) { if ($userData[0]['registerd_by'] == 'facebook') { $this->messages['error'] = Config::get('constants.errorMessages.user_from_social_site'); return $this->messages; } // generate password $password = $this->generatePassword(); $this->modelObjectUser->updatePassword($userData[0]['id'], Hash::make($password)); $view = 'api.user.forgotPassword'; $dataForView = ['name' => $userData[0]['user_name'], 'password' => $password]; $emails[] = $userData[0]['email_id']; $subject = 'Forgot Password'; $objMailHelper = new MailHelper(); $isMailSent = $objMailHelper->sendMail($view, $dataForView, $emails, $subject); $this->messages['status'] = $this->successStatus; } else { $this->messages['error'] = Config::get('constants.errorMessages.user_not_found'); } } return $this->messages; }