示例#1
0
        /// <summary>
        ///
        /// </summary>
        protected void loadProfile()
        {
            if (FormsAuthentication.CookiesSupported &&
                HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName] != null)
            {
                try
                {
                    string encryptedValue = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName].Value;

                    if (encryptedValue != null)
                    {
                        int userId = int.Parse(FormsAuthentication.Decrypt(encryptedValue).Name);
                        SignInResponseDTO userProfile = UserDetailsFacade.GetUserRole(userId);

                        if (userProfile != null)
                        {
                            HttpContext.Current.Session.Add(SESSION_USERPROFILE, userProfile);
                        }
                    }
                }
                catch (Exception exc)
                {
                    log.Error(exc);
                }
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="userId"></param>
        public static SignInResponseDTO GetUserRole(int userId)
        {
            SignInResponseDTO retVal = null;

            try
            {
                DataSet ds = new ProjectDB(Utility.ConfigurationHelper.GPD_Connection).GetUserRole(userId);

                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    retVal = new SignInResponseDTO()
                    {
                        Email     = ds.Tables[0].Rows[0]["email"].ToString(),
                        UserId    = userId.ToString(),
                        FirstName = ds.Tables[0].Rows[0]["first_name"].ToString(),
                        LastName  = ds.Tables[0].Rows[0]["last_name"].ToString()
                    };

                    if (ds.Tables.Count == 1)
                    {
                        return(retVal);
                    }

                    foreach (DataRow dataRow in ds.Tables[1].Rows)
                    {
                        retVal.Roles.Add(new UserRoleDTO()
                        {
                            GroupId         = int.Parse(dataRow["group_id"].ToString()),
                            GroupName       = dataRow["GroupName"].ToString(),
                            PartnerId       = dataRow["partner_id"].ToString(),
                            PartnerName     = dataRow["PartnerName"].ToString(),
                            PartnerImageUrl = DBNull.Value.Equals(dataRow["PartnerImageUrl"]) ? ConfigurationHelper.DefaultPartnerImageUrl : dataRow["PartnerImageUrl"].ToString()
                        });
                    }

                    if (retVal.Roles.Count > 0)
                    {
                        retVal.PartnerNames    = retVal.Roles.Select(i => i.PartnerName).Distinct().ToList();
                        retVal.SelectedPartner = retVal.PartnerNames.FirstOrDefault();
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("Unable to get user profile for id: " + userId, ex);
            }

            return(retVal);
        }
示例#3
0
        /// <summary>
        /// Is User has ADMIN role
        /// </summary>
        /// <returns>bool</returns>
        public bool AdminRole()
        {
            try
            {
                // get user profile
                SignInResponseDTO userProfile = GetUserProfile();

                if (userProfile != null)
                {
                    return(userProfile.Roles.Exists(T => T.PartnerName.ToUpper().Contains("ADMIN")));
                }
            }
            catch (Exception exc)
            {
                log.Error(exc);
            }

            return(false);
        }
示例#4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="role"></param>
        /// <param name="partner"></param>
        /// <returns></returns>
        public bool HasRolesForPartner(string role, string partner)
        {
            try
            {
                // get user profile
                SignInResponseDTO userProfile = GetUserProfile();

                if (userProfile != null)
                {
                    return(userProfile.Roles.Exists(i => i.PartnerName.Equals(partner) && i.GroupName.Equals(role)));
                }
            }
            catch (Exception exc)
            {
                log.Error(exc);
            }

            return(false);
        }
示例#5
0
        private async Task <string> GetAccessToken()
        {
            HttpClient client  = new HttpClient();
            string     baseUri = "http://localhost:40000/api/auth/sign-in";

            SignInRequestDTO requestDTO = new SignInRequestDTO {
                username = "******", password = "******"
            };

            var json          = System.Text.Json.JsonSerializer.Serialize(requestDTO);
            var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json");

            var result = await client.PostAsync(baseUri, stringContent);

            SignInResponseDTO resultContent = await System.Text.Json.JsonSerializer.DeserializeAsync <SignInResponseDTO>(await result.Content.ReadAsStreamAsync());


            return(resultContent.token);
        }
示例#6
0
        /// <summary>
        /// Is User assigned to any Roles in the list
        /// </summary>
        /// <returns>bool</returns>
        public bool AnyFromRoles(string[] rolesList)
        {
            try
            {
                // get user profile
                SignInResponseDTO userProfile = GetUserProfile();

                if (userProfile != null)
                {
                    return(userProfile.Roles.Any(T => rolesList.Contains(T.GroupName.ToUpper())));
                }
            }
            catch (Exception exc)
            {
                log.Error(exc);
            }

            return(false);
        }