Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 2499 | Rev 2581 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 2499 Rev 2503
Línea 1010... Línea 1010...
1010
            }
1010
            }
Línea 1011... Línea 1011...
1011
            
1011
            
1012
            
1012
            
-
 
1013
            $deviceMapper = DeviceMapper::getInstance($this->adapter);
1013
            $deviceMapper = DeviceMapper::getInstance($this->adapter);
1014
            $device = $deviceMapper->fetchOne($device_uuid);
1014
            $device = $deviceMapper->fetchOne($device_uuid);
1015
            /*
1015
            if(!$device) {
1016
            if(!$device) {
1016
                $device                 = new Device();
1017
                $device                 = new Device();
1017
                $device->id             = $device_uuid;
1018
                $device->id             = $device_uuid;
Línea 1026... Línea 1027...
1026
                    return new JsonModel([
1027
                    return new JsonModel([
1027
                        'success' => false,
1028
                        'success' => false,
1028
                        'data' => 'ERROR_DEVICE_NOT_FOUND',
1029
                        'data' => 'ERROR_DEVICE_NOT_FOUND',
1029
                    ]);
1030
                    ]);
1030
                }
1031
                }
-
 
1032
            }*/
-
 
1033
            if(!$device) {
-
 
1034
                return new JsonModel([
-
 
1035
                    'success' => false,
-
 
1036
                    'data' => 'ERROR_DEVICE_NOT_FOUND',
-
 
1037
                ]);
1031
            }
1038
            }
1032
            
-
 
Línea 1033... Línea 1039...
1033
 
1039
 
Línea 1108... Línea 1114...
1108
            $authAdapter->setData($email, $password);
1114
            $authAdapter->setData($email, $password);
Línea 1109... Línea 1115...
1109
            
1115
            
1110
            $authService = new AuthenticationService();
1116
            $authService = new AuthenticationService();
Línea -... Línea 1117...
-
 
1117
            $result = $authService->authenticate($authAdapter);
1111
            $result = $authService->authenticate($authAdapter);
1118
            
Línea 1112... Línea 1119...
1112
            
1119
            $ip = Functions::getUserIP();
