示例#1
0
        public static IList <SecurityCredentialModel> GetCredentialForUser(Guid objectId)
        {
            SecurityCredentialModel.CreateMap();
            IList <SecurityCredential>      att  = SecurityUserHelper.GetCredentialByUserId(objectId);
            IList <SecurityCredentialModel> data =
                Mapper.Map <IList <SecurityCredential>, IList <SecurityCredentialModel> >(att);

            return(data);
        }
示例#2
0
        public ActionResult CredentialUpdatePartial(
            [ModelBinder(typeof(DevExpressEditorsBinder))] SecurityCredentialModel item, Guid objectId)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    SecurityCredentialModel.CreateMap();
                    using (DBEntities context = Settings.CreateDataContext())
                    {
                        SecurityCredential obj =
                            (from p in context.SecurityCredential where p.Id == item.Id select p).FirstOrDefault();
                        if (obj != null)
                        {
                            Mapper.Map(item, obj);
                            obj.SecurityUserId = objectId;
                            if (obj.AuthenticationType == (byte)AuthenticationType.Domain)
                            {
                                obj.PasswordHash = null;
                            }
                            else if (!string.IsNullOrEmpty(item.Password))
                            {
                                obj.PasswordHash = HashHelper.GenerateStringHash(item.Password, obj.PasswordSalt);
                            }
                            context.SaveChanges();
                        }
                    }
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Пожалуйста, исправте все ошибки.";
            }

            return(CredentialPartial(objectId));
        }
示例#3
0
        public ActionResult CredentialAddNewPartial(
            [ModelBinder(typeof(DevExpressEditorsBinder))] SecurityCredentialModel item, Guid objectId)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    SecurityCredentialModel.CreateMap();
                    using (DBEntities context = Settings.CreateDataContext())
                    {
                        SecurityCredential obj = Mapper.Map <SecurityCredentialModel, SecurityCredential>(item);
                        obj.Id             = Guid.NewGuid();
                        obj.SecurityUserId = objectId;
                        obj.PasswordSalt   = HashHelper.GenerateSalt();

                        if (obj.AuthenticationType == (byte)AuthenticationType.Generic &&
                            !string.IsNullOrEmpty(item.Password))
                        {
                            obj.PasswordHash = HashHelper.GenerateStringHash(item.Password, obj.PasswordSalt);
                        }

                        context.AddToSecurityCredential(obj);
                        context.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Пожалуйста, исправте все ошибки.";
            }
            return(CredentialPartial(objectId));
        }