示例#1
0
    public bool CheckAuthentication()
    {
        HttpCookie cookie = Request.RequestContext.HttpContext.Request.Cookies[Constants.COOKIE_CRM];

        if (cookie != null)
        {
            FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);
            FormsIdentity identity = new FormsIdentity(ticket);
            UserData udata = UserData.CreateUserData(ticket.UserData);
            AuthenticationProjectPrincipal principal = new AuthenticationProjectPrincipal(identity, udata);

            //return CommonFunc.CheckAuthorized(190, (int)Modules.Question, (int)Permissions.Read);
            return CommonFunc.CheckAuthorized(principal.UserData.UserID, (int)Modules.Question, (int)Permissions.Read);
        }

        return false;
    }
示例#2
0
        /// <summary>
        /// Update user group
        /// </summary>
        /// <param name="objUI"></param>
        /// <returns></returns>
        public Message Update(string id, string userName, string groupId, bool isActive, AuthenticationProjectPrincipal principal)
        {
            Message msg = null;
            try
            {
                if (auDao.CheckExistInAD(userName))
                {
                    UserAdmin user = GetByUserName(userName);
                    if (user == null)
                    {
                        user = new UserAdmin();
                        user.UserName = userName;
                        user.DeleteFlag = false;
                        user.CreateDate = DateTime.Now;
                        user.UpdateDate = DateTime.Now;
                        user.CreatedBy = principal.UserData.UserName;
                        user.UpdatedBy = principal.UserData.UserName;

                        dbContext.UserAdmins.InsertOnSubmit(user);
                        dbContext.SubmitChanges();
                    }

                    int _groupId = int.Parse(groupId);

                    User_Group user_group = GetUser_Group(user.UserAdminId, _groupId);

                    if (user_group == null)
                    {
                        user_group = GetUser_Group(int.Parse(id));
                    }
                    else if(user_group.ID.ToString() != id)
                    {
                        msg = new Message(MessageConstants.E0020, MessageType.Error, "User " + userName + " belong group " + user_group.Group.GroupName, "database");
                    }

                    if (msg == null)
                    {
                        if (user_group != null)
                        {
                            user_group.UserAdminId = user.UserAdminId;
                            user_group.GroupId = int.Parse(groupId);
                            user_group.IsActive = isActive;

                            user_group.UpdateDate = DateTime.Now;
                            user_group.UpdatedBy = principal.UserData.UserName;
                            //Write Log
                            new UserAdminLogDao().WriteLogForUserAdmin(null, user_group, ELogAction.Update);

                            dbContext.SubmitChanges();
                            msg = new Message(MessageConstants.I0001, MessageType.Info, "User " + userName + " belong group " + user_group.Group.GroupName, "updated");
                        }
                        else
                        {
                            msg = new Message(MessageConstants.E0020, MessageType.Error, "User " + userName + " belong group " + user_group.Group.GroupName + " does not", "database");
                        }
                    }
                }
                else
                {
                    msg = new Message(MessageConstants.E0005, MessageType.Error, "User " + userName, "Active Directory");
                }
            }
            catch (Exception)
            {
                msg = new Message(MessageConstants.E0007, MessageType.Error);
            }
            return msg;
        }
示例#3
0
 /// <summary>
 /// Descypt salary follow permission
 /// </summary>
 /// <param name="text"></param>
 /// <param name="principal"></param>
 /// <param name="groupDao"></param>
 /// <param name="userAdminDao"></param>
 /// <returns></returns>
 public static string DescyptSalary(string text, AuthenticationProjectPrincipal principal, GroupDao groupDao, UserAdminDao userAdminDao)
 {
     bool canViewSalary = groupDao.HasPermisionOnModule(
         userAdminDao.GetByUserName(principal.UserData.UserName).UserAdminId, (int)Permissions.Read, (int)Modules.ViewSalaryInfo);
     string result = "";
     if (!string.IsNullOrEmpty(text))
     {
         result = canViewSalary ? EncryptUtil.Decrypt(text) : Constants.PRIVATE_DATA;
     }
     return result;
 }
示例#4
0
        public Message InsertMany(List<string> list_userName, string groupId, bool isActive, AuthenticationProjectPrincipal principal)
        {
            Message msg = null;
            DbTransaction trans = null;
            bool isSuccess = true;
            try
            {
                dbContext.Connection.Open();
                trans = dbContext.Connection.BeginTransaction();
                dbContext.Transaction = trans;

                foreach (string userName in list_userName)
                {
                    msg = Insert(userName, groupId, isActive, principal);
                    if (msg.MsgType == MessageType.Error)
                    {
                        isSuccess = false;
                        break;
                    }
                }
                if (!isSuccess)
                {
                    trans.Rollback();
                }
                else
                {
                    string groupName = new GroupDao().GetById(int.Parse(groupId)).GroupName;
                    msg = new Message(MessageConstants.I0001, MessageType.Info,
                        string.Format("User \"{0}\" belong to group \"{1}\"",
                        string.Join("\"" + Constants.SEPARATE_USER_ADMIN_USERNAME + " \"", list_userName), groupName), "added");
                    trans.Commit();
                }
            }
            catch
            {
                trans.Rollback();
                msg = new Message(MessageConstants.E0007, MessageType.Error);
            }
            return msg;
        }