public ActionResult Index(LoginData data) { Compression.SetCompression(); if ((string.IsNullOrEmpty(data.Name) || string.IsNullOrEmpty(data.Password)) && (string.IsNullOrEmpty(data.RegName) || string.IsNullOrEmpty(data.RegPassword))) return View(data); if (!string.IsNullOrEmpty(data.Name) && !string.IsNullOrEmpty(data.Password)) { var res = Model.LoginUser(data.Name, data.Password); if (res.NoSuchUser) { data.IsError = true; data.Error = "No such user name."; return View(data); } if (res.BadPassword) { data.IsError = true; data.Error = "Incorrect password."; return View(data); } if (!string.IsNullOrEmpty(res.Error)) { data.IsError = true; data.Error = res.Error; return View(data); } return this.RedirectToAction("UsersStuff"); } if (!string.IsNullOrEmpty(data.RegName) && !string.IsNullOrEmpty(data.RegPassword)) { if (data.RegName.Length > 100 || data.RegPassword.Length > 100) { data.IsError = true; data.Error = "User name and password should be shorter than 100 characters."; return View(data); } var res = Model.RegisterUser(data.RegName, data.RegPassword); if (res.NameTaken) { data.IsError = true; data.Error = "This name already taken."; return View(data); } if (!string.IsNullOrEmpty(res.Error)) { data.IsError = true; data.Error = res.Error; return View(data); } return this.RedirectToAction("UsersStuff"); } return View(data); }
public ActionResult Index(LoginData data) { Compression.SetCompression(); data.IsError = false; data.Error = null; if ((string.IsNullOrEmpty(data.Name) || string.IsNullOrEmpty(data.Password)) && (string.IsNullOrEmpty(data.RegName) || string.IsNullOrEmpty(data.RegPassword))) { return(View(data)); } if (!string.IsNullOrEmpty(data.Name) && !string.IsNullOrEmpty(data.Password)) { var res = Model.LoginUser(data.Name, data.Password); if (res.NoSuchUser) { data.IsError = true; data.Error = "No such user name."; return(View(data)); } if (res.BadPassword) { data.IsError = true; data.Error = "Incorrect password."; return(View(data)); } if (!string.IsNullOrEmpty(res.Error)) { data.IsError = true; data.Error = res.Error; return(View(data)); } if (!string.IsNullOrEmpty(data.redirectInfo)) { return(this.Redirect(Utils.Utils.BaseUrl + data.redirectInfo)); } else { return(this.RedirectToAction("UsersStuff")); } } if (!string.IsNullOrEmpty(data.RegName) && !string.IsNullOrEmpty(data.RegPassword)) { if (data.RegName.Length > 100 || data.RegPassword.Length > 100) { data.IsError = true; data.Error = "User name and password should be shorter than 100 characters."; return(View(data)); } var res = Model.RegisterUser(data.RegName, data.RegPassword); if (res.NameTaken) { data.IsError = true; data.Error = "This name is already taken."; return(View(data)); } if (!string.IsNullOrEmpty(res.Error)) { data.IsError = true; data.Error = res.Error; return(View(data)); } if (!string.IsNullOrEmpty(data.redirectInfo)) { return(this.Redirect(Utils.Utils.BaseUrl + data.redirectInfo)); } else { return(this.RedirectToAction("UsersStuff")); } } return(View(data)); }