public static void SaveBlocksData(FrontEditorContext _context, int projectId, List <EditorBaseViewModel> blocks)
        {
            EditorModelData editorData = GetProjectEditorData(_context, projectId);

            editorData.Blocks = blocks;
            SaveProjectEditorData(_context, projectId, editorData);
        }
        public static void SaveCustomCss(FrontEditorContext _context, int projectId, string customCss)
        {
            EditorModelData editorData = GetProjectEditorData(_context, projectId);

            editorData.CustomCss = customCss;
            SaveProjectEditorData(_context, projectId, editorData);
        }
        internal static void SaveProjectHeaderData(FrontEditorContext _context, ProjectHeaderDataViewModel model)
        {
            EditorModelData editorData = GetProjectEditorData(_context, model.ProjectIdForBaseDatas);

            editorData.Title       = model.TitleForBaseDatas;
            editorData.Description = model.Description;
            SaveProjectEditorData(_context, model.ProjectIdForBaseDatas, editorData);
        }
        public static UserViewModel GetUser(FrontEditorContext _context, int uId)
        {
            User user     = _context.Users.Where(x => x.Id == uId).FirstOrDefault();
            int  projects = _context.Projects.Where(x => x.Owner == user).Count();
            IdentityUserRole <int> urole = _context.UserRoles.Where(x => x.UserId == user.Id).FirstOrDefault();

            return(new UserViewModel(user, urole.RoleId, projects));
        }
