Exemplo n.º 1
0
        public async Task <LoginOutputModel> LoginAsync(LoginInputModel loginInputModel)
        {
            Guard.ArgumentIsNotNull(loginInputModel, nameof(loginInputModel));
            Guard.ArgumentNotNullOrEmpty(loginInputModel.UserName, nameof(loginInputModel.UserName));
            Guard.ArgumentNotNullOrWhiteSpace(loginInputModel.Password, nameof(loginInputModel.Password));

            var user = await _userRepository.GetAsync(x => x.Name == loginInputModel.UserName);

            if (!user.IsActivie)
            {
                throw new CustomException("User is not activie.");
            }
            if (user.Password != loginInputModel.Password)
            {
                throw new CustomException("Username or password is error.");
            }
            string token = _clientContext.CreateToken(new
            {
                Id       = user.Id,
                UserName = user.Name
            });

            return(new LoginOutputModel()
            {
                ReturnUrl = string.Empty,
                Token = token
            });
        }