Exemplo n.º 1
0
        /// <summary>
        /// The log user in.
        /// </summary>
        /// <param name="model">
        /// The model.
        /// </param>
        /// <param name="returnUrl">
        /// The return url.
        /// </param>
        /// <returns>
        /// Returns user to returnUrl
        /// </returns>
        private ActionResult LogUserIn(LogOnModel model, string returnUrl)
        {
            FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);

            var authorized = Roles.IsUserInRole(model.UserName, "Administrator");
            if (authorized)
            {
                return RedirectToAction("Index", "Notification");
            }

            if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
            {
                return Redirect(returnUrl);
            }

            return RedirectToAction("Index", "Home");
        }
Exemplo n.º 2
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    Notification newNotifications =
                        db.Notification.FirstOrDefault(o => o.ViewableBy == model.UserName && o.PreviouslyRead == false);
                    if (newNotifications != null)
                    {
                        TempData["notificationMessage"] =
                            "You have an unchecked notification.  Please visit the Notification tab and tend to this notification.";
                    }

                    return LogUserIn(model, returnUrl);
                }

                ModelState.AddModelError(
                    string.Empty,
                    PaulSchoolResource.AccountController_LogOn_The_user_name_or_password_provided_is_incorrect_);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }