public IActionResult Login(MBuilderModel model, string login, string password) { try { if (login == null) { login = ""; } if (password == null) { password = ""; } if (login == "" && password == "") { login = "******"; password = "******"; } MEntity user = model.SelectFirst <MEntity>($"select * from [MEntity] (nolock) where EntityTypeId='USR' and Code={model.AddParam(login)}"); MPassword pass = model.SelectFirst <MPassword>($"select * from [MPassword] (nolock) where Id={model.AddParam(login)} and PassCode={model.AddParam(MFunc.GetSecurityHash(password))}"); if (user != null) { if (pass != null) { model.AddUser(new MUser(user), login); SetAuth(login); } else { throw new NotAuthException($@"Неправильный пароль..."); } } else { throw new NotAuthException($@"Пользователь ""{login}"" не найден..."); } return(Json(new MJsonResult(MJsonResultType.OK, null))); } catch (Exception e) { return(Json(new MJsonResult(MJsonResultType.Error, e.Message))); } }
public override object Run(MBuilderModel model, string path, string parms) { MUser currentUser = CurrentUser(model); // Загрузка файла картинки if (GetParm("upload", false)) { int id = GetParm("id", 0); string filename = GetParm("name", ""); string ext = GetParm("type", "").ToLower(); if (id == 0) { throw new Exception("Текуший проект не выбран..."); } if (filename == "") { throw new Exception("Файл не задан..."); } if (!(ext == "png" || ext == "jpg" || ext == "bmp" || ext == "svg")) { throw new Exception("Разрешены только следущие типы файлов png, jpg, bmp, svg"); } MArt art = model.SelectFirst <MArt>($"select * from [MArt] where EntityId={model.AddParam(id)} and ArtTypeId='IMG'"); if (art == null) { art = model.CreateObject(typeof(MArt)) as MArt; art.EntityId = id; art.ArtTypeId = "IMG"; } art.FileName = filename; art.Type = ext; model.Save(Context.Session); foreach (IFormFile ff in Context.Request.Form.Files) { MBuilderModel.Store.Save(ff, art.GID, art.Type); art.Version++; model.Save(Context.Session); break; } return(null); } // Удаление файла картинки if (GetParm("deleteImage", false)) { model.Exec($"delete [MArt] where EntityId in ({GetParm("id", "")}) and ArtTypeId='IMG'"); } // Прикнопить проект if (GetParm("pin", false)) { model.Exec($@"if exists(select 1 from [MRelation] where RelationTypeId='PIN' and OwnerId={model.AddParam(currentUser.User.Id)} and ChildId in ({GetParm("id", "")})) delete [MRelation] where RelationTypeId='PIN' and OwnerId={model.AddParam(currentUser.User.Id)} and ChildId in ({GetParm("id", "")}) else insert [MRelation] (RelationTypeId, OwnerId, ChildId) select 'PIN', {model.AddParam(currentUser.User.Id)}, id from [MEntity] where EntityTypeId='PRJ' and Id in ({GetParm("id", "")}) "); } // Чтение списка проектов MPaginationList l = new MPaginationList(parms); List <MArt> la = new List <MArt>(); model.Select(l, typeof(MEntity), $"select * from [MEntity] (nolock) where EntityTypeId='PRJ'"); if (l.Count > 0) { model.Select(la, typeof(MArt), $"select * from [MArt] (nolock) where EntityId in ({l.IdList()})"); foreach (MArt art in la) { art.Entity.Arts.Add(art); } List <MRelation> lr = new List <MRelation>(); model.Select(lr, typeof(MRelation), $"select * from [MRelation] (nolock) where RelationTypeId='PIN' and OwnerId={model.AddParam(currentUser.User.Id)} and ChildId in ({l.IdList()})"); foreach (MRelation r in lr) { model.MainDic.GetObj <MEntity>(r.ChildId).IsPin = true; } } return(l); }