Ejemplo n.º 1
0
        public HttpResponseMessage InsertUserMaster([FromBody] clsUserMaster request)
        {
            LoggerFactory.LoggerInstance.LogDebug("Request Started for : " + request.Userid + " Party name :" + request.Umusername);
            HttpResponseMessage response = new HttpResponseMessage();

            try
            {
                UserMasterService objComService = new UserMasterService();
                var objResponse = objComService.InsertUserMaster(request);
                if (objResponse != null && objResponse.ToString() != "")
                {
                    response = Request.CreateResponse(HttpStatusCode.OK, objResponse);
                    LoggerFactory.LoggerInstance.LogDebug("Request End for : " + request.Userid + "   Party name :" + request.Umusername);
                }
                else
                {
                    response = Request.CreateErrorResponse(HttpStatusCode.NotFound, "No detail found  for   Party name : " + request.Umusername + ".");
                }
            }
            catch (Exception ex)
            {
                LoggerFactory.LoggerInstance.LogException(ex);
                response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Error occured while getting   Party name " + request.Umusername + ".");
            }
            return(response);
        }
Ejemplo n.º 2
0
        public string Add(OperateUserMasterModel addModel)
        {
            if (!ModelState.IsValid)
            {
                return(JSONHelper.ToJsonSuggest(ResSuggest.OperateFail + ResMessage.WrongFormat));
            }

            if (_userMasterService.GetCachedModel(addModel.UserID) != null)
            {
                return(JSONHelper.ToJsonSuggest(ResUserMaster.UserIDExist));
            }

            var userMasterModel = new UserMaster();
            var roleUserModel   = new RoleUser();
            var host            = "crm3.chowtaifook.sz";

            if (addModel.UserIDTemplate != "0" && addModel.UserIDTemplate != "")
            {
                var templateRoleUserModel = _roleUserService.GetCachedModel(t => t.UserID == addModel.UserIDTemplate);
                host = _userSiteService.GetUserSite(addModel.UserIDTemplate);   //获取服务器域名

                if (templateRoleUserModel == null)
                {
                    return(JSONHelper.ToJsonSuggest(ResUserMaster.EquelPrivilegeUserID + ResMessage.NotExist));
                }
                else
                {
                    roleUserModel.RoleID = templateRoleUserModel.RoleID;
                }
            }
            else if (string.IsNullOrEmpty(addModel.RoleID))
            {
                roleUserModel.RoleID    = short.Parse(addModel.RoleID);
                addModel.UserIDTemplate = _roleUserService.GetCachedModel(t => t.RoleID == short.Parse(addModel.RoleID)).UserID;
                host = _userSiteService.GetUserSite(addModel.UserIDTemplate);
            }
            else
            {
                return(JSONHelper.ToJsonSuggest(ResUserMaster.PlearsEnterEquelPrivilegeUserIDOrRoleID));
            }

            var randomCode = new RandomCode();

            addModel.Password = randomCode.GetRandomCode("1,2,3,4,5,6,7,8,9", 4) + randomCode.GetRandomCode("A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z", 4);

            userMasterModel = Mapper.Map <OperateUserMasterModel, UserMaster>(addModel);
            //userMasterModel.PasswordExprityDate = DateAndTime.DateAdd("d", 90, DateTime.Now.ToShortDateString());

            userMasterModel.PasswordExprityDate = DateTime.Now.AddDays(90);

            roleUserModel.UserID = addModel.UserID;

            var context       = ResUserMaster.LoginAddress + "http://" + host + "/Login.aspx " + ResUserMaster.UserID + ":" + userMasterModel.UserID + " " + ResUserMaster.Password + ":" + addModel.Password;
            var bllUserMaster = new UserMasterService();

            if (bllUserMaster.AddUserTemplate(userMasterModel, roleUserModel, addModel.UserIDTemplate, "ctfsystem", addModel.EmailAdd, ResUserMaster.COUPriviligeOpen, context, "HTML"))
            {
                return(JSONHelper.ToJsonSuggest(ResSuggest.AddSuccess));
            }
            else
            {
                return(JSONHelper.ToJsonSuggest(ResSuggest.AddFail));
            }
        }
Ejemplo n.º 3
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (httpContext == null)
            {
                throw new ArgumentNullException("httpContext");
            }

            RequestContext requestContext = httpContext.Request.RequestContext;

            if (HttpContext.Current.Session["RoleId"] == null)
            {
                return(false);
            }

            var roleId = new Guid(HttpContext.Current.Session["RoleId"].ToString());

            IPrincipal user = httpContext.User;

            if (!user.Identity.IsAuthenticated)
            {
                return(false);
            }

            if (!requestContext.RouteData.Values.ContainsKey(RouteDataController))
            {
                throw new ApplicationException("RouteDataKey " + RouteDataController + " does not exist in the current RouteData");
            }

            if (!requestContext.RouteData.Values.ContainsKey(RouteDataAction))
            {
                throw new ApplicationException("RouteDataKey " + RouteDataAction + " does not exist in the current RouteData");
            }

            if (!(user.Identity is ClaimsIdentity))
            {
                return(false);
            }

            var username = user.Identity.Name;
            var userInfo = UserMasterService.GetAll().Where(x => x.Username == username).FirstOrDefault();

            if (userInfo == null)
            {
                return(false);
            }

            var UserRole = (from ur in UserRoleMappingService.GetAll().ToList().Where(x => x.UserMasterId == userInfo.UniqueId)
                            join ro in RoleMasterService.GetAll().ToList() on ur.RoleMasterId equals ro.UniqueId
                            where ro.UniqueId == roleId && ro.IsActive == true
                            select ro).FirstOrDefault();

            if (UserRole.Name == "Admin")
            {
                return(true);
            }

            string activity = requestContext.RouteData.Values[RouteDataController].ToString() + "/" + requestContext.RouteData.Values[RouteDataAction].ToString();

            var roleActions = (from ur in RoleActionMappingService.GetAll().ToList()
                               join ro in ActionMasterService.GetAll().ToList() on ur.ActionMasterId equals ro.UniqueId
                               where ur.RoleMasterId == roleId && ro.IsActive == true
                               select ro.AccessCode).ToList();

            return(roleActions.Contains(activity));
        }