public User GetUserByCredentials(string email, string password)
        {
            var oneTimeClient = new PortalApiClient(_baseUrl, email.EncodeToBase64(), password.EncodeToBase64());

            PortalUserInfo user;

            try
            {
                user = oneTimeClient.GetCurrentUserInfo();
            }
            catch (AuthenticationException)
            {
                return(null);
            }

            if (user == null)
            {
                return(null);
            }

            PortalProfile userProfile = _portalApiClient.GetUserInfoById(user.UserId);

            if (userProfile == null)
            {
                return(null);
            }

            User addUser = GetUserInfo(userProfile);

            return(addUser);
        }
        private User GetUserInfo(PortalProfile profile)
        {
            User adUser = new User
            {
                Id        = profile.UserId,
                FirstName = profile.FirstName,
                LastName  = profile.LastName,
                Email     = profile.Email,
                Role      = UserRole.User,
            };

            return(adUser);
        }
        public User GetUserByID(string guid)
        {
            if (!int.TryParse(guid.Substring(PREFIX.Length), out int id))
            {
                return(null);
            }

            PortalProfile userProfile = _portalApiClient.GetUserInfoById(id);

            User adUser = GetUserInfo(userProfile);

            return(adUser);
        }
Exemplo n.º 4
0
        public PortalProfile GetUserInfoById(int id)
        {
            var response = GetResponse <PortalProfile>(string.Format(PROFILE, id));

            if (response.StatusCode == HttpStatusCode.NotFound)
            {
                return(null);
            }
            else if (response.StatusCode != HttpStatusCode.OK || response.Data == null)
            {
                throw new ApplicationException("Portal API doesn't work: " + response.Content);
            }

            PortalProfile userInfo = response.Data;

            return(userInfo);
        }