Beispiel #1
0
        //核查登陆密码和用户名是否正确(即在UserRepository仓储类中是否存在)
        public LoginUserModel Login(User user)
        {
            //1 实例化LoginUserModel对象
            //2 把Password转化为加密形式
            //3 在User仓储类找到用户名和密码 IsDel为false的实体
            //4.1没找到 返回error登陆模型
            //4.2找到返回ok登陆模型.更新User仓储类里面的landIp,lastLandTime属性
            ExceptionHelper.ThrowIfNull(user, "登陆用户", "登陆用户无效");
            LoginUserModel model = new LoginUserModel();
            var            md5   = new Tgnet.Security.MD5();

            user.Password = md5.Encrypt(user.Password);
            var userEntity = _IUserRepository.Entities.Where(u => u.UserName == user.UserName && u.Password == user.Password).FirstOrDefault();

            if (userEntity == null)
            {
                model.Status = "error";
                model.Msg    = "对不起,用户名或密码不正确";
                return(model);
            }

            //登陆模型赋值
            model.Status   = "ok";
            model.Msg      = "登陆成功";
            model.UserId   = userEntity.UserId;
            model.UserName = userEntity.UserName;
            //找到仓储类中userid等于 userEntity.userId的实体
            return(model);
        }
Beispiel #2
0
        public IUserService add(User user)
        {
            ExceptionHelper.ThrowIfNull(user, "用户", "用户对象为空");
            var md5 = new Tgnet.Security.MD5();

            user.Password = md5.Encrypt(user.Password);
            _IUserRepository.Add(user);
            _IUserRepository.SaveChanges();
            return(GetService(user.UserId));
        }
Beispiel #3
0
        public IUserService Add(DIary.Data.Users user)
        {
            //user.createTime = DateTime.Now;
            var md5 = new Tgnet.Security.MD5();

            user.Password = md5.Encrypt(user.Password);
            _UserRepository.Add(user);
            _UserRepository.SaveChanges();
            IUserService _UserService = new UserService(_UserRepository, user.Id);

            return(_UserService);
        }
Beispiel #4
0
        //用户登录
        public UserLoginModel Login(DIary.Data.Users user)
        {
            UserLoginModel model = new UserLoginModel();
            var            md5   = new Tgnet.Security.MD5();

            user.Password = md5.Encrypt(user.Password);
            var userEntity = _UserRepository.Entities.Where(u => u.UserName == user.UserName && u.Password == user.Password /* && !u.isDel*/).FirstOrDefault();

            if (userEntity == null)
            {
                model.Status = "error";
                model.Msg    = "对不起,用户名与密码不正确";
                return(model);
            }
            model.Status   = "ok";
            model.Msg      = "登陆成功";
            model.UserId   = userEntity.Id;
            model.UserName = userEntity.UserName;
            _UserRepository.Update(u => u.Id == userEntity.Id, l => new DIary.Data.Users()
            {
                landIp = user.landIp, lastLandTime = user.lastLandTime
            });
            return(model);
        }