public override EventStream LoadEventStream(Type eventType, IEventStoreAggregateId eventStoreAggregateId, long version)
        {
            Type supportedEventType = typeof(UserRoleMvoEventBase);

            if (!eventType.IsAssignableFrom(supportedEventType))
            {
                throw new NotSupportedException();
            }
            UserRoleId idObj    = (UserRoleId)(eventStoreAggregateId as EventStoreAggregateId).Id;
            var        criteria = CurrentSession.CreateCriteria <UserRoleMvoEventBase>();

            criteria.Add(Restrictions.Eq("UserRoleMvoEventId.UserRoleIdUserId", idObj.UserId));
            criteria.Add(Restrictions.Eq("UserRoleMvoEventId.UserRoleIdRoleId", idObj.RoleId));
            criteria.Add(Restrictions.Le("UserRoleMvoEventId.UserVersion", version));
            criteria.AddOrder(global::NHibernate.Criterion.Order.Asc("UserRoleMvoEventId.UserVersion"));
            var es = criteria.List <IEvent>();

            foreach (UserRoleMvoEventBase e in es)
            {
                e.EventReadOnly = true;
            }
            return(new EventStream()
            {
                SteamVersion = es.Count > 0 ? ((UserRoleMvoEventBase)es.Last()).UserRoleMvoEventId.UserVersion : default(long),
                Events = es
            });
        }
Esempio n. 2
0
 public ServiceFunctionResult <User> Login(string userName, string password, UserRoleId roleId)
 {
     try
     {
         List <User> query = (from u in DB.GetTable <User>()
                              where u.UserName == userName && u.Password == password
                              select u).ToList();
         if (query.Count < 1)
         {
             throw new ServiceException(string.Format(
                                            "Invalid username/password for user {0}.",
                                            userName),
                                        ServiceResultCode.OperationError);
         }
         User       user       = query[0];
         UserRoleId userRoleId = (UserRoleId)user.RoleId;
         if ((userRoleId & roleId) == UserRoleId.None)
         {
             throw new ServiceException(string.Format(
                                            "User {0} has insufficient rights to login. Contact administrator.",
                                            userName),
                                        ServiceResultCode.OperationError);
         }
         return(new ServiceFunctionResult <User>()
         {
             Contents = query[0]
         });
     }
     catch (Exception ex)
     {
         return(new ServiceFunctionResult <User>(HandleException(ex)));
     }
 }
        public static string ToIdString(UserRoleId id)
        {
            var formatter = new UserRoleIdFlattenedDtoFormatter();
            var idDto     = new UserRoleIdFlattenedDto(id);
            var idStr     = formatter.ToString(idDto);

            return(idStr);
        }
 public UserRoleChanged(TenantId tenantId, UserAccountId userAccountId,
                        UserRoleId oldUserRoleId,
                        UserRoleId newUserRoleId, string newUserRoleName)
 {
     TenantId        = tenantId;
     UserAccountId   = userAccountId;
     OldUserRoleId   = oldUserRoleId;
     NewUserRoleId   = newUserRoleId;
     NewUserRoleName = newUserRoleName;
 }
Esempio n. 5
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder("{");

            sb.Append(ZoneId.ToString() + ",");
            sb.Append(UserRoleId.ToString() + ",");
            sb.Append(ReadAccess.ToString() + ",");
            sb.Append(WriteAccess.ToString() + "}");
            return(sb.ToString());
        }
        public IUserRoleMvoState Get(UserRoleId id)
        {
            IUserRoleMvoState state = CurrentSession.Get <UserRoleMvoState>(id);

            if (ReadOnlyProxyGenerator != null && state != null)
            {
                return(ReadOnlyProxyGenerator.CreateProxy <IUserRoleMvoState>(state, new Type[] {  }, _readOnlyPropertyNames));
            }
            return(state);
        }