Example #5
0
 public AccountController(
     UserManager <User> userManager,
     SignInManager <User> signInManager,
     ILogger <AccountController> logger,
     IConfiguration config,
     FrontEditorContext context) : base(logger, config, context)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
 }
        public static void RemoveUser(FrontEditorContext _context, int uId)
        {
            User           user     = _context.Users.Where(x => x.Id == uId).FirstOrDefault();
            List <Project> projects = _context.Projects.Where(x => x.Owner == user).ToList();

            foreach (Project proj in projects)
            {
                _context.Projects.Remove(proj);
            }
            _context.Users.Remove(user);
            _context.SaveChanges();
        }
        public static UserViewModel SaveUserProfile(FrontEditorContext _context, UserViewModel model)
        {
            User user = _context.Users.Where(x => x.Id == model.UserId).FirstOrDefault();

            user.DisplayName        = model.DisplayName;
            user.UserName           = model.UserName;
            user.NormalizedUserName = model.UserName.ToUpper();
            user.Email           = model.Email;
            user.NormalizedEmail = model.Email.ToUpper();
            _context.SaveChanges();
            return(new UserViewModel(user, model.RoleId));
        }
        public static async Task <PasswordResetViewModel> PasswordReset(FrontEditorContext _context, UserManager <User> _userManager, PasswordResetViewModel model)
        {
            User user = _context.Users.Where(
                x => x.Email == model.Email &&
                x.UserName == model.UserName).FirstOrDefault();

            if (user == null)
            {
                model.ErrorText += "Felhasználó nem található!";
            }
            else
            {
                await _userManager.RemovePasswordAsync(user);

                var result = await _userManager.AddPasswordAsync(user, model.Password);

                if (!result.Succeeded)
                {
                    foreach (var error in result.Errors)
                    {
                        if (error.Code == "PasswordTooShort")
                        {
                            model.ErrorText += "A jelszó legalább 6 karakter!<br />";
                        }
                        else if (error.Code == "PasswordRequiresNonAlphanumeric")
                        {
                            model.ErrorText += "A jelszó tartalmaz legalább egy nem alfanumerikus karaktert!<br />";
                        }
                        else if (error.Code == "PasswordRequiresDigit")
                        {
                            model.ErrorText += "A jelszó legalább egy számot tartalmaz!<br />";
                        }
                        else if (error.Code == "PasswordRequiresUpper")
                        {
                            model.ErrorText += "A jelszó legalább egy nagybetűt tartalmaz!<br />";
                        }
                        else if (error.Code == "PasswordRequiresLower")
                        {
                            model.ErrorText += "A jelszó legalább egy kisbetűt tartalmaz!<br />";
                        }
                        else
                        {
                            model.ErrorText += error.Description + "<br />";
                        }
                    }
                }
            }
            return(model);
        }
        public static EditorViewModel EditorData(FrontEditorContext _context, int projectId, string rootFolder)
        {
            EditorViewModel editor  = new EditorViewModel();
            Project         project = _context.Projects.Where(x => x.Id == projectId).FirstOrDefault();

            if (project == null)
            {
                return(editor);
            }
            editor.ProjectData = new ProjectViewModel(project);
            editor.EditorData  = GetProjectEditorData(_context, projectId);
            editor.ImageList   = GetProjectImageList(projectId, rootFolder);

            return(editor);
        }
        public static void SetProjectStatus(FrontEditorContext _context, int projectId, ProjectStatus status, bool addExport = false)
        {
            Project project = _context.Projects.Where(x => x.Id == projectId).FirstOrDefault();

            if (project != null)
            {
                project.Status = status;
                if (addExport)
                {
                    project.ExportCount++;
                }
                _context.Update(project);
                _context.SaveChanges();
            }
        }
        public static EditorModelData GetProjectEditorData(FrontEditorContext _context, int projectId)
        {
            ProjectJSON data = _context.ProjectJSONDatas.Where(x => x.ProjectId == projectId).FirstOrDefault();

            if (data == null)
            {
                data = new ProjectJSON()
                {
                    ProjectId   = projectId,
                    ProjectData = parser.SerializeData(new EditorModelData())
                };
                _context.Add(data);
                _context.SaveChanges();
            }
            return(parser.DeserializeData(data.ProjectData));
        }
        public static async Task <PasswordChangeViewModel> ChangePassword(FrontEditorContext _context, UserManager <User> _userManager, System.Security.Claims.ClaimsPrincipal User, PasswordChangeViewModel model)
        {
            User user = await _userManager.GetUserAsync(User);

            await _userManager.RemovePasswordAsync(user);

            var result = await _userManager.AddPasswordAsync(user, model.NewPassword);

            if (result.Succeeded)
            {
                model = new PasswordChangeViewModel()
                {
                    PasswordChanged = true
                };
            }
            else
            {
                foreach (var error in result.Errors)
                {
                    if (error.Code == "PasswordTooShort")
                    {
                        model.ErrorText += "A jelszó legalább 6 karakter!<br />";
                    }
                    else if (error.Code == "PasswordRequiresNonAlphanumeric")
                    {
                        model.ErrorText += "A jelszó tartalmaz legalább egy nem alfanumerikus karaktert!<br />";
                    }
                    else if (error.Code == "PasswordRequiresDigit")
                    {
                        model.ErrorText += "A jelszó legalább egy számot tartalmaz!<br />";
                    }
                    else if (error.Code == "PasswordRequiresUpper")
                    {
                        model.ErrorText += "A jelszó legalább egy nagybetűt tartalmaz!<br />";
                    }
                    else if (error.Code == "PasswordRequiresLower")
                    {
                        model.ErrorText += "A jelszó legalább egy kisbetűt tartalmaz!<br />";
                    }
                    else
                    {
                        model.ErrorText += error.Description + "<br />";
                    }
                }
            }
            return(model);
        }
        public static void DeleteProject(FrontEditorContext _context, int projectId, int userId)
        {
            Project project = _context.Projects.Where(x => x.Id == projectId).FirstOrDefault();

            if (!UsersBL.UserIsAdmin(_context, userId) && project.Owner.Id != userId)
            {
                throw new Exception("Nincs jogosultsága a kért művelet elvégzéséhez!");
            }
            ProjectJSON jsondata = _context.ProjectJSONDatas.Where(x => x.ProjectId == projectId).FirstOrDefault();

            if (jsondata != null)
            {
                _context.ProjectJSONDatas.Remove(jsondata);
            }
            _context.Projects.Remove(project);
            _context.SaveChanges();
        }
        public static ProjectListViewModel ProjectListModel(FrontEditorContext _context, bool isAdmin, bool adminMode, int userId, string redirectTo = "")
        {
            ProjectListViewModel project = new ProjectListViewModel();

            project.AdminMode      = isAdmin;
            project.ShowAllProject = isAdmin && adminMode;
            project.RedirectTo     = redirectTo;
            if (project.ShowAllProject)
            {
                project.ProjectList = _context.Projects.Select(x => new ProjectViewModel(x)).ToList();
            }
            else
            {
                project.ProjectList = _context.Projects.Where(x => x.Owner.Id == userId).Select(x => new ProjectViewModel(x)).ToList();
            }
            return(project);
        }
        public static UserViewModel EditUserProfile(FrontEditorContext _context, UserViewModel model)
        {
            User user = _context.Users.Where(x => x.Id == model.UserId).FirstOrDefault();

            user.DisplayName        = model.DisplayName;
            user.UserName           = model.UserName;
            user.NormalizedUserName = model.UserName.ToUpper();
            user.Email           = model.Email;
            user.NormalizedEmail = model.Email.ToUpper();
            IdentityUserRole <int> userRole = _context.UserRoles.Where(x => x.UserId == model.UserId).FirstOrDefault();

            userRole.RoleId = model.RoleId;
            _context.SaveChanges();
            return(new UserViewModel(user, model.RoleId)
            {
                DatasChanged = true
            });
        }
        public static string ExportProjectJson(FrontEditorContext _context, int projectId, string rootPath)
        {
            ProjectJSON data = _context.ProjectJSONDatas.Where(x => x.ProjectId == projectId).FirstOrDefault();

            if (data == null)
            {
                throw new Exception("Projekt nem található!");
            }

            string fileName     = projectId + "-export-" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + ".zip";
            string exportPath   = rootPath + "/export/" + fileName;
            string tempPath     = rootPath + "/export/" + projectId + "-export-" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + "/";
            string templatePath = rootPath + "/export-template/";
            string imagesPath   = rootPath + "/images/projects/" + projectId + "/";

            //Create temp folder and copy template and images
            System.IO.Directory.CreateDirectory(tempPath);
            foreach (string dirPath in Directory.GetDirectories(templatePath, "*", SearchOption.AllDirectories))
            {
                Directory.CreateDirectory(dirPath.Replace(templatePath, tempPath));
            }
            foreach (string newPath in Directory.GetFiles(templatePath, "*.*", SearchOption.AllDirectories))
            {
                File.Copy(newPath, newPath.Replace(templatePath, tempPath), true);
            }
            if (Directory.Exists(imagesPath))
            {
                foreach (string newPath in Directory.GetFiles(imagesPath, "*.*", SearchOption.AllDirectories))
                {
                    File.Copy(newPath, newPath.Replace(imagesPath, tempPath + "images/"), true);
                }
            }
            //Create template json file
            using (FileStream fs = File.Create(tempPath + "project.json"))
            {
                Byte[] html = new UTF8Encoding(true).GetBytes(data.ProjectData);
                fs.Write(html, 0, html.Length);
            }
            //Create .zip file
            ZipFile.CreateFromDirectory(tempPath, exportPath);
            //Remove temp folder
            Directory.Delete(tempPath, true);
            return("/export/" + fileName);
        }
 public static void ImportProjectFromZip(FrontEditorContext _context, int projectId, string rootPath, string zipPath)
 {
     try
     {
         string tempPath   = rootPath + "/import/" + projectId + "-import-" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + "/";
         string imagesPath = rootPath + "/images/projects/" + projectId + "/";
         ZipFile.ExtractToDirectory(zipPath, tempPath);
         //Parse json and Save it
         string          importedData = System.IO.File.ReadAllText(tempPath + "project.json");
         EditorModelData data         = parser.DeserializeData(importedData);
         ProjectJSON     jsonData     = _context.ProjectJSONDatas.Where(x => x.ProjectId == projectId).FirstOrDefault();
         if (jsonData == null)
         {
             jsonData = new ProjectJSON()
             {
                 ProjectId   = projectId,
                 ProjectData = parser.SerializeData(data)
             };
             _context.Add(jsonData);
         }
         else
         {
             jsonData.ProjectData = parser.SerializeData(data);
             _context.Update(jsonData);
         }
         _context.SaveChanges();
         //Empty files folder and copy new files to files folder
         foreach (string file in Directory.GetFiles(imagesPath, "*.*", SearchOption.AllDirectories))
         {
             File.Delete(file);
         }
         foreach (string file in Directory.GetFiles(tempPath + "images/", "*.*", SearchOption.AllDirectories))
         {
             File.Copy(file, file.Replace(imagesPath, tempPath), true);
         }
         //Delete import files from temp folder
         Directory.Delete(tempPath, true);
     }
     catch (Exception ex)
     {
         throw new Exception("Hiba történta projekt impotálása közben!");
     }
 }
        public static List <UserViewModel> GetUserList(FrontEditorContext _context)
        {
            List <UserViewModel> response = new List <UserViewModel>();
            List <User>          users    = _context.Users.ToList();

            foreach (User user in users)
            {
                int projects = _context.Projects.Where(x => x.Owner == user).Count();
                IdentityUserRole <int> urole = _context.UserRoles.Where(x => x.UserId == user.Id).FirstOrDefault();
                if (urole == null)
                {
                    response.Add(new UserViewModel(user, 2, projects));
                }
                else
                {
                    response.Add(new UserViewModel(user, urole.RoleId, projects));
                }
            }
            return(response);
        }
        public static void SaveProjectEditorData(FrontEditorContext _context, int projectId, EditorModelData saveData)
        {
            ProjectJSON data = _context.ProjectJSONDatas.Where(x => x.ProjectId == projectId).FirstOrDefault();

            if (data == null)
            {
                data = new ProjectJSON()
                {
                    ProjectId   = projectId,
                    ProjectData = parser.SerializeData(saveData)
                };
                _context.Add(data);
            }
            else
            {
                data.ProjectData = parser.SerializeData(saveData);
                _context.Update(data);
            }
            _context.SaveChanges();
        }
        public static async Task <UserViewModel> ResetPassword(FrontEditorContext _context, UserManager <User> _userManager, int userId)
        {
            UserViewModel model   = new UserViewModel();
            User          usr     = _context.Users.Where(x => x.Id == userId).FirstOrDefault();
            string        newPass = UsersBL.GeneratePassword(_userManager);
            await _userManager.RemovePasswordAsync(usr);

            var result = await _userManager.AddPasswordAsync(usr, newPass);

            if (result.Succeeded)
            {
                model.NewPassword = newPass;
            }
            else
            {
                foreach (IdentityError error in result.Errors)
                {
                    model.ErrorText += error.Description + "<br />";
                }
            }
            return(model);
        }
        public static ProjectViewModel EditProjectData(FrontEditorContext _context, ProjectViewModel proj)
        {
            Project project = _context.Projects.Where(x => x.Id == proj.ProjectId).FirstOrDefault();

            project.Title       = proj.Title;
            project.Description = proj.Description;
            project.Category    = proj.Category;
            project.LastEdit    = DateTime.Now;
            if (proj.OwnerId < 0)
            {
                User owner = _context.Users.Where(x => x.Id == proj.OwnerId).FirstOrDefault();
                project.Owner = owner;
            }
            project.Status = proj.Status;

            _context.Projects.Update(project);
            _context.SaveChanges();
            return(new ProjectViewModel(project)
            {
                DatasChanged = true
            });
        }
        public static ProjectViewModel CreateProject(FrontEditorContext _context, ProjectViewModel proj)
        {
            User    owner   = _context.Users.Where(x => x.Id == proj.OwnerId).FirstOrDefault();
            Project project = new Project()
            {
                Title       = proj.Title,
                Description = proj.Description,
                Category    = proj.Category,
                CreateTime  = DateTime.Now,
                Owner       = owner,
                LastEdit    = DateTime.Now,
                Status      = ProjectStatus.New,
                ExportCount = 0
            };

            _context.Projects.Add(project);
            _context.SaveChanges();
            return(new ProjectViewModel(project)
            {
                DatasChanged = true, NewProject = true
            });
        }
