Esempio n. 1
0
        public ActionResult Resend(int id)
        {
            try
            {
                var mail        = DataContext.Mails.WithSiteId(CurrentSiteId).FirstOrDefault(i => i.Id == id);
                var mailService = new MailService(DataContext);
                var mailSetting = CurrentSite.GetMailSetting();
                if (mailSetting == null)
                {
                    ShowError(MessageResource.ConfigMailSettingFirst);
                }
                else
                {
                    mailService.SendMail(mailSetting, mail);
                    SaveChanges();

                    ShowSuccess(MessageResource.ResendMailSuccess);
                }
            }
            catch
            {
                ShowError(MessageResource.ResendMailFailed);
            }

            return(RedirectToIndex());
        }
        public ActionResult CustomCss(bool enableCustomCss, string content)
        {
            try
            {
                CurrentSite.EnsureCustomCss();

                var path = HttpContext.Server.MapPath(CurrentSite.GetCustomCssPath());
                using (var writer = new StreamWriter(path))
                {
                    writer.Write(content);
                }
                CurrentSite.EnableCustomCss = enableCustomCss;
                SaveChanges();

                ShowSuccess(MessageResource.UpdateSuccess);
            }
            catch
            {
                ShowError(MessageResource.UpdateFailed);
            }

            ViewBag.Content         = content;
            ViewBag.EnableCustomCss = enableCustomCss;

            return(View());
        }
Esempio n. 3
0
        public virtual async Task <IActionResult> ManageLogins()
        {
            if (!CurrentSite.HasAnySocialAuthEnabled())
            {
                return(RedirectToAction("Index"));
            }

            var user = await UserManager.FindByIdAsync(HttpContext.User.GetUserId());

            if (user == null)
            {
                return(View("Error"));
            }
            var userLogins = await UserManager.GetLoginsAsync(user);

            //var externalSchemes = await SignInManager.GetExternalAuthenticationSchemesAsync();
            var externalSchemes = await AccountService.GetExternalAuthenticationSchemes();

            var otherLogins = externalSchemes.Where(auth => userLogins.All(ul => auth.Name != ul.LoginProvider)).ToList();

            var model = new ManageLoginsViewModel
            {
                CurrentLogins = userLogins,
                OtherLogins   = otherLogins
            };

            model.ShowRemoveButton = await UserManager.HasPasswordAsync(user) || model.CurrentLogins.Count > 1;

            return(View(model));
        }
        public ActionResult Robots()
        {
            if (CurrentSite == null)
            {
                return(SiteNotFound());
            }

            return(File(CurrentSite.GetRobotsPath(), "text/plain"));
        }
Esempio n. 5
0
        public virtual async Task <IActionResult> Register(string returnUrl = null)
        {
            if (AccountService.IsSignedIn(User))
            {
                return(this.RedirectToSiteRoot(CurrentSite));
            }
            if (!CurrentSite.AllowNewRegistration)
            {
                return(new StatusCodeResult(404));
            }
            // login is equivalent to register for new social auth users
            // if db auth is disabled just redirect
            if (CurrentSite.DisableDbAuth && CurrentSite.HasAnySocialAuthEnabled())
            {
                return(RedirectToAction("Login"));
            }

            ViewData["Title"] = StringLocalizer["Register"];

            returnUrl = IdentityServerIntegration.EnsureFolderSegmentIfNeeded(CurrentSite, returnUrl);
            //identityserver integration point
            var idProvider = await IdentityServerIntegration.GetAuthorizationContextAsync(returnUrl);

            if (!string.IsNullOrEmpty(idProvider))
            {
                // if IdP is passed, then bypass showing the login screen
                return(ExternalLogin(idProvider, returnUrl));
            }
            ViewData["ReturnUrl"] = returnUrl;

            var model = new RegisterViewModel
            {
                SiteId = CurrentSite.Id
            };

            if ((CurrentSite.CaptchaOnRegistration) && (!string.IsNullOrWhiteSpace(CurrentSite.RecaptchaPublicKey)))
            {
                model.RecaptchaSiteKey    = CurrentSite.RecaptchaPublicKey;
                model.UseInvisibleCaptcha = CurrentSite.UseInvisibleRecaptcha;
            }
            model.UseEmailForLogin           = CurrentSite.UseEmailForLogin;
            model.RegistrationPreamble       = CurrentSite.RegistrationPreamble;
            model.RegistrationAgreement      = CurrentSite.RegistrationAgreement;
            model.AgreementRequired          = !string.IsNullOrWhiteSpace(CurrentSite.RegistrationAgreement);
            model.ExternalAuthenticationList = await AccountService.GetExternalAuthenticationSchemes();

            var viewName = await CustomRegistration.GetRegisterViewName(CurrentSite, HttpContext);

            await CustomRegistration.HandleRegisterGet(
                CurrentSite,
                model,
                HttpContext,
                ViewData);

            return(View(viewName, model));
        }
