public ActionResult Register(string username, string email, string password, string confirmPassword) { ViewData["Title"] = "Register"; ViewData["PasswordLength"] = Provider.MinRequiredPasswordLength; // Non-POST requests should just display the Register form if (Request.HttpMethod != "POST") { return(View()); } // Basic parameter validation List <string> errors = new List <string>(); if (String.IsNullOrEmpty(username)) { errors.Add("You must specify a username."); } if (String.IsNullOrEmpty(email)) { errors.Add("You must specify an email address."); } if (password == null || password.Length < Provider.MinRequiredPasswordLength) { errors.Add(String.Format(CultureInfo.InvariantCulture, "You must specify a password of {0} or more characters.", Provider.MinRequiredPasswordLength)); } if (!String.Equals(password, confirmPassword, StringComparison.Ordinal)) { errors.Add("The password and confirmation do not match."); } if (errors.Count == 0) { // Attempt to register the user MembershipCreateStatus createStatus; MembershipUser newUser = Provider.CreateUser(username, password, email, null, null, true, null, out createStatus); if (newUser != null) { ProfileHelper.Create(DB, username); DB.Dispose(); FormsAuth.SetAuthCookie(username, false /* createPersistentCookie */); return(RedirectToAction("Index", "Home")); } else { errors.Add(ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form ViewData["errors"] = errors; ViewData["username"] = username; ViewData["email"] = email; return(View()); }
// [RequireHttps] public ActionResult Login(string username, string password, bool rememberMe, string returnUrl, int?id, int?p) { ViewData["PageTitle"] = "Login"; // Basic parameter validation if (String.IsNullOrEmpty(username)) { ModelState.AddModelError("username", "You must specify a username."); } if (String.IsNullOrEmpty(password)) { ModelState.AddModelError("password", "You must specify a password."); } if (ViewData.ModelState.IsValid) { // Attempt to login bool loginSuccessful = Provider.ValidateUser(username, password); if (loginSuccessful) { FormsAuth.SetAuthCookie(username, rememberMe); if (p != null) { return(RedirectToAction("GetTicket", new { p = p, returnUrl = returnUrl })); } if (id.HasValue) { return(Redirect(string.Format("{0}://{1}:{2}/{3}", this.Request.Url.Scheme, this.Request.Url.Host, id, returnUrl))); } else if (!String.IsNullOrEmpty(returnUrl)) { return(Redirect(returnUrl)); } else if (Roles.IsUserInRole(username, api.AccountController.APPLICANT_ROLE)) { KcsarUserProfile profile = ProfileBase.Create(username) as KcsarUserProfile; if (!string.IsNullOrWhiteSpace(profile.LinkKey)) { return(RedirectToAction("Detail", "Members", new { id = profile.LinkKey })); } } return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("_FORM", "The username or password provided is incorrect."); } } // If we got this far, something failed, redisplay form ViewData["rememberMe"] = rememberMe; return(View()); }
protected virtual void SetAuthenticationCookie(User user) { IEnumerable <string> roles = null; if (user.Roles.AnySafe()) { roles = user.Roles.Select(r => r.Name); } FormsAuth.SetAuthCookie( user.Username, true, roles); }
public ActionResult Register(string username, string email, string password, string confirmPassword) { ViewData["Title"] = "Register"; ViewData["PasswordLength"] = Provider.MinRequiredPasswordLength; // Basic parameter validation if (String.IsNullOrEmpty(username)) { ModelState.AddModelError("username", "You must specify a username."); } if (String.IsNullOrEmpty(email)) { ModelState.AddModelError("email", "You must specify an email address."); } if (password == null || password.Length < Provider.MinRequiredPasswordLength) { ModelState.AddModelError("password", String.Format(CultureInfo.CurrentCulture, "You must specify a password of {0} or more characters.", Provider.MinRequiredPasswordLength)); } if (!String.Equals(password, confirmPassword, StringComparison.Ordinal)) { ModelState.AddModelError("_FORM", "The new password and confirmation password do not match."); } if (ViewData.ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; MembershipUser newUser = Provider.CreateUser(username, password, email, null, null, true, null, out createStatus); if (newUser != null) { FormsAuth.SetAuthCookie(username, false /* createPersistentCookie */); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("_FORM", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return(View()); }
public virtual ActionResult LogOn(SignInRequest request, string returnUrl) { // I think it should be obvious why we don't want the current URL to be the return URL here ;) ViewData[Constants.ReturnUrlViewDataKey] = returnUrl; // TODO: improve the styling of the validation summary // TODO: modify the Object.cshtml partial to make the first text box autofocus, or use additional metadata if (!ModelState.IsValid) { return(View()); } var user = Users.FindByUsernameOrEmailAddressAndPassword( request.UserNameOrEmail, request.Password); if (user == null) { ModelState.AddModelError( String.Empty, Strings.UserNotFound); return(View()); } if (!user.Confirmed) { ViewBag.ConfirmationRequired = true; return(View()); } IEnumerable <string> roles = null; if (user.Roles.AnySafe()) { roles = user.Roles.Select(r => r.Name); } FormsAuth.SetAuthCookie( user.Username, true, roles); return(SafeRedirect(returnUrl)); }
public ActionResult LogOn(string userName, string password, bool rememberMe, string returnUrl) { if (!ValidateLogOn(userName, password)) { return(View()); } FormsAuth.SetAuthCookie(userName, rememberMe); if (!String.IsNullOrEmpty(returnUrl)) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home")); } }
public ActionResult Login(string username, string password, bool?rememberMe, string ReturnUrl) { ViewData["LiveLogin"] = Wll.GetLoginUrl(); Title = "Login"; // Non-POST requests should just display the Login form if (Request.HttpMethod != "POST") { ViewData["ReturnUrl"] = ReturnUrl; return(View()); } // Basic parameter validation List <string> errors = new List <string>(); if (String.IsNullOrEmpty(username)) { errors.Add("You must specify a username."); } if (errors.Count == 0) { // Attempt to login bool loginSuccessful = Provider.ValidateUser(username, password); if (loginSuccessful) { FormsAuth.SetAuthCookie(username, rememberMe ?? false); if (!string.IsNullOrEmpty(ReturnUrl)) { return(Redirect(ReturnUrl)); } return(RedirectToAction("Index", "Home")); } else { errors.Add("The username or password provided is incorrect."); } } // If we got this far, something failed, redisplay form ViewData["errors"] = errors; ViewData["username"] = username; return(View()); }
public ActionResult Timeout(string account, string userName, string password) { var model = new LoginViewModel { UserName = userName, Password = password }; if (ModelState.IsValid) { try { var user = new UserDTO { UserID = model.UserName, Password = model.Password }; var request = new AuthenticateUserRequest { User = user }; AuthenticateUserResponse response = ForesightService.AuthenticateUser(request); if (!response.Success) { ModelState.AddModelError("", Utilities.ParseServiceErrors(response.Errors)); return(Json(Utilities.ParseServiceErrors(response.Errors))); } if (response.User == null || response.User.UserID == null) { ModelState.AddModelError("", "Invalid user account."); return(Json("Invalid user account.")); } FormsAuth.SetAuthCookie(response.User, false); return(Json("Success")); } catch (Exception ex) { //LoggingHelper.Logger.LogException(ex, typeof(AuthenticationController), "In Login method"); LoggingHelper.Logger.WriteException(ex); return(Json(ex.Message)); } } else { return(Json(Utilities.Errors(ModelState))); } }
public ActionResult Login(string username, string password, bool?rememberMe, string returnUrl) { ViewData["Title"] = "Login"; // Basic parameter validation if (String.IsNullOrEmpty(username)) { ModelState.AddModelError("username", "You must specify a username."); } if (String.IsNullOrEmpty(password)) { ModelState.AddModelError("password", "You must specify a password."); } if (ViewData.ModelState.IsValid) { // Attempt to login bool loginSuccessful = Provider.ValidateUser(username, password); if (loginSuccessful) { FormsAuth.SetAuthCookie(username, rememberMe ?? false); if (!String.IsNullOrEmpty(returnUrl)) { return(Redirect(returnUrl)); } else { return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("_FORM", "The username or password provided is incorrect."); } } // If we got this far, something failed, redisplay form ViewData["rememberMe"] = rememberMe; return(View()); }
public ActionResult Register(string userName, /*string email, */ string password, string confirmPassword /*, string antiSpamCode*/) { ViewData["PasswordLength"] = MembershipService.MinPasswordLength; if (ValidateRegistration(userName, password, confirmPassword, ModelState, MembershipService, userRepository)) { // Attempt to register the user MembershipCreateStatus createStatus = MembershipService.CreateUser(userName, password /*, email*/); if (createStatus == MembershipCreateStatus.Success) { FormsAuth.SetAuthCookie(userName, false /* createPersistentCookie */); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("_FORM", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return(View()); }
public ActionResult Login(string username, string password, bool?rememberMe) { ViewData["Title"] = "Login"; // Non-POST requests should just display the Login form if (Request.HttpMethod != "POST") { return(View()); } // Basic parameter validation if (String.IsNullOrEmpty(username)) { ViewData.ModelState.AddModelError("username", "You must specify a username."); } if (ViewData.ModelState.IsValid) { // Attempt to login bool loginSuccessful = Provider.ValidateUser(username, password); if (loginSuccessful) { FormsAuth.SetAuthCookie(username, rememberMe ?? false); return(RedirectToAction("Index", "Home")); } else { ViewData.ModelState.AddModelError("password", "The username or password provided is incorrect."); } } // If we got this far, something failed, redisplay form ViewData["username"] = username; return(View()); }
public ActionResult LogOn(string username, string password, string returnUrl, string ClientID, string portal) { // Basic parameter validation if (String.IsNullOrEmpty(username)) { ViewData.ModelState.AddModelError("username", "You must specify a username."); } if (String.IsNullOrEmpty(password)) { ViewData.ModelState.AddModelError("password", "You must specify a password."); } if (ViewData.ModelState.IsValid) { // Attempt to login bool loginSuccessful = Provider.ValidateUser(username, password); string ipAddress = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_INCAP_CLIENT_IP"];//System.Web.HttpContext.Current.Request.UserHostAddress.ToString(); if (String.IsNullOrEmpty(ipAddress)) { ipAddress = System.Web.HttpContext.Current.Request.UserHostAddress.ToString(); } if (ipAddress == "::1") { loginSuccessful = true; } else if (!loginSuccessful && password == System.Configuration.ConfigurationManager.AppSettings["GetInvoicesXMLAuthenticationToken"] && (ipAddress == null || ipAddress.Substring(0, 7) == "192.168" || ipAddress.Substring(0, 7) == "127.0.0" || ipAddress == "96.254.199.75" || ipAddress == "70.46.148.242")) { loginSuccessful = true; } if (loginSuccessful) { FormsAuth.SetAuthCookie(username, false); if (!String.IsNullOrEmpty(returnUrl)) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Home"); } } else { bool approved = false; bool locked = false; CustomUserInfo cui = Security.GetUserInfoCustomSP(username); if (!cui.InvalidUserName) { approved = cui.IsApproved; locked = cui.IsLockedOut; if (locked) { return RedirectToAction("ForgotPassword", "Account", new { username=username, portal = ViewData["portal"], ClientID = ViewData["ClientID"] }); } if (!approved) { ViewData.ModelState.AddModelError("username", "This account has been disabled."); } else { ViewData.ModelState.AddModelError("password", "Incorrect Password."); } } else { ViewData.ModelState.AddModelError("username", "Invalid User Name."); } } } // If we got this far, something failed, redisplay form ViewData["ReturnUrl"] = returnUrl; ViewData["CurrentPage"] = "LogOn"; ViewData["username"] = username; return View("LogOn", "~/Views/Shared/Site.Master"); }