public IActionResult Index() { if (SetupHelper.IsDbCreateComplete && SetupHelper.IsAdminCreateComplete) { if (GlobalContext.SetupConfig == null) { GlobalContext.SetupConfig = SetupHelper.LoadSetup(); } var setupConfig = GlobalContext.SetupConfig; if (setupConfig == null) { TempData["ErrorMessage"] = "Setup config file is missed. Please reinstall."; return(Redirect("~/CmsHome/ResourceNotFound")); } if (setupConfig.StartupData.Trim('/') == "" || setupConfig.StartupData.Trim().ToLower() == "/home") { return(View()); } var langEnabledUrl = NccUrlHelper.AddLanguageToUrl(CurrentLanguage, NccUrlHelper.EncodeUrl(setupConfig.StartupUrl)); return(Redirect(langEnabledUrl)); } return(Redirect("/SetupHome/Index")); }
public async Task <IActionResult> ConfirmEmail(string userId, string code) { if (userId == null || code == null) { return(Redirect(NccUrlHelper.AddLanguageToUrl(CurrentLanguage, "/CmsHome"))); } var user = await _userManager.FindByIdAsync(userId); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{userId}'."); } var result = await _userManager.ConfirmEmailAsync(user, code); IList <string> roleList = new List <string>(); foreach (var item in user.Roles) { roleList.Add(item.Role.Name); } if (result.Succeeded) { var rsp = FireEvent(UserActivity.Type.EmailConfirmed, user.Email, user, roleList, ""); } return(View(result.Succeeded ? "ConfirmEmail" : "Error")); }
public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { if (GlobalContext.WebSite.AllowRegistration == false) { TempData["ErrorMessage"] = "Registration is not allowed."; return(Redirect("Home/Error")); } ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new NccUser { UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { var subscriber = _nccPermissionService.Get(GlobalContext.WebSite.NewUserRole); user.Permissions.Add(new NccUserPermission() { Permission = subscriber, User = user }); _nccUserService.Update(user); _logger.LogInformation("User created a new account with password."); var rsp = FireEvent(UserActivity.Type.Registered, model.Email, user, new List <string>() { GlobalContext.WebSite.NewUserRole }, ""); if (rsp != null) { returnUrl = rsp.ReturnUrl; } var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id.ToString(), code, Request.Scheme); await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation("User created a new account with password."); if (string.IsNullOrEmpty(returnUrl)) { return(Redirect(NccUrlHelper.AddLanguageToUrl(CurrentLanguage, "/CmsHome"))); } return(Redirect(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
private static string ListItemHtml(NccMenuItem item, string currentLanguage) { var url = "/"; var urlPrefix = ""; var data = ""; if (item.MenuActionType == NccMenuItem.ActionType.BlogCategory) { url = item.Url; url = NccUrlHelper.AddLanguageToUrl(currentLanguage, url); return("<li><a href=\"" + url + "\" target=\"" + item.Target + "\">" + item.Name + "</a></li>"); } else if (item.MenuActionType == NccMenuItem.ActionType.BlogPost) { url = item.Url; url = NccUrlHelper.AddLanguageToUrl(currentLanguage, url); return("<li><a href=\"" + url + "\" target=\"" + item.Target + "\">" + item.Name + "</a></li>"); } else if (item.MenuActionType == NccMenuItem.ActionType.Module) { url = item.Url; url = NccUrlHelper.AddLanguageToUrl(currentLanguage, url); return("<li><a href=\"" + url + "\" target=\"" + item.Target + "\">" + item.Name + "</a></li>"); } else if (item.MenuActionType == NccMenuItem.ActionType.Page) { url = item.Url; url = NccUrlHelper.AddLanguageToUrl(currentLanguage, url); return("<li><a href=\"" + url + "\" target=\"" + item.Target + "\">" + item.Name + "</a></li>"); } else if (item.MenuActionType == NccMenuItem.ActionType.Tag) { url = item.Url; url = NccUrlHelper.AddLanguageToUrl(currentLanguage, url); return("<li><a href=\"" + url + "\" target=\"" + item.Target + "\">" + item.Name + "</a></li>"); } else if (item.MenuActionType == NccMenuItem.ActionType.Url) { urlPrefix = ""; } if (!string.IsNullOrEmpty(item.Data)) { data = "?slug=" + item.Data; } url = urlPrefix + item.Url + data; if (!string.IsNullOrEmpty(currentLanguage) && GlobalConfig.WebSite.IsMultiLangual && !IsExternalUrl(url)) { url = "/" + currentLanguage + url; } var li = "<li><a href=\"" + url + "\" target=\"" + item.Target + "\">" + item.Name + " </a></li>"; return(li); }
private IActionResult RedirectToLocal(string returnUrl) { if (Url.IsLocalUrl(returnUrl)) { return(Redirect(NccUrlHelper.AddLanguageToUrl(CurrentLanguage, returnUrl))); } else { return(RedirectToAction(NccUrlHelper.AddLanguageToUrl(CurrentLanguage, "/CmsHome"))); } }
public async Task <IActionResult> Logout() { var user = await _userManager.FindByNameAsync(User.Identity.Name); await _signInManager.SignOutAsync(); _logger.LogInformation("User logged out."); var roles = await _userManager.GetRolesAsync(user); var returnUrl = NccUrlHelper.AddLanguageToUrl(CurrentLanguage, "/CmsHome"); var rsp = FireEvent(UserActivity.Type.Logedout, user.Email, user, roles, NccUrlHelper.AddLanguageToUrl(CurrentLanguage, "/CmsHome")); if (rsp != null) { returnUrl = rsp.ReturnUrl; } return(Redirect(returnUrl)); }
public ActionResult Index(string slug) { ViewBag.CurrentLanguage = CurrentLanguage; if (!string.IsNullOrEmpty(slug)) { NccPage page = _pageService.GetBySlug(slug); if (page != null) { page = _mediator.Send(new OnPageShow(page)).Result; foreach (var item in page.PageDetails) { item.Content = _nccShortCodeProvider.ReplaceShortContent(item.Content); } return(View(page)); } } TempData["Message"] = "Page not found"; return(Redirect(NccUrlHelper.AddLanguageToUrl(CurrentLanguage, "/CmsHome/ResourceNotFound"))); }
public void NccUrlHelper_Add_language_to_url_should_work() { var url = NccUrlHelper.AddLanguageToUrl("en", "/CmsHome"); Assert.Equal("/CmsHome", url); FakeGlobalContext.EnableMultiLanguage(); var url2 = NccUrlHelper.AddLanguageToUrl("en", "/CmsHome"); Assert.Equal("/en/CmsHome", url2); FakeGlobalContext.DisableMultiLanguage(); var url3 = NccUrlHelper.AddLanguageToUrl("en", "CmsHome"); Assert.Equal("CmsHome", url3); FakeGlobalContext.EnableMultiLanguage(); var url4 = NccUrlHelper.AddLanguageToUrl("en", "CmsHome"); Assert.Equal("/en/CmsHome", url4); var url5 = NccUrlHelper.AddLanguageToUrl("en", "http://localhost:5000/CmsHome/"); Assert.Equal("http://localhost:5000/en/CmsHome/", url5); var url6 = NccUrlHelper.AddLanguageToUrl("en", "https://localhost:5000/CmsHome/"); Assert.Equal("https://localhost:5000/en/CmsHome/", url6); var url7 = NccUrlHelper.AddLanguageToUrl("bn", "http://localhost:5000/CmsHome/?query=DamaCoreCMS&version=0.4.4"); Assert.Equal("http://localhost:5000/bn/CmsHome/?query=DamaCoreCMS&version=0.4.4", url7); }
public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null) { if (string.IsNullOrEmpty(returnUrl)) { returnUrl = NccUrlHelper.AddLanguageToUrl(CurrentLanguage, "/CmsHome"); } ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set lockoutOnFailure: true var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : false); if (result.Succeeded) { _logger.LogInformation("User logged in."); var user = _nccUserService.GetByUserName(model.Email); var roles = _nccPermissionService.LoadAll(); var rsp = FireEvent(UserActivity.Type.Logedin, model.Email, user, roles.Select(x => x.Name).ToList(), returnUrl); if (rsp != null) { returnUrl = rsp.ReturnUrl; } foreach (var item in user.Roles) { if (item.Role.Name == NccCmsRoles.SuperAdmin) { return(RedirectToLocal("/Admin")); } } var startups = _startupService.LoadAll(); foreach (var item in startups) { if (user.Permissions.Where(x => x.Permission.Name == item.Permission.Name).Count() > 0) { return(Redirect(item.StartupUrl)); } } return(RedirectToLocal(returnUrl)); } if (result.RequiresTwoFactor) { return(RedirectToAction(nameof(LoginWith2fa), new { returnUrl, model.RememberMe })); } if (result.IsLockedOut) { _logger.LogWarning("User account locked out."); return(RedirectToAction(nameof(Lockout))); } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(View(model)); } } // If we got this far, something failed, redisplay form return(View(model)); }
private static string ListItemHtml(NccMenuItem item, string currentLanguage) { var url = "/"; var urlPrefix = ""; var data = ""; if (item.MenuActionType == NccMenuItem.ActionType.BlogCategory) { //urlPrefix = "/Category/"; url = item.Url; url = NccUrlHelper.AddLanguageToUrl(currentLanguage, url); return("<li><a href=\"" + url + "\" target=\"" + item.Target + "\">" + item.Name + "</a></li>"); } else if (item.MenuActionType == NccMenuItem.ActionType.BlogPost) { url = item.Url; url = NccUrlHelper.AddLanguageToUrl(currentLanguage, url); return("<li><a href=\"" + url + "\" target=\"" + item.Target + "\">" + item.Name + "</a></li>"); } else if (item.MenuActionType == NccMenuItem.ActionType.Module) { //urlPrefix = "/" + item.Controller + "/" + item.Action + "/"; url = item.Url; url = NccUrlHelper.AddLanguageToUrl(currentLanguage, url); return("<li><a href=\"" + url + "\" target=\"" + item.Target + "\">" + item.Name + "</a></li>"); } else if (item.MenuActionType == NccMenuItem.ActionType.Page) { //urlPrefix = "";/*/CmsHome/CmsPage/View/*/ //item.Url = item.Url.StartsWith("/") == true ? item.Url : "/" + item.Url; //item.Url = NccUrlHelper.AddLanguageToUrl(currentLanguage, item.Url); //return "<li><a href=\"" + item.Url + "\" target=\"" + item.Target + "\">" + item.Name + " </a></li>"; url = item.Url; url = NccUrlHelper.AddLanguageToUrl(currentLanguage, url); return("<li><a href=\"" + url + "\" target=\"" + item.Target + "\">" + item.Name + "</a></li>"); } else if (item.MenuActionType == NccMenuItem.ActionType.Tag) { url = item.Url; url = NccUrlHelper.AddLanguageToUrl(currentLanguage, url); return("<li><a href=\"" + url + "\" target=\"" + item.Target + "\">" + item.Name + "</a></li>"); } else if (item.MenuActionType == NccMenuItem.ActionType.Url) { urlPrefix = ""; } if (!string.IsNullOrEmpty(item.Data)) { data = "?slug=" + item.Data; } url = urlPrefix + item.Url + data; if (!string.IsNullOrEmpty(currentLanguage) && GlobalContext.WebSite.IsMultiLangual && !IsExternalUrl(url)) { url = "/" + currentLanguage + url; } var li = "<li><a href=\"" + url + "\" target=\"" + item.Target + "\">" + item.Name + " </a></li>"; return(li); }