Esempio n. 6
0
 public override int GetHashCode()
 {
     unchecked
     {
         int result = CurrentSite.GetHashCode();
         result = (result * 397) ^ North.GetHashCode();
         result = (result * 397) ^ South.GetHashCode();
         result = (result * 397) ^ East.GetHashCode();
         result = (result * 397) ^ West.GetHashCode();
         return(result);
     }
 }
Esempio n. 7
0
        public ActionResult Index()
        {
            CurrentSite.EnsureRobots();

            var path = HttpContext.Server.MapPath(CurrentSite.GetRobotsPath());

            using (var reader = new StreamReader(path))
            {
                ViewBag.Robots = reader.ReadToEnd();
            }

            return(View(CurrentSite));
        }
Esempio n. 8
0
        public ActionResult Setting()
        {
            var setting = CurrentSite.GetMailSetting();

            if (setting == null)
            {
                setting = new MailSetting {
                    Port = 25
                };
            }

            return(View(setting));
        }
        public ActionResult CustomCss()
        {
            CurrentSite.EnsureCustomCss();

            var path = HttpContext.Server.MapPath(CurrentSite.GetCustomCssPath());

            using (var reader = new StreamReader(path))
            {
                ViewBag.Content = reader.ReadToEnd();
            }

            ViewBag.EnableCustomCss = CurrentSite.EnableCustomCss;

            return(View());
        }
        public void Execute(IJobExecutionContext context)
        {
            var host = context.JobDetail.JobDataMap.GetString("HOST");

            try
            {
                using (var ccnet = new CCNET(host))
                {
                    var projects = ccnet.Server.GetProjectStatus().OrderBy(t => t.ServerName).ThenBy(t => t.Name).ToArray();
                    CurrentSite.ProjectStatusCollection[host] = projects;
                    CurrentSite.OnProjectChagned(host);
                }
            }
            catch { }
        }
        public ActionResult Permalink(PermalinkSetting model)
        {
            try
            {
                CurrentSite.SetPermalinkSetting(model);
                DataContext.SaveChanges();

                ShowSuccess(SusuCMS.MessageResource.UpdateSuccess);
            }
            catch
            {
                ShowError(SusuCMS.MessageResource.UpdateFailed);
            }

            return(View(model));
        }
Esempio n. 12
0
        public ActionResult Setting(MailSetting model)
        {
            try
            {
                CurrentSite.SetMailSetting(model);
                SaveChanges();

                ShowSuccess(MessageResource.UpdateSuccess);
            }
            catch
            {
                ShowError(MessageResource.UpdateFailed);
            }

            return(RedirectToIndex());
        }
Esempio n. 13
0
        public ActionResult Setting(string json)
        {
            try
            {
                var model = System.Web.Helpers.Json.Decode <UserSetting>(json);
                CurrentSite.SetUserSetting(model);
                SaveChanges();

                ShowSuccess(MessageResource.UpdateSuccess);
            }
            catch
            {
                ShowError(MessageResource.UpdateFailed);
            }

            return(RedirectToIndex());
        }
Esempio n. 14
0
        public virtual async Task <IActionResult> Login(string returnUrl = null)
        {
            if (AccountService.IsSignedIn(User))
            {
                return(this.RedirectToSiteRoot(CurrentSite));
            }

            returnUrl = IdentityServerIntegration.EnsureFolderSegmentIfNeeded(CurrentSite, returnUrl);
            //identityserver integration point
            var idProvider = await IdentityServerIntegration.GetAuthorizationContextAsync(returnUrl);

            if (!string.IsNullOrEmpty(idProvider))
            {
                // if IdP is passed, then bypass showing the login screen
                return(ExternalLogin(idProvider, returnUrl));
            }

            ViewData["Title"]     = StringLocalizer["Log In"];
            ViewData["ReturnUrl"] = returnUrl;

            var model = new LoginViewModel();

            var recaptchaKeys = await RecaptchaKeysProvider.GetKeys().ConfigureAwait(false);

            if ((CurrentSite.CaptchaOnLogin) && (!string.IsNullOrEmpty(recaptchaKeys.PublicKey)))
            {
                model.RecaptchaSiteKey    = recaptchaKeys.PublicKey;
                model.UseInvisibleCaptcha = recaptchaKeys.Invisible;
            }
            model.UseEmailForLogin = CurrentSite.UseEmailForLogin;
            model.LoginInfoTop     = CurrentSite.LoginInfoTop;
            model.LoginInfoBottom  = CurrentSite.LoginInfoBottom;
            var externalSchemes = await AccountService.GetExternalAuthenticationSchemes();

            model.ExternalAuthenticationList = externalSchemes.ToList();
            // don't disable db auth if there are no social auth providers configured
            model.DisableDbAuth = CurrentSite.DisableDbAuth && CurrentSite.HasAnySocialAuthEnabled();

            return(View(model));
        }
