public IHttpActionResult Activate(int id) { if (db.ActivateUser(id) == ActivateUserResult.Ok) { return(Ok()); } return(NotFound()); }
public ActionResult Login(string username, string password) { var userSession = Session["User"] as User; if (userSession != null) { if (userSession.Admin) { return(RedirectToAction("Users")); } else { return(RedirectToAction("Dashboard")); } } if (username != "" && password != "") { User user = db.GetUser(username); if (user == null) { ViewBag.error = Resources.Resources.WrongUsernameOrPassword; } else { if (user.EmailConfirmed == false) { ViewBag.error = Resources.Resources.EmailNotConfirmed; return(View()); } if (user.Blocked) { ViewBag.error = Resources.Resources.YouAreBlocked; return(View()); } if (user.LoginTrials > 1 && user.LoginTrials <= 3) { ViewBag.ShowCaptcha = 1; } else { ViewBag.ShowCaptcha = 0; } string EncryptedPassword = user.MD5Hash(password); if (user.Admin) { if (EncryptedPassword != user.Password || (!this.IsCaptchaValid("") && (user.LoginTrials > 1 && user.LoginTrials <= 4))) { ViewBag.error = Resources.Resources.WrongUsernameOrPassword; if (user.LoginTrials <= 3) { db.UpdateTrials(username); } else { user.Blocked = true; db.UpdateTrials(username); } } else { db.ActivateUser(username); FormsAuthentication.SetAuthCookie(user.Username, false); Session["User"] = user; return(RedirectToAction("Dashboard", "Home")); } } else { if ((EncryptedPassword != user.Password) || (!this.IsCaptchaValid("") && (user.LoginTrials > 1 && user.LoginTrials <= 4))) { ViewBag.error = Resources.Resources.WrongUsernameOrPassword; if (user.LoginTrials <= 3) { db.UpdateTrials(username); } else { user.Blocked = true; db.UpdateTrials(username); } } else { db.ActivateUser(username); FormsAuthentication.SetAuthCookie(username, false); Session["User"] = user; return(RedirectToAction("Dashboard")); } } } } else { ViewBag.error = Resources.Resources.EmptyLoginFields; } return(View()); }