Exemplo n.º 1
0
        public async Task<bool> CheckIfUserEmailsIsAlreadyRegistered(AuthenticationType tipoAuth, string email)
        {

            string excepMessage = string.Empty;
            try
            {
                string baseUrl = await CommunicationManager.ServiceManager.GetServiceEndpoint("GP_BASE_URL");
                Generated.UsersClient sc = new Generated.UsersClient(baseUrl, await CommunicationManager.Instance.GetHttpClientWithToken(tipoAuth, new HttpClient()));
                var result = await sc.GetByUsernameAsync(email, GetGPAppVersion());

                SessionExternal session = TranslateSessionExternalGPToLocal(result);
                if (session.UserId != null)
                {
                    excepMessage = AppResources.ExistingUserEmail;
                    throw new Exception(AppResources.ExistingUserEmail);
                }
                else
                    return false;
            }
            catch (Exception ex)
            {
                if (string.IsNullOrEmpty(excepMessage)) // Erros genericos
                    throw new Exception(AppResources.CouldNotValidateExistingUserEmail);

                throw ex; // Erros com mensagem definida
            }

        }
Exemplo n.º 2
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;
            }
        }
Exemplo n.º 3
0
        public BusinessLayer.Entities.SessionExternal TranslateSessionExternalGPToLocal(Generated.UserData gt_sessionExt)
        {
            SessionExternal localSession = new SessionExternal();
            try
            {
                if (gt_sessionExt != null)
                {
                    localSession.IsAuthenticated = gt_sessionExt.IsAuthenticated.HasValue ? gt_sessionExt.IsAuthenticated.Value : false;
                    localSession.Name = gt_sessionExt.Name;
                    localSession.SecurityId = gt_sessionExt.SecurityId;
                    localSession.UserId = gt_sessionExt.UserId;
                    localSession.Username = gt_sessionExt.Username;
                    localSession.UserType = UserType.Patient; // TODO Validar esta instrução.. Forçado type = patient? 
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Erro a realizar o convert de UserData para SessionExternal");
                return localSession;
            }

            return localSession;
        }
Exemplo n.º 4
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;
            }
        }