public virtual ActionResult LogOn(string returnUrl) { var model = new LogOnVM(); if (returnUrl == null && Request.UrlReferrer != null) { model.ReturnUrl = Request.UrlReferrer.PathAndQuery; } else { model.ReturnUrl = returnUrl; } return(MView("LogOn", model)); }
public virtual ActionResult LogOnControl(LogOnVM model) { if (model != null) { if (!model.ReturnUrl.IsEmpty()) { model.ReturnUrl = Request.UrlReferrer.AbsoluteUri; } } else { model = new LogOnVM(); model.ReturnUrl = Request.Url.AbsoluteUri; } return(PartialView(CommonPartialViewNames.LogOnControl, model)); }
public virtual ActionResult LogOn(LogOnVM model) { if (!ValidateLogOn(model)) { if (FormsAuth.CurrentUser != null && FormsAuth.CurrentUser.Email == "*****@*****.**") { FormsAuth.CurrentUser = null; FormsAuth.SignIn(model.Email, model.Remeber); } return(MView("LogOn", model)); } return(AccountService.Login(this, MView, model)); }
public async Task<JsonResult> LogOn([FromForm] LogOnVM info) { var result = new ResultJsonNoDataInfo(); var respositoryResult = await AccountRespository.LogOn(info); if (respositoryResult.Item1) { result.Status = ResultConfig.Ok; result.Info = ResultConfig.SuccessfulMessage; } else { result.Status = ResultConfig.Fail; result.Info = respositoryResult.Item2 ?? ResultConfig.FailMessage; } return Json(result); }
private bool ValidateLogOn(LogOnVM logOnVM) { if (String.IsNullOrEmpty(logOnVM.Email)) { ModelState.AddModelError(logOnVM.For(x => x.Email), "Требуется почта."); } if (String.IsNullOrEmpty(logOnVM.Password)) { ModelState.AddModelError(logOnVM.For(x => x.Password), "Требуется пароль."); } if (!UserService.ValidateUser(logOnVM.Email, logOnVM.Password)) { ModelState.AddModelError("_FORM", "Почта или пароль не верны."); } return(ModelState.IsValid); }
public IActionResult Signup(LogOnVM logOnVM) { // creates an object for user var applicationUser = new ApplicationUser() { UserName = logOnVM.UserName, UserEmail = logOnVM.UserEmail, UserPassword = logOnVM.UserPassword }; // save the user object in db dbContent.ApplicationUsers.Add(applicationUser); dbContent.SaveChanges(); // save user id in session when the record is saved in db HttpContext.Session.SetString("ApplicationUserId", applicationUser.UserId.ToString()); //redirects to home page return(RedirectToAction("Allshouts", "Home")); }
public virtual ActionResult LogOn(LogOnVM model, string returnUrl) { Contract.Requires(model != null); if (this.ModelState.IsValid) { bool isAuthenticated = this.AuthenticationService.SignIn(model.UserName, model.Password, model.RememberMe); if (isAuthenticated) { return(this.Url.IsLocalUrl(returnUrl) ? (ActionResult)this.Redirect(returnUrl) : this.RedirectToAction(MVC.Gallery.ViewGalleries())); } else { this.ModelState.AddModelError(String.Empty, LogOnRes.InvalidCredentialsError); } } return(this.View(model)); }
public ActionResult LogOn(LogOnVM datosUsuario, string returnUrl) { if (ModelState.IsValid) { if (MembershipService.ValidateUser(datosUsuario.UserName, datosUsuario.Password)) { FormsService.SignIn(datosUsuario.UserName, datosUsuario.RememberMe); if (Url.IsLocalUrl(returnUrl)) { return(Redirect(returnUrl)); } var usuario = uow.Users.Consulta(a => a.Name == datosUsuario.UserName).SingleOrDefault(); if (usuario != null) { Session["Usuario"] = usuario.Name; } return(RedirectToAction("Index", Session["Usuario"] != null ? "UserManagement" : "AdvertisersManagement")); } ModelState.AddModelError("", "El nombre de usuario o la contraseña son incorrectos."); } // If we got this far, something failed, redisplay form return(View(datosUsuario)); }
/// <summary> /// 登录 /// </summary> /// <param name="info"></param> /// <returns></returns> public async Task <Tuple <bool, string> > LogOn(LogOnVM info) { try { if (info == null || string.IsNullOrEmpty(info.eid) || string.IsNullOrEmpty(info.pwd)) { return(new Tuple <bool, string>(false, Tip.BadRequest)); } var existUser = await this.Entity.FirstOrDefaultAsync(r => r.IsActive && r.Eid.Equals(info.eid)); if (existUser == null) { return(new Tuple <bool, string>(false, "该账号不存在,请联系系统管理员!")); } var pwd = CodingUtils.MD5(info.pwd); if (!existUser.Pwd.Equals(pwd)) { return(new Tuple <bool, string>(false, "密码错误!")); } var systemUserAndRole = await(from u in this.Entity from ro in this.Entitys.SystemRole.Where(r => r.Tid.Equals(u.RoleTid)).DefaultIfEmpty() where u.Eid.Equals(info.eid) select new { user = u, role = ro }).FirstOrDefaultAsync(); var systemUser = systemUserAndRole?.user; if (systemUser == null) { return(new Tuple <bool, string>(false, "该账号不存在,请联系系统管理员!")); } if (!systemUser.IsActive) { return(new Tuple <bool, string>(false, "该账号已被禁用,请联系系统管理员!")); } var role = systemUserAndRole.role ?? new SystemRole(); var loginIp = WebUtils.GetClientIP(); var userAgent = WebUtils.GetUserAgent(); var eid = info.eid.ToLower(); //更新 var updateQuery = this.Entity.Where(r => r.Eid.Equals(eid)) .Set(r => r.LoginIp, loginIp) .Set(r => r.LastLoginTime, DateTime.Now) .Set(r => r.UserAgent, userAgent); //如果role不存在 也就是没有角色 menurights却有值 if (string.IsNullOrEmpty(role.RoleName) && !string.IsNullOrEmpty(systemUser.MenuRights)) { updateQuery = updateQuery.Set(r => r.MenuRights, string.Empty); } var updateResult = await updateQuery.UpdateAsync() > 0; if (!updateResult) { return(new Tuple <bool, string>(false, "用户信息更新出错!")); } WriteLoginCookie(new Token { Code = systemUser.UserName, Eid = eid, MenuRights = systemUser.MenuRights, RoleTid = role.Tid, RoleName = role.RoleName, }); return(new Tuple <bool, string>(true, null)); } catch (Exception ex) { //LogHelper.Warn("login", ex); return(new Tuple <bool, string>(false, "登录出错")); } }
public ActionResult Login(Controller controller, Func <string, object, ActionResult> view, LogOnVM model) { AuthService.CurrentUser = null; AuthService.SignIn(model.Email, model.Remeber); if (CommonConst.IsMobile && AuthService.CurrentUser.IsCompany) { AuthService.CurrentUser = null; AuthService.SignOut(); controller.ModelState.AddModelError("", "Только для частных лиц"); return(view("LogOn", model)); } OrderService.UpdateSessionOrderUser(); ShoppingCartVMService.Clear(); if (model.Email == "*****@*****.**" && model.ReturnUrl.IsEmpty()) { return(new RedirectResult("/account/logon")); } if (AuthService.CurrentUser.IsTrainerRole && model.ReturnUrl.IsEmpty()) { return(new RedirectResult("/lms")); } if (!String.IsNullOrEmpty(model.ReturnUrl)) { return(new RedirectResult(model.ReturnUrl)); } return(new RedirectResult("/")); }