public ActionResult login(UserLogOnModel model) { if (!_validateCodeService.CheckCode(model.ValidCode)) { _validateCodeService.ClearSession(); return(Json(new { result = false, message = "验证码不正确" }, JsonRequestBehavior.AllowGet)); } var userInfo = _accountInfoTask.GetAccount(model.Account); if (userInfo == null) { return(Json(new { result = false, message = "用户不存在" }, JsonRequestBehavior.AllowGet)); } if (userInfo.Password != CryptTools.HashPassword(model.Password)) { return(Json(new { result = false, message = "用户名或密码不正确" }, JsonRequestBehavior.AllowGet)); } // 添加登录日志 _accountLoginLogTask.Add(new AccountLoginLog { Account = userInfo.Account, CreateDate = DateTime.Now, IP = DNTRequest.GetIP(), }); // 更新购物车 FormsAuthServiceCookie.SignIn(model.Account, false); return(Json(new { result = true, message = string.Empty }, JsonRequestBehavior.AllowGet)); }
protected void ImageButton1_Click(object sender, EventArgs e) { string username = txtName.Text.ToString().Trim(); string password = txtPwd.Text.ToString().Trim(); if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password)) { msg.InnerHtml = "用户名或密码为空"; return; } UserEntryService userentry = new UserEntryService(); UserLogOnModel model = new UserLogOnModel() { Email = username, Password = password, RememberMe = false }; try { if (userentry.Logon(model) != null) { try { AuthorityManager.PermissionCheck("ManageSystem"); Response.Redirect("index.html"); } catch (AccessForbiddenException) {//访问拒绝 msg.InnerHtml = "您不是系统管理员,无法进入系统管理!"; } catch (ActionForbiddenException) { //禁止操作 msg.InnerHtml = "您的操作被拒绝,你没有进入后台的权限!"; } } else { msg.InnerHtml = "用户名或者密码错误"; } } catch (LogonException k) {//管理员被禁用 msg.InnerHtml = k.Message; } }
public bool UpdateDeviceId(UserLogOnModel userModel) { List <Parameter> param = new List <Parameter>(); param.Add(new Parameter("@UserId", userModel.Id)); param.Add(new Parameter("@DeviceId", userModel.DeviceId)); param.Add(new Parameter("@TenantId", userModel.TenantID)); Parameter p_IsError = new Parameter("@IsError", DBNull.Value, ParameterDirection.Output, DbType.Int16, 1); Parameter p_ErrorMsg = new Parameter("@ErrorMsg", DBNull.Value, ParameterDirection.Output, DbType.String, 16); param.Add(p_IsError); param.Add(p_ErrorMsg); var r = dataBaseService.ExecuteNonQuery(StoredProcedures.UpdateUserDeviceId, DBCommandType.Procedure, param.ToArray()); if (r > 0) { return(true); } return(false); }
public UserLogOnModel ValidateUserLogOn(UserLogOnModel logOnModel) { List <Parameter> param = new List <Parameter>(); param.Add(new Parameter("@Email", logOnModel.Email)); param.Add(new Parameter("@Password", logOnModel.Password)); param.Add(new Parameter("@TenantId", logOnModel.TenantID)); param.Add(new Parameter("@CreatedByEntity", logOnModel.CreatedByEntity)); Parameter p_IsError = new Parameter("@IsError", DBNull.Value, ParameterDirection.Output, DbType.Int16, 1); Parameter p_ErrorMsg = new Parameter("@ErrorMsg", DBNull.Value, ParameterDirection.Output, DbType.String, 16); param.Add(p_IsError); param.Add(p_ErrorMsg); var r = dataBaseService.ExecuteScalar(StoredProcedures.ValidateLoginDetail, DBCommandType.Procedure, param.ToArray()); int Id = Convert.ToInt16(r); if (Id > 0) { logOnModel.Success = true; logOnModel.Id = Id; } else if (Id == -3) { logOnModel.Success = false; logOnModel.ErrorMessage = "Phone Number not verified login failed"; } else if (Id == -2) { logOnModel.Success = false; logOnModel.ErrorMessage = "Invalid login."; } else if (Id == -4) { logOnModel.Success = false; logOnModel.ErrorMessage = "Invalid Email ID or User is not registered with this password."; } return(logOnModel); }
/// <summary> /// 用户登录 /// </summary> /// <param name="name">账户名</param> /// <param name="psd">账户密码</param> /// <returns>Account</returns> public Account Logon(UserLogOnModel model) { Account user = null; //创建账户仓储 IRepository <Account> accountRep = FBS.Factory.Factory <IRepository <Account> > .GetConcrete <Account>(); ISpecification <Account> namespec; if (string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.UserName)) { //昵称登录 namespec = new Specification <Account>(o => o.UserName == model.UserName); } else if (string.IsNullOrEmpty(model.UserName) && !string.IsNullOrEmpty(model.Email)) { //邮箱登录 namespec = new Specification <Account>(o => o.Email == model.Email);//查询条件 } else { throw new NullReferenceException("用户登录时,用户名和邮箱至少使用一个"); } if (accountRep.Exists(namespec))//这个账户是否存在 { user = accountRep.Find(namespec); if (!user.CheckPsd(model.Password)) { throw new LogonException("密码错误");//账户存在,密码错误 } else { if (new UserEntryService().CheckForbidden(user.Id)) { throw new LogonException("您由于不遵守相关规定,账户被禁用");//您由于不遵守相关规定,账户被禁用 } //将Identify更新到HttpContext中 UserIdentity u = new UserIdentity("Forms", true, user.Id.ToString()); /*UserInfoService uis=new UserInfoService(); * string[] roles=uis.GetUserRoles(user.Id);*/ string[] roles = user.Roles.Split('|'); if (roles == null) { roles = new string[1] { string.Empty } } ; System.Security.Principal.GenericPrincipal gp = new System.Security.Principal.GenericPrincipal(u, roles); HttpContext.Current.User = gp; //添加ticket到cookie FormsAuthenticationTicket ticket = AuthenticationHelper.CreateAuthenticationTicket(user.Id.ToString(), user.UserName, model.RememberMe); AuthenticationHelper.SetAuthenticalCookie(ticket); } } else { throw new LogonException("账户不存在");//账户不存在 } return(user); }