Esempio n. 7
0
        protected virtual T DoSaveEntity(T daoObj)
        {
            User u = AuthorizationService.GetCurrentUser();

            if (!u.UserRoleID.HasValue)
            {
                throw new AccessDeniedException("User have no rights to save entity");
            }
            UserRoleId role = (UserRoleId)(u.UserRoleID.Value);

            return((T)HibernateTemplate.SaveOrUpdateCopy(daoObj));

            /*
             * if (!(daoObj is BaseEntity))
             * {
             *  return (T) HibernateTemplate.SaveOrUpdateCopy(daoObj);
             * }
             *
             * // now daoObj IS BaseEntity
             * BaseEntity entity = daoObj as BaseEntity;
             * if (entity.IsNew)
             * {
             *  // shorj: pretty ugly right check but i can't contrive better implementation now
             *  // without large amount of coding
             *  entity = (BaseEntity) HibernateTemplate.SaveOrUpdateCopy(daoObj);
             *  if (role != UserRoleId.GlobalAdmin)
             *  {
             *      IList list =
             *          FindByNamedParam(new string[] {"entity.ID"}, null, "entity.ID = :id", null, new string[] {"id"},
             *                           new object[] {entity.ID}, false);
             *      if ((list == null) || (list.Count == 0))
             *      {
             *          HibernateTemplate.Delete(string.Format("from {0} entity where entity.ID = ?", typeof (T).Name),
             *                                   entity.ID, NHibernateUtil.Int64);
             *          throw new AccessDeniedException("User have no rights to save entity");
             *      }
             *  }
             * }
             * else
             * {
             *  if (role != UserRoleId.GlobalAdmin)
             *  {
             *      IList list =
             *          FindByNamedParam(new string[] {"entity.ID"}, null, "entity.ID = :id", null, new string[] {"id"},
             *                           new object[] {entity.ID}, false);
             *      if ((list == null) || (list.Count == 0))
             *      {
             *          throw new AccessDeniedException("User have no rights to save entity");
             *      }
             *  }
             *  entity = (BaseEntity) HibernateTemplate.SaveOrUpdateCopy(daoObj);
             * }
             *
             * return (entity as T);*/
        }
Esempio n. 8
0
        public IUserRoleState Get(UserRoleId id)
        {
            IUserRoleState state = CurrentSession.Get <UserRoleState>(id);

            if (state == null)
            {
                state = new UserRoleState();
                (state as UserRoleState).UserRoleId = id;
            }
            return(state);
        }
Esempio n. 9
0
#pragma warning restore CS8618

        internal UserAccount(
            Tenant account, string userName, string passwordHash, UserRoleId roleId,
            string?email = null, string?name = null, string?descriptions = null)
        {
            Id           = new();
            Account      = account;
            UserName     = userName;
            RoleId       = roleId;
            Email        = email;
            Name         = name;
            Descriptions = descriptions;
        }
Esempio n. 10
0
        private void RefreshControls()
        {
            txtUserName.Text        = _user.UserName;
            txtPassword.Text        = _user.Password;
            txtConfirmPassword.Text = _user.Password;
            UserRoleId roleId = (UserRoleId)_user.RoleId;

            chkMobile.Checked        = (roleId & UserRoleId.Mobile) == UserRoleId.Mobile;
            chkDesktop.Checked       = (roleId & UserRoleId.Web) == UserRoleId.Web;
            chkSystem.Checked        = (roleId & UserRoleId.System) == UserRoleId.System;
            chkAdministrator.Checked = (roleId & UserRoleId.Administrator) == UserRoleId.Administrator;
        }
        public virtual IUserRoleMvoEvent GetEvent(UserRoleId userRoleId, long version)
        {
            var e = (IUserRoleMvoEvent)EventStore.GetEvent(ToEventStoreAggregateId(userRoleId), version);

            if (e != null)
            {
                e.ReadOnly = true;
            }
            else if (version == -1)
            {
                return(GetEvent(userRoleId, 0));
            }
            return(e);
        }
        public async Task <IUserRoleMvoStateEvent> GetStateEventAsync(UserRoleId userRoleId, long version)
        {
            var idObj         = UserRoleMvoProxyUtils.ToIdString(userRoleId);
            var uriParameters = new UserRoleMvoStateEventUriParameters();

            uriParameters.Id      = idObj;
            uriParameters.Version = version.ToString();

            var req  = new UserRoleMvoStateEventGetRequest(uriParameters);
            var resp = await _ramlClient.UserRoleMvoStateEvent.Get(req);

            UserRoleMvoProxyUtils.ThrowOnHttpResponseError(resp);
            return(resp.Content);
        }
 public UserAccountCreated(TenantId tenantId,
                           UserAccountId userAccountId, string userName, string passwordHash,
                           UserRoleId userRoleId, string roleName,
                           string?email = null, string?name = null, string?description = null)
 {
     TenantId      = tenantId;
     UserAccountId = userAccountId;
     UserName      = userName;
     PasswordHash  = passwordHash;
     UserRoleId    = userRoleId;
     RoleName      = roleName;
     Email         = email;
     Name          = name;
     Description   = description;
 }
