/** * Elimina il token relativo ad un certo utente e applicazione * @param string $user_id l'id dell' utente * @param string $app_id l'id dell' app * @return boolean */ public static function removeTokenForUser($user_id, $app_id){ $conditions = "user_identifier = :user AND app_identifier = :app"; $bindings = array(":user" => $user_id, ":app"=> $app_id ); return PCModelManager::deleteObject(PCModelToken::getMapper(), $conditions, $bindings); }
/** * 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; }