public void RegsiterUser(string account, string username, string description, string password1, string password2) { if (password1 != password2) { throw new UserException("2次密码输入不一致"); } if (password1.Length < 6) { throw new UserException("密码最小长度为6位"); } if (AccountExist(account)) { throw new UserException("用户名已经存在"); } UserSimp userSimp = new UserSimp() { Account = account, UserName = username, DelFlag = DelFlag.Normal, //头像,我们给一个默认值 Head = @"E:\ShareYou\ShareYou\Content\Image\Head\2c8d94e6-3d6b-4b61-8150-c3d3790b9ab8.png", //第一级的会员 MemberId = 0, //进行md5加密操作 Password = Md5String.GetMd5String(password1), }; UserInfo userinfo = new UserInfo() { Description = description, Email = "", EmailValidateCode = "", DelFlag = DelFlag.Normal, IsValide = EmailValide.NotValide, Follower = 0, Follow = 0, Liked = 0, Number = "", }; //异常继续往上抛出 DbSession.UserDal.AddUser(userSimp, userinfo); }
private void RememeberMe(string account, string md5Password, bool state) { if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(md5Password)) { throw new ArgumentNullException("用户名或者密码为空", innerException: null); } HttpCookie cookie1 = new HttpCookie("ck1", account); HttpCookie cookie2 = new HttpCookie("ck2", Md5String.GetMd5String(md5Password)); if (state) { cookie1.Expires = DateTime.Now.AddDays(7); cookie2.Expires = DateTime.Now.AddDays(7); } else { cookie1.Expires = DateTime.Now.AddDays(-7); cookie2.Expires = DateTime.Now.AddDays(-7); } Response.Cookies.Add(cookie1); Response.Cookies.Add(cookie2); }
//如果需要另外的Service来解决,必须new 对象出来,不然存在一个循环引用的问题,但是还是有好处的,就是避免了创建过多的对象出来 public UserSimp Login(string account, string password) { if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password)) { throw new UserException("密码或者账号为空,请重新输入"); } if (!AccountExist(account)) { throw new UserException("账户不存在,大兄弟!"); } DelFlag status = (DelFlag)Convert.ToInt32(DbSession.UserDal.GetUserStatus(account)); //可能存在异常,我们继续往上抛出 if (status == DelFlag.Deleted) //账户被删除 { throw new UserException("此用户已被删除,请申诉或者重新申请账户"); } if (status == DelFlag.Freeze) { throw new UserException("当前账户被冻结"); } //可以获取用户信息 UserSimp model = null; if (Md5String.GetMd5String(password) == DbSession.UserDal.GetPassword(account).ToString()) { //表示信息校验成功 //出现的异常继续往上抛出 model = DbSession.UserDal.GetUserSimp(account); } else { //密码错误,出现异常了 throw new UserException("用户密码错误"); } return(model); }