예제 #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);
     }
 }
예제 #2
0
 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);
     }
 }
예제 #3
0
 private void ValidateUserAllowed(User user, IDto dto)
 {
     if (user == null)
     {
         Logger.LogWarning($"User not found, dto:{dto.ToJson()}");
         throw new LocalException("Unauthorized", HttpStatusCode.Unauthorized);
     }
 }
예제 #4
0
 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);
     }
 }
예제 #5
0
 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);
     }
 }