Пример #1
0
        internal static LoginResponseInternal LoginInternal(LoginRequestInternal loginRequest)
        {
            LogUtils.LogMethodInvocationStart(true, loginRequest);


            UMarketSCClient       utibaClient = new UMarketSCClient();
            loginResponse         loginInfo;
            createsessionResponse newSession;
            LoginResponseInternal loginResponse = null;

            try
            {
                using (OperationContextScope scope = new OperationContextScope(utibaClient.InnerChannel))
                {
                    HttpRequestMessageProperty messageProperty = new HttpRequestMessageProperty();
                    messageProperty.Headers.Add(HttpRequestHeader.UserAgent, UserAgent);
                    OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, messageProperty);

                    newSession = utibaClient.createsession(new createsession());
                    String passwordHash           = GetSHA1(loginRequest.User.ToLower() + loginRequest.Password);
                    String passwordAndSessionHash = GetSHA1(newSession.createsessionReturn.sessionid + passwordHash.ToLower()).ToUpper();

                    login loginObject = new login();
                    loginObject.loginRequest = new loginRequestType()
                    {
                        sessionid   = newSession.createsessionReturn.sessionid,
                        device_type = loginRequest.DeviceType,
                        initiator   = loginRequest.User,
                        pin         = passwordAndSessionHash
                    };
                    loginInfo = utibaClient.login(loginObject);
                }
                loginResponse = new LoginResponseInternal()
                {
                    ResponseCode    = loginInfo.loginReturn.result,
                    ResponseMessage = loginInfo.loginReturn.result_message,
                    TransactionID   = loginInfo.loginReturn.transid,
                    SessionID       = newSession.createsessionReturn.sessionid
                };

                if (loginResponse.ResponseCode != 0)
                {
                    loginResponse.SetResponseNamespace(ApiResponseInternal.ResponseNamespace.BAC);
                }
            }
            catch (Exception e)
            {
                if (loginResponse == null)
                {
                    loginResponse = new LoginResponseInternal();
                }
                loginResponse.SetThrowedException(e);
            }
            return(loginResponse);
        }
Пример #2
0
        public override IMovilwayApiResponse PerformUtibaOperation(IMovilwayApiRequest requestObject, UMarketSCClient utibaClientProxy, String sessionID)
        {
            GetSessionRequestBody  request  = requestObject as GetSessionRequestBody;
            GetSessionResponseBody response = null;

            createsessionResponse newSessionResponse = utibaClientProxy.createsession(new createsession());
            String PIN = Utils.GenerateHash(newSessionResponse.createsessionReturn.sessionid, request.Username, request.Password);

            logger.InfoLow("[UTI] " + base.LOG_PREFIX + "[GetSessionProvider] [SEND-DATA] loginRequest {sessionid=" + newSessionResponse.createsessionReturn.sessionid + ",device_type=" + request.DeviceType + ",initiator=" + request.Username + ",pin=" + PIN + "}");

            loginResponse loginResponse = utibaClientProxy.login(new login()
            {
                loginRequest = new loginRequestType()
                {
                    sessionid   = newSessionResponse.createsessionReturn.sessionid,
                    device_type = request.DeviceType,
                    initiator   = request.Username,
                    pin         = PIN
                }
            });

            logger.InfoLow("[UTI] " + base.LOG_PREFIX + "[GetSessionProvider] [RECV-DATA] loginResponse {result=" + loginResponse.loginReturn.result + ",result_namespace=" + loginResponse.loginReturn.result_namespace + "}");

            response = new GetSessionResponseBody()
            {
                ResponseCode    = Utils.BuildResponseCode(loginResponse.loginReturn.result, loginResponse.loginReturn.result_namespace),
                ResponseMessage = loginResponse.loginReturn.result_message,
                TransactionID   = loginResponse.loginReturn.transid,
                SessionID       = newSessionResponse.createsessionReturn.sessionid
            };

            if (response.ResponseCode == 0)
            {
                if (ConfigurationManager.AppSettings["ProcessMigration"].ToLower() == "true")
                {
                    //logger.InfoHigh("Comienza la migración del usuario: " + request.AuthenticationData.Username);
                    bool migrateAgent = MigrateAgent(request.AuthenticationData.Username);
                    int  deviceType   = GetDeviceType(request.AuthenticationData.Username);
                    if (migrateAgent)
                    {
                        // Cambio de password Kinacu
                        var changePinResponse = new ServiceExecutionDelegator <ChangePinResponseBody, ChangePinRequestBody>().ResolveRequest(
                            new ChangePinRequestBody()
                        {
                            AuthenticationData = new AuthenticationData()
                            {
                                Username = request.AuthenticationData.Username,
                                Password = ConfigurationManager.AppSettings["StandardOldPin"]
                            },
                            DeviceType = deviceType,                                     /*int.Parse(ConfigurationManager.AppSettings["StandardNewDeviceType"]),*/
                            Agent      = request.AuthenticationData.Username,
                            OldPin     = ConfigurationManager.AppSettings["StandardOldPin"],
                            NewPin     = request.AuthenticationData.Password
                        }, ApiTargetPlatform.Kinacu, ApiServiceName.ChangePin);

                        // Login con Kinacu - NOT NOW - La proxima vez que entre va por Kinacu de una

                        //logger.InfoHigh("Resultado del cambio de clave del usuario: " + changePinResponse.ResponseCode);

                        // Save in DB
                        if (changePinResponse.ResponseCode == 0)
                        {
                            //logger.InfoHigh("Se migró exitosamente la clave del usuario: " + request.AuthenticationData.Username);
                            SaveAgentMigrated(request.AuthenticationData.Username);
                        }
                    }
                }

                // REPG2013 - esto queda deshabilitado por ahora

                // For speeding up, I'm caching the session value:
                //-var couchBaseClient = new CouchbaseClient();
                //-couchBaseClient.Store(StoreMode.Set, Utils.GetSessionForUserKey(request.Username, request.Password), response.SessionID, new TimeSpan(0, UtibaUtils.SessionTTL, 0));
                // Also caching the
                //-couchBaseClient.Store(StoreMode.Set, Utils.GetUserForSessionKey(response.SessionID), request.Username, new TimeSpan(0, UtibaUtils.SessionTTL, 0));
            }
            return(response);
        }