예제 #1
0
        public async Task <string> CreateAsync(User user)
        {
            await _users.InsertOneAsync(user);

            var response = await _users.Find(x => x.Id == user.Id).FirstOrDefaultAsync();

            var token = GeneratingToken.GenerateToken(_appSettings.Secret, user);

            return(token);
        }
        public async Task <string> CreateAsync(UserRegisterDto userIn)
        {
            var user = _mapper.Map <User>(userIn);
            await DbSet.InsertOneAsync(user);

            var response = await DbSet.Find(_ => _.Id == user.Id).FirstOrDefaultAsync();

            var token = GeneratingToken.GenerateToken(_appSettings.Secret, response);

            return(token);
        }
예제 #3
0
        public async Task <string> AuthenticateAsync(string username, string password)
        {
            var user = await _users.Find(x => x.Username == username).FirstOrDefaultAsync();

            if (user == null)
            {
                return(null);
            }
            bool isValidPassword = BCrypt.Net.BCrypt.Verify(password, user.Password);

            if (isValidPassword == false)
            {
                return(null);
            }

            var token = GeneratingToken.GenerateToken(_appSettings.Secret, user);

            return(token);
        }