public ActionResult RequestChangePassword(RequestChangePasswordModel model)
        {
            Account acc   = AccountRepos.GetByEmail(model.Email);
            string  token = WebSecurity.GeneratePasswordResetToken(acc.UserName, 1440);

            return(RedirectToAction("SendPasswordResetEmail", "Email", new { username = acc.UserName, token = token }));
        }
        public ActionResult SendPasswordChangeSuccessEmail(string username)
        {
            Account acc = AccountRepos.Get(username);

            UserMailer mailer = new UserMailer();

            mailer.PasswordChangeSuccessMessage(acc.UserName).Send();
            return(RedirectToAction("RequestChangePasswordSuccess", "Account"));
        }
        public ActionResult Login(LoginModel model)
        {
            using (DocCommanderEntities db = new DocCommanderEntities())
            {
                //Get configured values and get the users this template is for an intranet application.
                //Note AdminLoginOnlyallowed is commented out as
                //bool AdminLoginOnlyAllowed = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["AdminLoginOnlyAllowed"]);
                int     maxBadLogins = int.Parse(System.Configuration.ConfigurationManager.AppSettings["MaxBadLogins"]);
                Account acc          = AccountRepos.Get(model.UserName);

                //Trap errors
                if (acc == null)
                {
                    ModelState.AddModelError("", "Your username or password is not correct.");
                }

                if (!(bool)acc.IsEnabled)
                {
                    ModelState.AddModelError("", "Your account is not enabled. Please contact your site administrator.");
                }

                //if(AdminLoginOnlyAllowed && !User.IsInRole("Admin"))
                //ModelState.AddModelError("", "This website is being maintained. Normal service will resume shortly.");

                //check details submitted
                if (ModelState.IsValid)
                {
                    if (WebSecurity.IsConfirmed(model.UserName))
                    {
                        if (WebSecurity.Login(acc.UserName, model.Password, persistCookie: model.RememberMe))
                        {
                            //use the Enable function to reset the numBad Logins to 0;
                            AccountRepos.Enable(acc.UserName);
                            return(RedirectToAction("Dashboard", "Account"));
                        }
                        else
                        {
                            ModelState.AddModelError("", "Your username or password is not correct");
                            AccountRepos.AddBadLogin(model.UserName);
                            RedirectToAction("SendNotifyFailedLoginEmail", "Email", new { username = model.UserName });
                            if (maxBadLogins > 0 && AccountRepos.GetNumBadLogins(acc.AccountId) > maxBadLogins)
                            {
                                AccountRepos.Disable(acc.UserName);
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Your account is not activated. Please Check Your email and activate your account.");
                    }
                }
            }
            return(View(model));
        }
        public JsonResult UserAutoComplete(string term)
        {
            List <Account> users = AccountRepos.Search(term);
            JsonResult     res   = Json(users.Select(x => new
            {
                id    = x.AccountId,
                value = x.FirstName + " " + x.LastName,
                label = x.FirstName + " " + x.LastName
            }), JsonRequestBehavior.AllowGet);

            return(res);
        }
 public ActionResult ChangePassword(ChangePasswordModel model)
 {
     if (ModelState.IsValid)
     {
         bool security = WebSecurity.ResetPassword(model.Token, model.NewPassword);
         if (security)
         {
             AccountRepos.Enable(model.UserName);
         }
         return(RedirectToAction("ChangePasswordSuccess"));
     }
     return(View(model));
 }
        public ActionResult ConfirmAccount()
        {
            //get values from request, verify and activate account.
            string username = Request.QueryString["u"];
            string token    = Request.QueryString["t"];
            bool   success  = WebSecurity.ConfirmAccount(username, token);

            if (success)
            {
                AccountRepos.Enable(username);
                return(RedirectToAction("ConfirmationSuccess"));
            }
            ViewBag.ErrorMessage("We could not confirm your account. The confirmation token is nonly valid for 24Hours. please click here to request another confirmation email.");
            return(View("Error"));
        }
        public ActionResult SendNotifyFailedLoginEmail(string username)
        {
            Account account = AccountRepos.Get(username);
            EmailNotifyFailedLoginAttemptModel model = new EmailNotifyFailedLoginAttemptModel()
            {
                SiteName = siteName,
                SiteUrl  = siteUrl,
                ToEmail  = account.Email,
            };

            UserMailer mailer = new UserMailer();

            mailer.NotifyFailedLoginAttemptMessage(model).Send();
            return(RedirectToAction("RequestChangePasswordSuccess", "Account"));
        }
        public ActionResult SendConfirmationToken(string username)
        {
            Account acc = AccountRepos.Get(username);

            try
            {
                string ConfirmationToken = AccountRepos.GetConfirmationToken(username);
                RedirectToAction("SendAccountConfirmationEmail", "Email", new { account = acc, token = ConfirmationToken });
                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception)
            {
                ViewBag.ErrorMessage("Could not send a confirmation token.");
                return(RedirectToAction("Error"));
            }
        }
        public ActionResult SendPasswordResetEmail(string username, string token)
        {
            Account account = AccountRepos.Get(username);
            EmailPasswordResetModel model = new EmailPasswordResetModel()
            {
                SiteName           = siteName,
                SiteUrl            = siteUrl,
                FirstName          = account.FirstName,
                UserName           = account.UserName,
                ToEmail            = account.Email,
                PasswordResetToken = token,
                PasswordResetUrl   = siteUrl + "/Account/ChangePassword?u=" + account.UserName + @"&t=" + token
            };

            UserMailer mailer = new UserMailer();

            mailer.PasswordResetMessage(model).Send();
            return(RedirectToAction("RequestChangePasswordSuccess", "Account"));
        }
        public ActionResult SendAccountConfirmationEmail(string username, string token)
        {
            Account account = AccountRepos.Get(username);
            EmailConfirmationModel model = new EmailConfirmationModel()
            {
                SiteName          = siteName,
                SiteUrl           = siteUrl,
                UserName          = account.UserName,
                FirstName         = account.FirstName,
                ToEmail           = account.Email,
                ConfirmationToken = token,
                ConfirmationUrl   = siteUrl + "/Account/ConfirmAccount?u=" + account.UserName + @"&t" + token
            };

            UserMailer mailer = new UserMailer();

            mailer.ConfirmationTokenMessage(model).Send();
            return(RedirectToAction("RegistrationSuccess", "Account"));
        }
        public ActionResult SendWelcomeEmail(string username)
        {
            Account           account = AccountRepos.Get(username);
            EmailWelcomeModel model   = new EmailWelcomeModel()
            {
                SiteName    = siteName,
                SiteUrl     = siteUrl,
                FirstName   = account.FirstName,
                LoginUrl    = siteUrl + "/Account/login",
                SiteHelpUrl = siteUrl + "/Help/",
                ToEmail     = account.Email,
                UserName    = account.UserName
            };

            UserMailer mailer = new UserMailer();

            mailer.WelcomeMessage(model).Send();
            return(RedirectToAction("RegistrationSuccess", "Account"));
        }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            //Authenticate against LDAP if the account has the IsLDAPAccount flag
            if (AccountRepos.GetIsLDAPAccount(model.UserName))
            {
                if (AuthenticateLDAP(model))
                {
                    if (this.Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                        !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return(this.Redirect(returnUrl));
                    }
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    return(this.RedirectToAction("Index", "Home"));
                }
            }
            this.ModelState.AddModelError(string.Empty, "The user name or password provided is incorrect.");
            return(this.View(model));
        }
 public string GetDisplayNameFromId(int id)
 {
     return(AccountRepos.GetDisplayName(id));
 }
        public ActionResult AddUserToRoles(string username)
        {
            Account acc = AccountRepos.Get(username);

            return(View(acc));
        }
        public ActionResult EditUser(string username)
        {
            Account acc = AccountRepos.Get(username);

            return(View(acc));
        }