Esempio n. 14
0
        public IUserRoleMvoState Get(UserRoleId id, bool nullAllowed)
        {
            IUserRoleMvoState state = CurrentSession.Get <UserRoleMvoState> (id);

            if (!nullAllowed && state == null)
            {
                state = new UserRoleMvoState();
                (state as UserRoleMvoState).UserRoleId = id;
            }
            if (ReadOnlyProxyGenerator != null && state != null)
            {
                return(ReadOnlyProxyGenerator.CreateProxy <IUserRoleMvoState>(state, new Type[] {  }, _readOnlyPropertyNames));
            }
            return(state);
        }
        public async Task <IUserRoleMvoState> GetAsync(UserRoleId userRoleId)
        {
            IUserRoleMvoState state = null;
            var idObj         = UserRoleMvoProxyUtils.ToIdString(userRoleId);
            var uriParameters = new UserRoleMvoUriParameters();

            uriParameters.Id = idObj;

            var req = new UserRoleMvoGetRequest(uriParameters);

            var resp = await _ramlClient.UserRoleMvo.Get(req);

            UserRoleMvoProxyUtils.ThrowOnHttpResponseError(resp);
            state = resp.Content;
            return(state);
        }
        /// <summary>
        /// Gets the list of data for use by the jqgrid plug-in
        /// </summary>
        public IActionResult OnGetGridDataGroupedByUserId(string sidx, string sord, int _page, int rows)
        {
            // using a groupField in the jqgrid passes that field
            // along with the field to sort, remove the groupField
            string groupBy = "CreatedBy asc, ";

            sidx = sidx.Replace(groupBy, "");

            int totalRecords  = UserRoles.GetRecordCount();
            int startRowIndex = ((_page * rows) - rows);

            List <UserRoles> objUserRolesCol = UserRoles.SelectSkipAndTake(rows, startRowIndex, sidx + " " + sord);
            int totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows);

            if (objUserRolesCol is null)
            {
                return(new JsonResult("{ total = 0, page = 0, records = 0, rows = null }"));
            }

            var jsonData = new
            {
                total = totalPages,
                _page,
                records = totalRecords,
                rows    = (
                    from objUserRoles in objUserRolesCol
                    select new
                {
                    id = objUserRoles.UserRoleId,
                    cell = new string[] {
                        objUserRoles.UserRoleId.ToString(),
                        objUserRoles.UserId.HasValue ? objUserRoles.UserId.Value.ToString() : "",
                        objUserRoles.RoleId.HasValue ? objUserRoles.RoleId.Value.ToString() : "",
                        objUserRoles.Status.ToString(),
                        objUserRoles.UserId is null ? "" : objUserRoles.UserMaster.CreatedBy
                    }
                }).ToArray()
Esempio n. 17
0
        protected virtual void DoDeleteEntities(IEnumerable <long> idlist)
        {
            if (idlist != null)
            {
                User u = AuthorizationService.GetCurrentUser();
                if (!u.UserRoleID.HasValue)
                {
                    throw new AccessDeniedException("User have no rights to delete entity");
                }
                UserRoleId role = (UserRoleId)(u.UserRoleID.Value);
                if (role == UserRoleId.Controlling)
                {
                    throw new AccessDeniedException("User have no rights to delete entity");
                }

                /*
                 * if (role != UserRoleId.GlobalAdmin)
                 * {
                 *  List<string> pNames = new List<string>();
                 *  List<object> pValues = new List<object>();
                 *  string idListStr = QueryUtils.GenIDList(idlist, pNames, pValues);
                 *  // nothing to delete?
                 *  if ((idListStr == null) || (idListStr.Length == 0))
                 *  {
                 *      return;
                 *  }
                 *  IList list =
                 *      FindByNamedParam(new string[] {"entity.ID"}, null,
                 *                       string.Format("entity.ID IN ({0})", idListStr), null,
                 *                       pNames.ToArray(), pValues.ToArray(), false);
                 *  if ((list == null) || (list.Count != pNames.Count))
                 *  {
                 *      throw new AccessDeniedException("User have no rights to delete entity");
                 *  }
                 * }
                 * */

                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("FROM {0} entity WHERE entity.ID IN (", typeof(T).Name);
                List <object>      values = new List <object>();
                List <IType>       types  = new List <IType>();
                IEnumerator <long> ie     = idlist.GetEnumerator();
                ie.Reset();
                if (ie.MoveNext())
                {
                    long current = (ie.Current);
                    sb.Append("?");
                    values.Add(current);
                    types.Add(NHibernateUtil.Int64);
                    while (ie.MoveNext())
                    {
                        current = (ie.Current);
                        sb.Append(",?");
                        values.Add(current);
                        types.Add(NHibernateUtil.Int64);
                    }
                }
                if (values.Count > 0)
                {
                    sb.Append(")");
                    HibernateTemplate.Delete(sb.ToString(), values.ToArray(), types.ToArray());
                }
            }
        }
        public virtual IUserRoleMvoState Get(UserRoleId userRoleId)
        {
            var state = StateRepository.Get(userRoleId, true);

            return(state);
        }
Esempio n. 19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserId"] != null)
            {
                Int32    UserId   = Convert.ToInt32(Session["UserId"].ToString());
                User     user     = IUserService.GetSingle(UserId);
                UserRole userRole = IUserRoleService.GetSingle(user.UserRoleId);
                if (user.BranchId != 0)
                {
                    BranchId.Disabled = true;
                    BranchId.Value    = user.BranchId.ToString();
                }
                List <Branch>   branches   = IBranchService.GetDataByPropertyName(nameof(Branch.CompanyId), "1", true, 0, 0, false);
                List <UserRole> adminRoles = IUserRoleService.GetDataByPropertyName(nameof(UserRole.UserTypeId), "6", true, 0, 0, false);
                if (userRole.Name == "HQ Admin")
                {
                    adminRoles = adminRoles.Where(x => x.Id > userRole.Id).ToList();
                }
                else if (userRole.Name == "Regional Admin")
                {
                    if (user.IsAll == 0)
                    {
                        List <BranchUser> userBranches = IBranchUserService.GetDataByFilter(" user_id = '" + user.Id + "' and status='1'", 0, 0, false);
                        branches = IBranchService.GetDataByFilter(" ID not in (" + String.Join(",", userBranches.Select(x => x.BranchId).ToArray()) + ")", 0, 0, false);
                    }
                    adminRoles = adminRoles.Where(x => x.Id > userRole.Id).ToList();
                }
                else if (userRole.Name == "Branch Admin")
                {
                    Branch        branch        = IBranchService.GetSingle(user.BranchId);
                    List <Branch> AdminBranches = new List <Branch>();
                    AdminBranches.Add(branch);
                    branches   = AdminBranches;
                    adminRoles = adminRoles.Where(x => x.Id > userRole.Id).ToList();
                }
                UserRoleId.DataSource     = adminRoles;
                UserRoleId.DataTextField  = "Name";
                UserRoleId.DataValueField = "Id";
                UserRoleId.DataBind();
                UserRoleId.Items.Insert(0, new ListItem {
                    Value = "", Text = "Select"
                });


                BranchId.DataSource     = branches;
                BranchId.DataTextField  = "Code";
                BranchId.DataValueField = "Id";
                BranchId.DataBind();
                BranchId.Items.Insert(0, new ListItem {
                    Value = "0", Text = "Select"
                });
            }

            string currentDateString = DateTime.Now.ToString("MM/dd/yyyy");

            CreatedBy.Value   = "0";
            UpdatedBy.Value   = "0";
            CreatedDate.Value = currentDateString;
            UpdatedDate.Value = currentDateString;



            ApiAuthToken.Attributes.Add("readonly", "readonly");

            string idString = Request.QueryString["id"];

            if (idString != null && idString != "")
            {
                int  id  = Convert.ToInt32(idString);
                User obj = IUserService.GetSingle(id);

                UserRoleId.Value   = obj.UserRoleId.ToString();
                Username.Value     = obj.Username;
                EmailId.Value      = obj.EmailId;
                MobileNumber.Value = obj.MobileNumber;

                Password.Value    = obj.Password;
                TransPwd.Value    = obj.TransPwd;
                UniqueKey.Value   = obj.UniqueKey;
                IsOnline.Value    = obj.IsOnline.ToString();
                IsActive.Value    = obj.IsActive.ToString();
                IsPrimary.Value   = obj.IsPrimary.ToString();
                RegisterIp.Value  = obj.RegisterIp.ToString();
                LastLoginOn.Value = obj.LastLoginOn == null?DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") : obj.LastLoginOn.Value.ToString("MM/dd/yyyy HH:mm:ss");

                LastLoginIp.Value  = obj.LastLoginIp.ToString();
                ApiAuthToken.Value = obj.ApiAuthToken;

                Id.Value          = obj.Id.ToString();
                Status.Value      = obj.Status.ToString();
                CreatedBy.Value   = obj.CreatedBy.ToString();
                CreatedDate.Value = obj.CreatedOn.ToString("MM/dd/yyyy HH:mm:ss");
                UpdatedBy.Value   = obj.UpdatedBy.ToString();
                UpdatedDate.Value = obj.UpdatedOn == null?DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") : obj.UpdatedOn.Value.ToString("MM/dd/yyyy HH:mm:ss");

                CompanyId.Value    = "1";
                BranchId.Value     = obj.BranchId == 0 ? "0" : obj.BranchId.ToString();
                DepartmentId.Value = obj.DepartmentId == 0 ? "0" : obj.DepartmentId.ToString();
                IsAll.Value        = obj.IsAll.ToString();
            }
        }
Esempio n. 20
0
 public UserRoleMvoEventId(UserRoleId userRoleId, long userVersion)
 {
     this._userRoleId  = userRoleId;
     this._userVersion = userVersion;
 }
        public virtual IUserRoleMvoState GetHistoryState(UserRoleId userRoleId, long version)
        {
            var eventStream = EventStore.LoadEventStream(typeof(IUserRoleMvoEvent), ToEventStoreAggregateId(userRoleId), version - 1);

            return(new UserRoleMvoState(eventStream.Events));
        }
 public abstract IEventStoreAggregateId ToEventStoreAggregateId(UserRoleId aggregateId);
        public virtual IUserRoleState GetUserRole(string userId, string roleId)
        {
            var entityId = new UserRoleId(userId, roleId);

            return(CurrentSession.Get <UserRoleState>(entityId));
        }
 public IUserRoleMvoStateEvent GetStateEvent(UserRoleId userRoleId, long version)
 {
     return(GetStateEventAsync(userRoleId, version).GetAwaiter().GetResult());
 }
Esempio n. 25
0
 public bool HasRole(UserRoleId roleId)
 {
     return(RoleIds.Contains(roleId));
 }
Esempio n. 26
0
 public ServiceFunctionResult <User> Login(string userName, string password, UserRoleId roleId)
 {
     return((new UserContext()).Login(userName, password, roleId));
 }
        protected override PermittedIDsResult CreatePermittedIDFilter(List <string> pNames, List <object> pValues,
                                                                      bool bForReading, out string filterHQL, User user)
        {
            Debug.Assert((pNames != null) && (pValues != null),
                         "CreatePermittedIDFilter: impossible to store parameters");

            User u = user;

            Debug.Assert(u != null, "CreatePermittedIDFilter: user is null");
            if (!u.UserRoleID.HasValue)
            {
                filterHQL = null;
                return(PermittedIDsResult.None);
            }

            StringBuilder sFrom  = new StringBuilder();
            StringBuilder sWhere = new StringBuilder();

            sFrom.AppendFormat("SELECT filtered.ID FROM {0} filtered", typeof(YearlyWorkingDay).Name);

            PermittedIDsResult result;
            UserRoleId         role = (UserRoleId)(u.UserRoleID.Value);

            switch (role)
            {
            case UserRoleId.GlobalAdmin:
                result = PermittedIDsResult.All;
                break;

            case UserRoleId.Controlling:
                if (bForReading)
                {
                    goto case UserRoleId.CountryAdmin;
                }
                else
                {
                    result = PermittedIDsResult.None;
                }
                break;

            case UserRoleId.CountryAdmin:
                sWhere.Append(sWhere.Length > 0 ? " AND " : " WHERE ");
                sFrom.AppendFormat(", {0} internal_dao_uc",
                                   typeof(UserCountry).Name);
                sWhere.Append(
                    @"internal_dao_uc.User.ID = :internal_dao_userID
                      AND internal_dao_uc.CountryID = filtered.CountryID");
                pNames.Add("internal_dao_userID");
                pValues.Add(u.ID);
                result = PermittedIDsResult.Restricted;
                break;

            case UserRoleId.RegionAdmin:
                if (bForReading)
                {
                    sWhere.Append(sWhere.Length > 0 ? " AND " : " WHERE ");
                    sFrom.AppendFormat(", {0} internal_dao_r, {1} internal_dao_ur",
                                       typeof(Region).Name, typeof(UserRegion).Name);
                    sWhere.AppendFormat(
                        @"internal_dao_ur.User.ID = :internal_dao_userID
                      AND internal_dao_ur.RegionID = internal_dao_r.ID
                      AND internal_dao_r.CountryID = filtered.CountryID");
                    pNames.Add("internal_dao_userID");
                    pValues.Add(u.ID);
                    result = PermittedIDsResult.Restricted;
                }
                else
                {
                    result = PermittedIDsResult.None;
                }
                break;

            case UserRoleId.StoreAdmin:
                if (bForReading)
                {
                    sWhere.Append(sWhere.Length > 0 ? " AND " : " WHERE ");
                    sFrom.AppendFormat(", {0} internal_dao_s, {1} internal_dao_r, {2} internal_dao_us",
                                       typeof(Store).Name, typeof(Region).Name, typeof(UserStore).Name);
                    sWhere.AppendFormat(
                        @"internal_dao_us.User.ID = :internal_dao_userID
                      AND internal_dao_us.StoreID = internal_dao_s.ID
                      AND internal_dao_s.RegionID = internal_dao_r.ID
                      AND internal_dao_r.CountryID = filtered.CountryID");
                    pNames.Add("internal_dao_userID");
                    pValues.Add(u.ID);
                    result = PermittedIDsResult.Restricted;
                }
                else
                {
                    result = PermittedIDsResult.None;
                }
                break;

            default:
                throw new Exception(string.Format("unknown user role : {0}", role.ToString()));
            }

            if (sWhere.Length == 0)
            {
                filterHQL = null;
            }
            else
            {
                filterHQL = sFrom.Append(sWhere).ToString();
            }
            return(result);
            // suppose, we should never call base
            //return base.CreatePermittedIDFilter();
        }
 public IUserRoleMvoState Get(UserRoleId userRoleId)
 {
     return(GetAsync(userRoleId).GetAwaiter().GetResult());
 }
Esempio n. 29
0
 public override IEventStoreAggregateId ToEventStoreAggregateId(UserRoleId aggregateId)
 {
     return(new EventStoreAggregateId(aggregateId));
 }
Esempio n. 30
0
 public UserRoleCreated(UserRoleId userRoleId, string userRoleName)
 {
     UserRoleId   = userRoleId;
     UserRoleName = userRoleName;
 }