示例#1
0
 private void ValidateUserExists(User user, IDto dto)
 {
     if (user == null)
     {
         Logger.LogWarning($"User not found, dto:{dto.ToJson()}");
         throw new LocalException("NotFound", HttpStatusCode.NotFound);
     }
 }
 private async Task ValidatePasswordsMatch(User user, string password, IDto dto)
 {
     if (!await _userManager.CheckPasswordAsync(user, password))
     {
         Logger.LogWarning($"Login failed, dto:{dto.ToJson()}, user: {user.ToJson()}");
         throw new LocalException("Unauthorized", HttpStatusCode.Unauthorized);
     }
 }
 private void ValidateUserAllowed(User user, IDto dto)
 {
     if (user == null)
     {
         Logger.LogWarning($"User not found, dto:{dto.ToJson()}");
         throw new LocalException("Unauthorized", HttpStatusCode.Unauthorized);
     }
 }
 private async Task ValidateEmailNotConfirmed(User user, IDto dto)
 {
     if (await _userManager.CanSignInAsync(user))
     {
         Logger.LogWarning($"User Email already confirmed, dto:{dto.ToJson()}, user: {user.ToJson()}");
         throw new LocalException("Email already confirmed", HttpStatusCode.Unauthorized);
     }
 }
 private void ValidateUserNotLocked(User user, IDto dto)
 {
     if (user.LockoutEnabled)
     {
         Logger.LogWarning($"User locked, dto:{dto.ToJson()}, user: {user.ToJson()}");
         throw new LocalException("Accound locked", HttpStatusCode.Unauthorized);
     }
 }
示例#6
0
        public static async Task <HttpResponseMessage> PostAsync(
            this HttpClient client,
            string path,
            ITestOutputHelper output,
            IDto dto
            )
        {
            var builder = BuildPath(client, path);

            output.WriteLine($"METHOD POST, url:'{builder.Uri.PathAndQuery}' dto:'{dto.ToJson()}'");
            return(await WriteApiErrorAsync(await client.PostAsync(builder.Uri.PathAndQuery, dto.ToStringContent()), output));
        }
示例#7
0
        public static async Task <HttpResponseMessage> PutByIdAsync <TPrimaryKey>(
            this HttpClient client,
            string path,
            ITestOutputHelper output,
            TPrimaryKey id,
            IDto dto
            )
        {
            var builder = BuildPathWithEntity(client, path, id);

            output.WriteLine($"METHOD PUT, url:'{builder.Uri.PathAndQuery}' dto:'{dto.ToJson()}'");
            return(await WriteApiErrorAsync(await client.PutAsync(builder.Uri.PathAndQuery, dto.ToStringContent()), output));
        }
示例#8
0
 private void ValidateRoleExists(Role role, IDto dto, User currentUser)
 {
     if (role == null)
     {
         Logger.LogWarning($"Role not found, currentUser:{currentUser.ToJson()}, dto:{dto.ToJson()}");
         throw new LocalException("NotFound", HttpStatusCode.NotFound);
     }
 }