Esempio n. 15
0
        public ActionResult Index(string analyticsCode, string robots, string metaFieldsJson)
        {
            try
            {
                var tempPath    = GetTempFaviconPath();
                var faviconPath = Path.Combine(Server.MapPath(CurrentSite.GetFaviconPath()));
                if (System.IO.File.Exists(tempPath))
                {
                    if (System.IO.File.Exists(faviconPath))
                    {
                        System.IO.File.Delete(faviconPath);
                    }

                    System.IO.File.Move(tempPath, faviconPath);
                }

                CurrentSite.EnsureRobots();
                var path = HttpContext.Server.MapPath(CurrentSite.GetRobotsPath());
                using (var writer = new StreamWriter(path))
                {
                    writer.Write(robots);
                }

                CurrentSite.AnalyticsCode  = analyticsCode;
                CurrentSite.MetaFieldsJson = metaFieldsJson;

                SaveChanges();

                ShowSuccess(MessageResource.UpdateSuccess);
            }
            catch
            {
                ShowError(MessageResource.UpdateFailed);
            }

            return(View(CurrentSite));
        }
 protected void btnQuery_Click(object sender, EventArgs e)
 {
     gvBody.DataSource = MESComment.MesRpt.GetJO(txtTrxDate.Text, ddlStatus.SelectedItem.Value, txtCustomer.Text.Trim(), txtSCNo.Text.Trim(), CurrentSite.ToString());
     gvBody.DataBind();
 }
Esempio n. 17
0
        public virtual async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            ViewData["Title"]     = StringLocalizer["Log In"];
            ViewData["ReturnUrl"] = returnUrl;

            Analytics.HandleLoginSubmit("Onsite").Forget();

            var recaptchaKeys = await RecaptchaKeysProvider.GetKeys().ConfigureAwait(false);

            if ((CurrentSite.CaptchaOnLogin) && (!string.IsNullOrEmpty(recaptchaKeys.PublicKey)))
            {
                model.RecaptchaSiteKey    = recaptchaKeys.PublicKey;
                model.UseInvisibleCaptcha = recaptchaKeys.Invisible;
            }
            model.UseEmailForLogin           = CurrentSite.UseEmailForLogin;
            model.LoginInfoTop               = CurrentSite.LoginInfoTop;
            model.LoginInfoBottom            = CurrentSite.LoginInfoBottom;
            model.ExternalAuthenticationList = await AccountService.GetExternalAuthenticationSchemes();

            // don't disable db auth if there are no social auth providers configured
            model.DisableDbAuth = CurrentSite.DisableDbAuth && CurrentSite.HasAnySocialAuthEnabled();

            if (!ModelState.IsValid)
            {
                var errors       = ModelState.Keys.Where(k => ModelState[k].Errors.Count > 0).Select(k => new { propertyName = k, errorMessage = ModelState[k].Errors[0].ErrorMessage });
                var trackedError = errors.FirstOrDefault().errorMessage;
                Analytics.HandleLoginFail("Onsite", trackedError).Forget();

                return(View(model));
            }

            if ((CurrentSite.CaptchaOnLogin) && (!string.IsNullOrEmpty(recaptchaKeys.PrivateKey)))
            {
                var captchaResponse = await RecaptchaServerSideValidator.ValidateRecaptcha(Request, CurrentSite.RecaptchaPrivateKey);

                if (!captchaResponse.Success)
                {
                    Analytics.HandleLoginFail("Onsite", "reCAPTCHA Error").Forget();
                    ModelState.AddModelError("recaptchaerror", StringLocalizer["reCAPTCHA Error occured. Please try again"]);
                    return(View(model));
                }
            }

            var result = await AccountService.TryLogin(model);

            if (result.SignInResult.Succeeded)
            {
                return(await HandleLoginSuccess(result, returnUrl));
            }

            foreach (var reason in result.RejectReasons)
            {
                //these reasons are not meant to be shown in the ui
                // but we can log them so admin will see failed attempts in the log along with reasons
                Log.LogWarning(reason);
            }

            if (result.SignInResult.IsNotAllowed)
            {
                return(await HandleLoginNotAllowed(result, returnUrl));
            }

            if (result.SignInResult.RequiresTwoFactor)
            {
                return(await HandleRequiresTwoFactor(result, returnUrl, model.RememberMe));
            }

            if (result.SignInResult.IsLockedOut)
            {
                return(await HandleLockout(result));
            }
            else
            {
                Analytics.HandleLoginFail("Onsite", StringLocalizer["Invalid login attempt."]).Forget();

                Log.LogInformation($"login did not succeed for {model.Email}");
                ModelState.AddModelError(string.Empty, StringLocalizer["Invalid login attempt."]);
                return(View(model));
            }
        }
        public ActionResult Permalink()
        {
            var setting = CurrentSite.GetPermalinkSetting();

            return(View(setting));
        }
Esempio n. 19
0
        public ActionResult Setting()
        {
            var setting = CurrentSite.GetUserSetting();

            return(View(setting));
        }
Esempio n. 20
0
 private string GetTempFaviconPath()
 {
     return(Path.Combine(Server.MapPath(CurrentSite.GetDataFolderPath()), "temp.ico"));
 }