mirror of
https://gitlab.com/t6353/sharee.bike.git
synced 2025-05-13 23:26:29 +02:00
rebuild merchant select to get colors and init_map
This commit is contained in:
parent
0184300a35
commit
1b0ba8f010
8 changed files with 112 additions and 119 deletions
|
@ -49,7 +49,6 @@ sub handler {
|
|||
my $oprefix = $dbt->{operator}->{$varenv{dbname}}->{oprefix};
|
||||
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
|
||||
my $lang="de";
|
||||
my $owner=188;#default via API if authcookie doesn't match merchant_id
|
||||
my @keywords = $q->param;
|
||||
my $debug=1;
|
||||
my $user_agent = $q->user_agent();
|
||||
|
@ -60,7 +59,7 @@ print $q->header(-type => "application/json", -charset => "utf-8", -'Access-Cont
|
|||
|
||||
my $respreq = $q->param('request') || "";
|
||||
my $apiserver = $q->url(-base=>1) || "";
|
||||
my $copri_version = "4.1.8.31";
|
||||
my $copri_version = "4.1.8.41";
|
||||
|
||||
my $response = {
|
||||
apiserver => "$apiserver",
|
||||
|
@ -75,15 +74,11 @@ my $response = {
|
|||
uri_primary => "$varenv{uri_primary}",
|
||||
copri_version => "$copri_version",
|
||||
response_state => "OK, nothing todo",
|
||||
privacy_html => "site/privacy.html",
|
||||
privacy_html => "site/privacy_1.html",
|
||||
agb_html => "site/agb.html",
|
||||
impress_html => "site/impress.html",
|
||||
tariff_info_html => "site/tariff_info_1.html",
|
||||
bike_info_html => "site/bike_info.html",
|
||||
initMap => {
|
||||
center => { latitude => "", longitude => "" },
|
||||
radius => ""
|
||||
},
|
||||
last_used_operator => {
|
||||
operator_name => "sharee.bike | TeilRad GmbH",
|
||||
operator_color => "#009699",
|
||||
|
@ -93,39 +88,10 @@ my $response = {
|
|||
},
|
||||
lang => "DE"
|
||||
};
|
||||
#user_agent => "$user_agent"
|
||||
|
||||
my $merchanized = 0;
|
||||
my $merchant_conf = "";
|
||||
#while (($merchant_conf, my $value) = each %{ $dbt->{merchant_ids}}) {
|
||||
# if($merchant_conf && $value->{user_agent} && $user_agent && $user_agent =~ /$value->{user_agent}/){
|
||||
# #$owner = join("", map { $_ } keys %{ $value });
|
||||
# $owner = $value->{id};
|
||||
# $merchanized = 1;
|
||||
# $response->{initMap} = "$value->{initMap}";
|
||||
# $bw->log("APIjsonserver merchant select by user_agent: if($value->{user_agent} && $user_agent && $user_agent =~ /$value->{user_agent}/){",$merchant_id,"");
|
||||
# last;
|
||||
# }
|
||||
#}
|
||||
(my $aowner,$varenv{merchant_id},$response) = $apif->fetch_merchant(\%varenv,"",$R::authcookie,$R::merchant_id);
|
||||
|
||||
if(!$merchanized){
|
||||
while (($merchant_conf, my $value) = each %{ $dbt->{merchant_ids}}) {
|
||||
if($merchant_conf && (($R::authcookie && $R::authcookie =~ /$merchant_conf$/) || ($R::merchant_id && $R::merchant_id eq $merchant_conf))){
|
||||
$owner = $value->{id};
|
||||
$merchanized = 1;
|
||||
$value->{initMap} =~ s/\s//g;
|
||||
my ($lat,$lng) = split(/,/,$value->{initMap});
|
||||
$response->{initMap}->{center}->{latitude} = $lat;
|
||||
$response->{initMap}->{center}->{longitude} = $lng;
|
||||
$response->{initMap}->{radius} = "2.9";
|
||||
#$response->{initMap} = "$value->{initMap}";
|
||||
$bw->log("APIjsonserver merchant select by authcookie OR merchant_id: if($merchant_conf && (($R::authcookie && $R::authcookie =~ /$merchant_conf$/) || ($R::merchant_id && $R::merchant_id eq $merchant_conf))){",$merchant_conf,"");
|
||||
last;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!$merchanized && ($R::authcookie || $R::merchant_id)){
|
||||
if(!$aowner && ($R::authcookie || $R::merchant_id)){
|
||||
$response->{response_state} = "Failure 9900: no authcookie or merchant_id defined";
|
||||
$response->{response_text} = "Authentifizierung fehlgeschlagen.";
|
||||
$bw->log("NO authcookie or merchant_id defined",$R::merchant_id,"");
|
||||
|
@ -135,7 +101,7 @@ if(!$merchanized && ($R::authcookie || $R::merchant_id)){
|
|||
exit 0;
|
||||
}
|
||||
|
||||
#If param>40 || value > 200 then exit
|
||||
#If param>40 || value > 400 then exit
|
||||
foreach(@keywords){
|
||||
if(length($_) > 40 || length($q->param($_)) > 400){
|
||||
$response->{response_state} = "Failure 9000: amount of characters in $_ exceeds";
|
||||
|
@ -183,7 +149,7 @@ elsif($q->param('request') eq "authout"){
|
|||
}
|
||||
#authorization
|
||||
elsif($q->param('request') eq "authorization"){
|
||||
my ($auth,$authraw) = $apif->authorization($q,"","",$owner);
|
||||
my ($auth,$authraw) = $apif->authorization($q,"","",$aowner);
|
||||
if(ref($auth) eq "HASH" && $auth->{authcookie}){
|
||||
$response = { %$response, %$auth };
|
||||
$response->{response_text} = "Herzlich willkommen im Fahrradmietsystem";
|
||||
|
@ -230,11 +196,11 @@ elsif($q->param('request') eq "booking_request"){
|
|||
$gps = "$latitude,$longitude" if($latitude && $longitude);
|
||||
}
|
||||
|
||||
my $response_book = $tk->net_booking($authraw,$q->param('bike'),$owner,$gps);
|
||||
my $response_book = $tk->net_booking($authraw,$q->param('bike'),$aowner,$gps);
|
||||
|
||||
#just in time booking
|
||||
if(ref($response_book) eq "HASH" && $response_book->{response_state} =~ /OK/ && $q->param('state') && $q->param('state') =~ /occupied/){
|
||||
(my $rows, my $booking_values) = $apif->booking_update($q,$authraw,$owner);
|
||||
(my $rows, my $booking_values) = $apif->booking_update($q,$authraw,$aowner);
|
||||
$response = {%$response, %$booking_values};
|
||||
}else{
|
||||
$response = {%$response, %$response_book};
|
||||
|
@ -283,10 +249,10 @@ elsif($q->param('request') eq "booking_cancel" || $q->param('request') eq "booki
|
|||
if(ref($auth) eq "HASH" && $auth->{authcookie}){
|
||||
if($q->param('bike')){
|
||||
if($q->param('request') eq "booking_update" && $q->param('state') && $q->param('state') =~ /canceled/){
|
||||
($rows, my $booking_values) = $apif->booking_update($q,$authraw,$owner);
|
||||
($rows, my $booking_values) = $apif->booking_update($q,$authraw,$aowner);
|
||||
$response = {%$response, %$booking_values};
|
||||
}elsif($q->param('request') eq "booking_update" && (($q->param('state') && $q->param('state') =~ /occupied|available/) || ($q->param('lock_state') && $q->param('lock_state') =~ /locking|locked|unlocked/))){
|
||||
($rows, my $booking_values) = $apif->booking_update($q,$authraw,$owner);
|
||||
($rows, my $booking_values) = $apif->booking_update($q,$authraw,$aowner);
|
||||
$response = {%$response, %$booking_values};
|
||||
|
||||
#keep in mind, it works on operator dependency
|
||||
|
@ -389,7 +355,7 @@ elsif($q->param('request') eq "user_bikes_occupied"){
|
|||
my ($auth,$authraw) = $apif->auth_verify($q);
|
||||
if(ref($auth) eq "HASH" && $auth->{authcookie}){
|
||||
$response = { %$response, %$auth };
|
||||
($response->{bikes_occupied},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$auth,$owner);
|
||||
($response->{bikes_occupied},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$auth,$aowner);
|
||||
}else{
|
||||
$response->{response_state} = "Failure 1001: authcookie on primary not defined";
|
||||
$response->{response_text} = "Entschuldigung, die Session wurde unterbrochen";
|
||||
|
@ -416,7 +382,7 @@ elsif($q->param('request') eq "bikes_available"){
|
|||
if($varenv{syshost} eq "shareeapp-primary"){
|
||||
my ($auth,$authraw) = $apif->auth_verify($q);
|
||||
$response = { %$response, %$auth };
|
||||
($response->{bikes},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$auth,$owner);
|
||||
($response->{bikes},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$auth,$aowner);
|
||||
#my $stamp = gettimeofday;
|
||||
#$bw->log("X bikes_available $varenv{syshost} $stamp: $response->{user_group}",$response,"");
|
||||
}else{
|
||||
|
@ -437,7 +403,7 @@ elsif($q->param('request') eq "bikes_all"){
|
|||
if($varenv{syshost} eq "shareeapp-primary"){
|
||||
my ($auth,$authraw) = $apif->auth_verify($q);
|
||||
$response = { %$response, %$auth };
|
||||
($response->{bikes},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$auth,$owner);
|
||||
($response->{bikes},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$auth,$aowner);
|
||||
}else{
|
||||
my ($auth,$authraw) = $apif->auth_verify($q);
|
||||
$response = { %$response, %$auth };
|
||||
|
@ -445,7 +411,7 @@ elsif($q->param('request') eq "bikes_all"){
|
|||
|
||||
#on servicetool only stations on user_tour
|
||||
my $stations_allraw = {};
|
||||
(my $stations_not_used,$stations_allraw) = $apif->stations_all($q,"",$authraw) if($owner && $owner eq "187");#shareetool
|
||||
(my $stations_not_used,$stations_allraw) = $apif->stations_all($q,"",$authraw) if($aowner && $aowner eq "187");#shareetool
|
||||
|
||||
my ($bikes_all,$bikes_allraw,$bikes_on_station) = $apif->bikes_all($q,$authraw,$stations_allraw);
|
||||
|
||||
|
@ -456,7 +422,7 @@ elsif($q->param('request') eq "bikes_all"){
|
|||
my $response_work = {};
|
||||
|
||||
#shareetool
|
||||
if($owner && $owner eq "187"){
|
||||
if($aowner && $aowner eq "187"){
|
||||
(my $xresponse, $pos_record, my $node_template, my $crecord) = $apif->service_select($q,$authraw,"",$interval);
|
||||
|
||||
($response_work, my $node) = $apif->service_work($pos_record,$bikes_allraw,"",$node_template);
|
||||
|
@ -481,7 +447,7 @@ elsif($q->param('request') eq "bikes_all"){
|
|||
#print "bid:$bid|$bikes_allraw->{$bid}->{mtime}\n";
|
||||
|
||||
#shareetool disabled, needs also to much cpu-time
|
||||
#if(ref($response_work->{$biselect}) ne "HASH" || $response_work->{$biselect}->{int01}->{c_id} !~ /\d/ && $owner && $owner eq "187"){
|
||||
#if(ref($response_work->{$biselect}) ne "HASH" || $response_work->{$biselect}->{int01}->{c_id} !~ /\d/ && $aowner && $aowner eq "187"){
|
||||
# my $pos_record_bi = $apif->service_work_select($biselect,"","");
|
||||
# (my $response_work_bi, my $node) = $apif->service_work($pos_record_bi,$bikes_allraw);
|
||||
# $response_work->{$biselect} = $response_work_bi->{$biselect};
|
||||
|
@ -489,7 +455,7 @@ elsif($q->param('request') eq "bikes_all"){
|
|||
#}
|
||||
|
||||
#2019-02-14, fixed
|
||||
if(ref($response_work->{$biselect}) eq "HASH" && $owner && $owner eq "187"){#shareetool
|
||||
if(ref($response_work->{$biselect}) eq "HASH" && $aowner && $aowner eq "187"){#shareetool
|
||||
#print "$biselect: $response_work->{$biselect}->{mtime}\n";
|
||||
$bikes_allraw->{$bid}->{service_state_exist} = 1;
|
||||
|
||||
|
@ -581,7 +547,7 @@ elsif($q->param('request') eq "stations_all"){
|
|||
if($varenv{syshost} eq "shareeapp-primary"){
|
||||
my ($auth,$authraw) = $apif->auth_verify($q);
|
||||
$response = { %$response, %$auth };
|
||||
($response->{stations},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$auth,$owner);
|
||||
($response->{stations},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$auth,$aowner);
|
||||
}else{
|
||||
my ($auth,$authraw) = $apif->auth_verify($q);
|
||||
$response = { %$response, %$auth };
|
||||
|
@ -596,11 +562,11 @@ elsif($q->param('request') eq "stations_available"){
|
|||
my ($auth,$authraw) = $apif->auth_verify($q);
|
||||
#Mein konrad App
|
||||
#if($dbt->{merchant_ids}->{$varenv{merchant_id}}->{id} eq "176"){
|
||||
if($owner && $owner eq "176"){
|
||||
if($aowner && $aowner eq "176"){
|
||||
$response->{merchant_message} = "Herzlich Willkommen bei der neuen konrad App! Die App ist zwar schon installierbar, bis zur vollständigen Umstellung des Systems sind aber noch keine Räder ausleihbar. Das ist erst voraussichtlich Ende Januar der Fall und wird den Nutzern noch mitgeteilt. Danke für Ihr Verständnis! Ihr konrad-Team";
|
||||
}
|
||||
$response = { %$response, %$auth };
|
||||
($response->{stations},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$auth,$owner);
|
||||
($response->{stations},$response->{uri_operator_array},$response->{user_group},$response->{user_tour}) = $jsc->loop_sharees($q,$auth,$aowner);
|
||||
}else{
|
||||
my ($auth,$authraw) = $apif->auth_verify($q);
|
||||
$response = { %$response, %$auth };
|
||||
|
@ -625,7 +591,7 @@ elsif($q->param('request') eq "user_feedback" || $q->param('request') eq "user_m
|
|||
#if(!$back_id){#disabled because of every feedback have to be saved
|
||||
if(1==1){
|
||||
#INSERT just dadaset
|
||||
$back_id = $apif->service_insert($q,$authraw,$node_template,$crecord,$owner);
|
||||
$back_id = $apif->service_insert($q,$authraw,$node_template,$crecord,$aowner);
|
||||
$rows = $apif->service_update($q,$authraw,$node_template,$back_id);
|
||||
if($rows && $rows > 0){
|
||||
$response->{response_state} = "OK, feedback insert and update";
|
||||
|
@ -864,7 +830,7 @@ else{
|
|||
my $jrout = $json->pretty->encode({shareejson => $response});
|
||||
print $jrout;
|
||||
|
||||
$bw->log("APIjsonserver response by $user_agent mapped owner:$owner",$jrout,"");
|
||||
$bw->log("APIjsonserver response by $user_agent mapped aowner:$aowner",$jrout,"");
|
||||
#end JSON ----------------------------------------------------------------------------
|
||||
|
||||
return Apache2::Const::OK;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue