Esempio n. 1
0
        public async Task<bool> CreateAndSendValidationCodeAsync(AuthenticationType tipoAuth, string username, string _action)
        {
            try
            {
                string baseUrl = await CommunicationManager.ServiceManager.GetServiceEndpoint("GP_BASE_URL");
                Generated.SecurityClient sc = new Generated.SecurityClient(baseUrl, await CommunicationManager.Instance.GetHttpClientWithToken(tipoAuth, new HttpClient()));
                var result = await sc.GetCreateAndSendValidationCodeAsync(username, _action, string.Empty, string.Empty, string.Empty, string.Empty, GetGPAppVersion());

                return result;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        public async Task<Guid> GetValidateCodeByUsernameAsync(AuthenticationType tipoAuth, string _action, string _username, string _validationCode)
        {
            try
            {
                string baseUrl = await CommunicationManager.ServiceManager.GetServiceEndpoint("GP_BASE_URL");
                Generated.SecurityClient sc = new Generated.SecurityClient(baseUrl, await CommunicationManager.Instance.GetHttpClientWithToken(tipoAuth, new HttpClient()));
                var result = await sc.GetValidateCodeByUsernameAsync(_username, _action, _validationCode, GetGPAppVersion());

                var ret = Guid.Parse(result.ToString());

                return ret;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 3
0
        public async Task<bool> RegistryUserFromDeviceAndLogin(AuthenticationType tipoAuth, UserType userType, string userId, string username, string password, Guid validationCodeId)
        {
            try
            {
                string baseUrl = await CommunicationManager.ServiceManager.GetServiceEndpoint("GP_BASE_URL");
                Generated.SecurityClient sc = new Generated.SecurityClient(baseUrl, await CommunicationManager.Instance.GetHttpClientWithToken(tipoAuth, new HttpClient()));
                var result = await sc.GetRegistryUserFromDeviceAndLoginAsync(username, password, TranslateUserTypeLocalToGP(userType), userId, GetGPAppVersion());

                bool isAuthenticated = result.IsAuthenticated.HasValue ? result.IsAuthenticated.Value : false;

                if (isAuthenticated)
                {
                    SessionExternal Session = TranslateSessionExternalGPToLocal(result);
                    User = new User()
                    {
                        Name = Session.Name,
                        Type = Session.UserType,
                        UserId = Session.UserId,
                        Username = Session.Username,
                        //Session = new Session(encryptKey) { EncryptedSessionTokenSecret = Session.EncryptedAccessTokenSecret }, // É necessário?? Não está a ser devolvida... AccessToken substitui?
                        SecurityId = Session.SecurityId
                    };

                    // Este assign permite/serve para posteriormente a esta chamada quando algum serv for invocado com AuthenticationType = UserAuthentication utilizar estas credenciais para obter token
                    CommunicationManager.UserName = username;
                    CommunicationManager.UserPassWord = password;

                    var resultTMP = await GPService.Instance.GetAndSetPatientInfoByUniqueIdAsync(AuthenticationType.UserAuthentication, User.UserId); // Sincronamente irá obter dados paciente

                    GPService.Instance.GetPatientPhoto(AuthenticationType.UserAuthentication);  // obter foto do paciente ( colocar sincrono?? é necessária para a primeira página -filtro na página da agenda)
                    GPService.Instance.GetAndSetDefaultFinancialEntityByUniquePatient(AuthenticationType.UserAuthentication, null, null/*User.UserId*/);   // obter/preencher EFRID do paciente assincronamente 

                    return true;
                }

                return false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 4
0
        public async Task<bool> ChangeUserPasswordAsync(AuthenticationType tipoAuth, string username, string oldPassword, string newPassword)
        {
            try
            {
                string baseUrl = await CommunicationManager.ServiceManager.GetServiceEndpoint("GP_BASE_URL");
                Generated.SecurityClient sc = new Generated.SecurityClient(baseUrl, await CommunicationManager.Instance.GetHttpClientWithToken(tipoAuth, new HttpClient()));
                var result = await sc.GetChangeUserPasswordAsync(username, oldPassword, newPassword, GetGPAppVersion());

                if (result)
                {
                    // Este assign permite/serve para posteriormente a esta chamada quando algum serv for invocado com AuthenticationType = UserAuthentication utilizar estas credenciais para obter token
                    CommunicationManager.UserName = username;
                    CommunicationManager.UserPassWord = newPassword;
                }

                return result;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 5
0
        public async Task<User> GetMyUserIdAsync(AuthenticationType tipoAuth, bool setUser = true)
        {
            try
            {
                string baseUrl = await CommunicationManager.ServiceManager.GetServiceEndpoint("GP_BASE_URL");
                Generated.SecurityClient sc = new Generated.SecurityClient(baseUrl, await CommunicationManager.Instance.GetHttpClientWithToken(tipoAuth, new HttpClient()));
                var result = await sc.GetMyUserIdAsync(GetGPAppVersion());

                SessionExternal session = TranslateSessionExternalGPToLocal(result);
                if (session.UserId != null)
                {
                    var tmpUser = new User()
                    {
                        Name = session.Name,
                        Type = session.UserType,
                        UserId = session.UserId,
                        Username = session.Username,
                        //Session = new Session(encryptKey) { EncryptedSessionTokenSecret = Session.EncryptedAccessTokenSecret }, // É necessário?? Não está a ser devolvida... AccessToken substitui?
                        SecurityId = session.SecurityId
                    };

                    if (setUser)
                        User = tmpUser;

                    return tmpUser;
                }

                return null;

            }
            catch (Exception ex)
            {
                Debug.WriteLine("Erro em GetMyUserIdAsync");
                return null;
            }
        }