Example #23
0
        public static DashboardViewModel DashboardDatas(FrontEditorContext _context)
        {
            DashboardViewModel data = new DashboardViewModel();

            using (_context)
            {
                data = new DashboardViewModel()
                {
                    UsersCount              = _context.Users.Count(),
                    ProjectsCount           = _context.Projects.Count(),
                    CategoriesCount         = _context.Projects.Select(x => x.Category).Distinct().Count(),
                    ExportsCount            = _context.Projects.Select(x => x.ExportCount).Sum(),
                    NewProjectsCount        = _context.Projects.Where(x => x.Status == ProjectStatus.New).Count(),
                    InProgressProjectsCount = _context.Projects.Where(x => x.Status == ProjectStatus.Editable).Count(),
                    ExportedProjectsCount   = _context.Projects.Where(x => x.Status == ProjectStatus.Exported).Count()
                };
                data.StatusList = new List <StatusItemViewModel> {
                    new StatusItemViewModel("Új projekt", data.NewProjectsCount > 0 ? "Van" : "Nincs", data.NewProjectsCount > 0),
                    new StatusItemViewModel("Projekt folyamatban", data.InProgressProjectsCount > 0 ? "Van" : "Nincs", data.InProgressProjectsCount > 0),
                    new StatusItemViewModel("Exportált projekt", data.ExportedProjectsCount > 0 ? "Van" : "Nincs", data.ExportedProjectsCount > 0),
                    new StatusItemViewModel("Felhasználók", data.UsersCount > 100 ? "100 felett" : "100 alatt", data.UsersCount > 10),
                    new StatusItemViewModel("Exportálás", data.ExportsCount > 0 ? "Történt" : "Nem történt", data.ExportsCount > 0)
                };
                data.TechnologyList = new List <TechnologyItemViewModel> {
                    new TechnologyItemViewModel(".NET Core 3.1", "https://dotnet.microsoft.com/download/dotnet-core/3.1", "3.1.0", "MIT"),
                    new TechnologyItemViewModel("MySQL", "https://www.mysql.com/", "8.0.23", "MIT"),
                    new TechnologyItemViewModel("Entity Framework Core", "https://docs.microsoft.com/en-us/ef/core/", "3.1.5", "Apache-2.0"),
                    new TechnologyItemViewModel("Popper.js", "https://popper.js.org/", "1.16.1", "MIT"),
                    new TechnologyItemViewModel("jQuery", "https://code.jquery.com/jquery/", "3.5.1", "MIT"),
                    new TechnologyItemViewModel("Bootstrap", "https://getbootstrap.com/", "4.5.3", "MIT"),
                    new TechnologyItemViewModel("FontAwesome", "https://fontawesome.com/", "5.15.1", "MIT"),
                    new TechnologyItemViewModel("Chart.js", "https://www.chartjs.org/", "2.9.4", "MIT"),
                    new TechnologyItemViewModel("Json.NET", "https://www.newtonsoft.com/json", "13.0.1", "MIT"),
                };
            }
            return(data);
        }
        public static async Task <LoginViewModel> Login(FrontEditorContext _context, SignInManager <User> _signInManager, LoginViewModel model)
        {
            User usr = _context.Users.Where(x => x.Email == model.Email).FirstOrDefault();

            if (usr == null)
            {
                model.ErrorText += "Felhasználó nem található!";
            }
            else
            {
                var result = await _signInManager.PasswordSignInAsync(usr, model.Password, model.RememberMe, false);

                if (result.Succeeded)
                {
                    usr.LastActive = DateTime.Now;
                    _context.SaveChanges();
                }
                else
                {
                    model.ErrorText += "Nem megfelelő bejelentkezési adatok!";
                }
            }
            return(model);
        }
        public static ProjectViewModel GetProjectData(FrontEditorContext _context, int id)
        {
            Project project = _context.Projects.Where(x => x.Id == id).FirstOrDefault();

            return(new ProjectViewModel(project));
        }
