Пример #1
0
        public async Task UserLogin()
        {
            var userModel = new SysUser();

            userModel.Id         = Guid.NewGuid();
            userModel.CreateTime = DateTime.Now;
            userModel.Account    = "aruan";
            userModel.Email      = "*****@*****.**";
            userModel.PassWord   = "******".ToMd5Caps16();
            _userRepository.AddUser(userModel);
            await _unitOfWork.SaveAsync();

            var resultTrue = await _userRepository.UserLoginAync("aruan", "123456".ToMd5Caps16());

            Assert.True(resultTrue != null);
            var resultFalse = await _userRepository.UserLoginAync("zhangsan", "123456".ToMd5Caps16());

            Assert.False(resultFalse != null);
        }
Пример #2
0
        public async Task <IActionResult> Login([FromBody] UserLoginResource userLogin)
        {
            if (string.IsNullOrEmpty(userLogin.Account) || string.IsNullOrEmpty(userLogin.PassWord))
            {
                return(NotFound());
            }
            var user = await _userRepository.UserLoginAync(userLogin.Account, userLogin.PassWord.ToMd5Caps16());

            if (user == null)
            {
                return(NotFound("用户名或密码错误"));
            }
            var userResult = _mapper.Map <UserResource>(user);

            userResult.Token = _jwtServcie.CreateToken(user.Id.ToString(), user.Account);
            return(Ok(userResult));
        }