/** * * @param PCRequest $request */ public function repassAction($request){ $params = $request->getParams(); $user_id = $params['id']; $hash = $params['val']; $model_user = NULL; $result = PCMapperRepass::handleRepassRequest($user_id, $hash, $model_user); if($result == FALSE){ return NULL; } $mail = PCEmailBuilder::buildEmailForPasswordNotification($result, $model_user); PCEmailSender::sendMail($mail); $content = array(); $content['title'] = "WebSherpa"; $content['pageContent']= "<h1>A new password has been sent to your e-mail address (".$model_user->getEmail().")</h1>"; return PCRendererHTML::rendererForView('flexiblePage', $content); }
/** * Crea una nuova password(aggiorna il db) e la restituisce. restituisce false in caso negativo * @param PCModelUser $user_id l' id dell' utente * @param string $hash l' hash inviato dall'utente * @param PCModelUser * @return boolean|string */ public static function handleRepassRequest($user_id, $hash, &$user_to_ret) { $keys = array('request_hash'=>$hash, 'user_id'=>$user_id); $items = PCModelManager::fetchModelObjectInstances(PCModelRepass::getMapper(), $keys, NULL, TRUE); if (count($items) <= 0) { return FALSE; } $item = $items[0]; if ($item == NULL || $item->isExpired()) { c_dump("SCADUTA"); return FALSE; } $bindigngs = array(":h" => $hash, ":user"=> $user_id); PCModelManager::deleteObject(PCModelRepass::getMapper(), "request_hash = :h AND user_id = :user", $bindigngs); $newPwd = PCMapperRepass::rand_password(8); $model_user = PCModelManager::fetchObjectWithIdentifier(PCModelUser::getMapper(), $item->getUser_id(), NULL, TRUE); if($model_user == NULL){ $id = $item->getUser_id(); error_log("User non presente (user_id: $id )"); return FALSE; } $newPwdHash = PCAuth::computeHashForString($newPwd); if(PCMapperUser::changePasswordForUser($model_user, $newPwdHash) == FALSE){ return FALSE; } $user_to_ret = $model_user; return $newPwd; }
/** * * @param PCRequest $request */ public function handleRepassAction($request) { $error = NULL; $user = NULL; $param = $request->getParams(); $result = PCMapperRepass::createRepassRequest($param['email'], $user, $error); if ($result == FALSE) { return new PCRendererJSON(array("error" => $error)); } $mail = NULL; $domain = PCConfigManager::sharedManager()->getValue('DOMAIN_NAME'); $mail = PCEmailBuilder::buildEmailForPasswordLost("http://{$domain}/page/repass/?id=" . $user->getIdentifier() . "&val=" . $result, $user); PCEmailSender::sendMail($mail); $ok = array("result" => "OK"); return new PCRendererJSON($ok); }