Example #26
0
 public HomeController(ILogger <HomeController> logger, IConfiguration config, FrontEditorContext context) : base(logger, config, context)
 {
 }
 public static bool UserIsAdmin(FrontEditorContext _context, int userId)
 {
     return(_context.UserRoles.Where(x => x.UserId == userId && x.RoleId == 1).FirstOrDefault() != null);
 }
        public static async Task <UserViewModel> CreateUser(FrontEditorContext _context, UserManager <User> _userManager, UserViewModel model)
        {
            try
            {
                User user = _context.Users.Where(x => x.Email == model.Email).FirstOrDefault();
                if (user != null)
                {
                    throw new Exception("Ezzel az e-mail címmel már létezik felhasználó!");
                }
                else
                {
                    user = new User
                    {
                        DisplayName  = model.DisplayName,
                        UserName     = model.UserName,
                        Email        = model.Email,
                        LastActive   = DateTime.Now,
                        Registration = DateTime.Now
                    };
                    model.NewPassword = GeneratePassword(_userManager);
                    var result = await _userManager.CreateAsync(user, model.NewPassword);

                    if (result.Succeeded)
                    {
                        _context.UserRoles.Add(new IdentityUserRole <int>()
                        {
                            UserId = user.Id, RoleId = model.RoleId
                        });
                        _context.SaveChanges();
                        model.UserId = user.Id;
                    }
                    foreach (var error in result.Errors)
                    {
                        if (error.Code == "DuplicateUserName")
                        {
                            model.ErrorText += "Ezzel a felhasználónévvel már létezik felhasználó!<br/>";
                        }
                        else if (error.Code == "PasswordTooShort")
                        {
                            model.ErrorText += "A jelszó legalább 6 karakter!<br/>";
                        }
                        else if (error.Code == "PasswordRequiresNonAlphanumeric")
                        {
                            model.ErrorText += "A jelszó tartalmaz legalább egy nem alfanumerikus karaktert!<br/>";
                        }
                        else if (error.Code == "PasswordRequiresDigit")
                        {
                            model.ErrorText += "A jelszó legalább egy számot tartalmaz!<br/>";
                        }
                        else if (error.Code == "PasswordRequiresUpper")
                        {
                            model.ErrorText += "A jelszó legalább egy nagybetűt tartalmaz!<br/>";
                        }
                        else if (error.Code == "PasswordRequiresLower")
                        {
                            model.ErrorText += "A jelszó legalább egy kisbetűt tartalmaz!<br/>";
                        }
                        else
                        {
                            model.ErrorText += error.Description + "<br/>";
                        }
                    }
                    model.NewUser      = true;
                    model.Registration = DateTime.Now;
                    model.LastActive   = model.Registration;
                    model.DatasChanged = true;
                }
            }
            catch (Exception ex)
            {
                model.ErrorText = ex.Message;
            }
            return(model);
        }
 public UsersController(ILogger <HomeController> logger, IConfiguration config, FrontEditorContext context, UserManager <User> userManager) : base(logger, config, context)
 {
     _userManager = userManager;
 }
 private static EditorModelData NewMethod(FrontEditorContext _context, int projectId)
 {
     return(GetProjectEditorData(_context, projectId));
 }