1113
            if($result->getCode() == AuthResult::SUCCESS) {
1120
            if($result->getCode() == AuthResult::SUCCESS) {
Línea 1114... Línea 1121...
1114
                
1121
                
1115
                $userMapper = UserMapper::getInstance($this->adapter);
1122
                $userMapper = UserMapper::getInstance($this->adapter);
1116
                $user = $userMapper->fetchOneByEmail($email);
1123
                $user = $userMapper->fetchOneByEmail($email);
Línea 1117... Línea -...
1117
              
-
 
-
 
1124
              
Línea 1118... Línea 1125...
1118
                
1125
                
1119
                $device->user_id    = $user->id;
1126
                $device->user_id    = $user->id;
1120
                $device->ip         = Functions::getUserIP();
1127
                $device->ip         = $ip;
-
 
1128
                if($deviceMapper->update($device)) {
1121
                if($deviceMapper->update($device)) {
1129
                    
1122
                    
1130
                    
1123
                    $ip = Functions::getUserIP();
1131
                    
1124
                    
1132
                    $deviceHistoryMapper = DeviceHistoryMapper::getInstance($this->adapter);
1125
                    $deviceHistoryMapper = DeviceHistoryMapper::getInstance($this->adapter);
1133
                    $deviceHistory = $deviceHistoryMapper->fetchOneByDeviceIdAndUserIdAndIp($device->id, $user->id, $ip);
Línea 1134... Línea 1142...
1134
                        $deviceHistoryMapper->insert($deviceHistory);
1142
                        $deviceHistoryMapper->insert($deviceHistory);
1135
                    }
1143
                    }
Línea 1136... Línea 1144...
1136
                    
1144
                    
Línea 1137... Línea 1145...
1137
                    $pushMapper = PushMapper::getInstance($this->adapter);
1145
                    $pushMapper = PushMapper::getInstance($this->adapter);
1138
                    
1146
                    
1139
                    $userDevices =  $deviceMapper->fetchAllByUserId($user->id);
1147
                    $userDevices =  $deviceMapper->fetchAllByUserIdAndApplicationId($user->id, $device->application_id);
Línea 1140... Línea -...
1140
                    foreach($userDevices as $userDevice)
-
 
1141
                    {
1148
                    foreach($userDevices as $userDevice)
-
 
1149
                    {
Línea 1142... Línea -...
1142
       
-
 
-
 
1150
       
1143
                    
1151
                        if($userDevice->id != $device->id ) {
1144
                        if($userDevice->id != $device->id && $userDevice->token) {
-
 
1145
                            
-
 
1146
                            $key = $application->key;
-
 
1147
                            if ($device->variant_id) {
1152
                            $deviceMapper->releaseUserFormDevice($userDevice);
-
 
1153
                            
1148
                                $applicationVariant = $applicationVariantMapper->fetchOneByApplicationIdAndVariantId($application->id, $variant_id);
1154
                    
1149
                                if($applicationVariant) {
1155
                            if($userDevice->token) {
1150
                                    $key = $applicationVariant->key;
1156
                                
1151
                                    
1157
                                $key = $application->key;
-
 
1158
                                if ($device->variant_id) {
-
 
1159
                                    $applicationVariant = $applicationVariantMapper->fetchOneByApplicationIdAndVariantId($application->id, $variant_id);
-
 
1160
                                    if($applicationVariant) {
-
 
1161
                                        $key = $applicationVariant->key;
-
 
1162
                                        
-
 
1163
                                    } else {
1152
                                } else {
1164
                                        $applicationVariant = $applicationVariantMapper->fetchOneByApplicationIdAndDefault($application->id);
1153
                                    $applicationVariant = $applicationVariantMapper->fetchOneByApplicationIdAndDefault($application->id);
1165
                                        if($applicationVariant) {
1154
                                    if($applicationVariant) {
-
 
1155
                                        $key = $applicationVariant->key;
1166
                                            $key = $applicationVariant->key;
1156
                                    }
1167
                                        }
1157
                                }
1168
                                    }
1158
                            }
1169
                                }
1159
                            
1170
                                
1160
                            
1171
                                
1161
                            $push = new Push();
1172
                                $push = new Push();
1162
                            $push->status = Push::STATUS_PENDING;
-
 
1163
                            $push->data = json_encode([
-
 
1164
                                'server' => [
-
 
1165
                                    'key' =>  $key,
-
 
1166
                                 ],
-
 
1167
                                 'push' => [
-
 
1168
                                    'registration_ids'   => [ 
-
 
1169
                                        $userDevice->token,
-
 
1170
                                     ],
-
 
1171
                                     'notification' => [
-
 
1172
                                         'body' =>  'Se registro un inicio de sesión en otro dispositivo',
1173
                                $push->status = Push::STATUS_PENDING;
-
 
1174
                                $push->data = json_encode([
-
 
1175
                                    'server' => [
-
 
1176
                                        'key' =>  $key,
-
 
1177
                                     ],
-
 
1178
                                     'push' => [
-
 
1179
                                        'registration_ids'   => [ 
-
 
1180
                                            $userDevice->token,
-
 
1181
                                         ],
-
 
1182
                                         'notification' => [
-
 
1183
                                             'body' =>  'Se registro un inicio de sesión en otro dispositivo',
1173
                                         'title' => 'Nuevo inicio de sesión',
1184
                                             'title' => 'Nuevo inicio de sesión',
1174
                                         'vibrate' => 1,
1185
                                             'vibrate' => 1,
1175
                                         'sound' =>  1
1186
                                             'sound' =>  1
1176
                                     ],
1187
                                         ],
1177
                                    'data' => [
1188
                                        'data' => [
1178
                                        'command' => 'signout'
1189
                                            'command' => 'signout'
1179
                                    ]
1190
                                        ]
1180
                                 ]
1191
                                     ]
-
 
1192
                                 ]);
1181
                             ]);
1193
                                
1182
                            
1194
                                $pushMapper->insert($push);
Línea 1183... Línea 1195...
1183
                            $pushMapper->insert($push);
1195