public async Task <TodoFolder> Create(TodoFolderDTO itemDTO, string userId) { TodoFolder item = new TodoFolder() { Description = itemDTO.Description }; item.user = await _userSearcher.GetBy(x => x.Id == userId); return(await _folderSearcher.Insert(item)); }
public async Task <string> SignIn(UserDTO userDTO) { userDTO.Username = userDTO.Username.ToLower(); userDTO.Password = Constants.EncryptPwd(userDTO.Password); var result = await _userSearcher.GetBy(x => x.Username == userDTO.Username && x.Password == userDTO.Password); if (result != null) { var secretBytes = Encoding.UTF8.GetBytes(Constants.Secret); var key = new SymmetricSecurityKey(secretBytes); var algorithm = SecurityAlgorithms.HmacSha256; var signingCredentials = new SigningCredentials(key, algorithm); var token = new JwtSecurityToken( Constants.Issuer, Constants.Audiance, claims: new Claim[] { new Claim("userId", result.Id) }, notBefore: DateTime.Now, expires: DateTime.Now.AddDays(1), signingCredentials ); var tokenJson = new JwtSecurityTokenHandler().WriteToken(token); return(tokenJson); } else { return(null); } }