public ClientErrorsMiddleware(RequestDelegate next, ClientErrorManager clientErrorManager) { _next = next; _clientErrorManager = clientErrorManager; _jsonSerializerSettings = new JsonSerializerSettings(); _jsonSerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }
public static void OnInit(ClientErrorManager manager, FileServiceConfiguration configuration) { manager.AddErrors(new ClientErrors("FileService", new Dictionary <string, ClientError>() { { "too-big-file", new ClientError($"Too big file > {configuration.MaxSize} byte") }, { "file-load-err", new ClientError("File loading error") } })); }
public static void OnInit(ClientErrorManager manager) { manager.AddErrors(new ClientErrors("User", new Dictionary <string, ClientError> { { "u-inc-user-id", new ClientError("Incorrect user id!") }, { "u-inc-gettoken", new ClientError("Incorrect get user token!") } })); }
public static void OnInit(ClientErrorManager manager) { manager.AddErrors(new ClientErrors("Permission", new Dictionary <string, ClientError> { { "inc-perm-name", new ClientError("Incorrect permission name!") }, { "no-access", new ClientError("No access to this action!") } })); }
public static void OnInit(ClientErrorManager manager, ImageServiceConfiguration configuration) { manager.AddErrors(new ClientErrors("ImageService", new Dictionary <string, ClientError> { { "inc-photo-type", new ClientError("Incorrect photo type!") }, { "image-load-err", new ClientError("Image loading error!") }, { "too-big-image", new ClientError($"Too big image > {configuration.MaxSizeByte} byte") }, })); }
public static void OnInit(ClientErrorManager manager) { manager.AddErrors(new ClientErrors("RoleService", new Dictionary <string, ClientError> { { "inc-role-name", new ClientError("Incorrect role name!") }, { "inc-role-id", new ClientError("Incorrect role id!") } })); }
public static void OnInit(ClientErrorManager manager) { manager.AddErrors(new ClientErrors("DataBaseNotificationService", new Dictionary <string, ClientError> { { "inc-ntf-id", new ClientError("Incorrect notification id!") } } )); }
public static void OnInit(ClientErrorManager manager) { manager.AddErrors(new ClientErrors("TokenService", new Dictionary <string, ClientError> { { "inc-refresh-token", new ClientError("Incorrect refresh token!") }, { "inc-token", new ClientError("Incorrect token!") }, { "no-uuid", new ClientError("No UUID!") }, { "inc-uuid", new ClientError("Incorrect UUID!") }, { "no-token", new ClientError("No token!") } })); }
public static void OnInit(ClientErrorManager manager) { manager.AddErrors(new ClientErrors("Registration", new Dictionary <string, ClientError> { { "r-token-inc", new ClientError("Incorrect registration token!") }, { "r-token-already-used", new ClientError("User with this registration token is already registered!") }, { "r-login-alrd-reg", new ClientError("User with this login is already registered!") }, { "r-email-alrd-reg", new ClientError("User with this email is already registered!") }, { "r-ch-pass-token-inc", new ClientError("Change password token incorrect") }, { "r-email-no-reg", new ClientError("Change password token incorrect") } })); }
public static void OnInit(ClientErrorManager manager, IValidatingService validatingService) { manager.AddErrors(new ClientErrors("DirectMessagesService", new Dictionary <string, ClientError>() { { "inc-chatid", new ClientError("Incorrect chat!") }, { "inc-message-id", new ClientError("Incorrect message id!") } })); validatingService.AddValidateFunc("dr-text-message", (string prop, PropValidateContext context) => { if (prop == null) { return; } if (prop.Length < 1 || prop.Length > 300) { context.Valid.Add($"[dr-text-message-inc-length, [pn-{context.PropName}]]"); } }); }
public static void OnInit(ClientErrorManager manager, IValidatingService validatingService) { manager.AddErrors(new ClientErrors("Validating", new Dictionary <string, ClientError> { { "v-func-no", new ClientError("No validation function to property!") }, { "v-dto-invalid", new ClientError("Invalid dto!") } })); validatingService.AddValidateFunc("not-null", (object prop, PropValidateContext context) => { if (prop == null) { context.Valid.Add($"Please input {context.PropName}!"); } }); validatingService.AddValidateFunc("str-input", (string prop, PropValidateContext context) => { if (string.IsNullOrEmpty(prop)) { context.Valid.Add($"Please input {context.PropName}!"); } }); }
public static void OnInit(ClientErrorManager manager, IValidatingService validatingService, SubjectServiceConfiguration configuration) { manager.AddErrors(new ClientErrors("PupilSubject", new Dictionary <string, ClientError> { { "u-inc-subject-id", new ClientError("Incorrect subject id!") } })); validatingService.AddValidateFunc("str-sb-name", (string prop, PropValidateContext ctx) => { if (prop == null) { return; } if (prop.Length > configuration.MaxCountCharsName) { ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {255}]"); } /*if (prop.Length < configuration.MinCountCharsName) * ctx.Valid.Add($"[str-too-short, [pn-{ctx.PropName}], {255}]"); * if (!Regex.Match(prop, "^[ а-яА-ЯҐґЄєІіЇї]+$").Success) * ctx.Valid.Add($"[str-no-spc-ch-2, [pn-{ctx.PropName}]]"); //"Name musn't have specials chars!"*/ }); validatingService.AddValidateFunc("str-sb-comment", (string prop, PropValidateContext ctx) => { if (prop == null) { return; } if (prop.Length > configuration.MaxCountCharsComment) { ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {255}]"); } /*if (!Regex.Match(prop, "^[ а-яА-ЯҐґЄєІіЇї]+$").Success) * ctx.Valid.Add($"[str-no-spc-ch-2, [pn-{ctx.PropName}]]"); //"Comment musn't have specials chars!"*/ }); validatingService.AddValidateFunc("number-day-sb", (string prop, PropValidateContext ctx) => { int value; if (prop == null || !Int32.TryParse(prop, out value)) { return; } if (value > configuration.MaxDayNumber || value < configuration.MinDayNumber) { ctx.Valid.Add($"[inc-number-day]"); } }); validatingService.AddValidateFunc("number-lesson-sb", (string prop, PropValidateContext ctx) => { int value; if (prop == null || !Int32.TryParse(prop, out value)) { return; } if (value > configuration.MaxLessonNumber || value < configuration.MinLessonNumber) { ctx.Valid.Add($"[inc-number-lesson]"); } }); }
public static void OnInit(ClientErrorManager manager, IValidatingService validatingService, RegistrationServiceConfiguration configuration) { manager.AddErrors(new ClientErrors("Login", new Dictionary <string, ClientError>() { { "l-user-banned", new ClientError("User banned!") }, { "l-pass-log-inc", new ClientError("Incorrect login or password!") }, { "l-too-many-devices", new ClientError("Too many devices logged!") } })); validatingService.AddValidateFunc("date-birthday", (DateTime? prop, PropValidateContext context) => { if (prop == null) { return; } if (prop.Value == null || prop.Value > DateTime.Now) { context.Valid.Add($"[r-date-birthday-incorrect]"); } }); validatingService.AddValidateFunc("str-email-reg-no", (string prop, PropValidateContext context) => { if (prop == null) { return; } if (context.SeriviceProvider.GetService <IUserService>().IsIssetByEmail(prop)) { context.Valid.Add($"[r-email-reg]"); // "User with this email is already registered!" } }); validatingService.AddValidateFunc("str-login", (string prop, PropValidateContext ctx) => { if (prop == null) { return; } if (prop.Length > configuration.MaxCountCharsLogin) { ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {configuration.MaxCountCharsLogin}]"); // "Too long login(max {_configuration.MaxCountCharsLogin} characters)!" } if (!Regex.Match(prop, "^[a-zA-Z_0-9]*$").Success) { ctx.Valid.Add($"[str-no-spc-ch, [pn-{ctx.PropName}]]"); // "Login musn't have specials chars!" } }); validatingService.AddValidateFunc("str-creds", (string prop, PropValidateContext ctx) => { if (prop == null) { return; } if (prop.Length > configuration.MaxCountCharsName) { ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {255}]"); } if (!Regex.Match(prop, "^[а-яА-ЯҐґЄєІіЇї]+$").Success) { ctx.Valid.Add($"[str-no-spc-ch-2, [pn-{ctx.PropName}]]"); //"Name musn't have specials chars!" } }); validatingService.AddValidateFunc("str-password", (string prop, PropValidateContext ctx) => { if (prop == null) { return; } if (prop.Length > configuration.MaxCountCharsPassword) { ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {configuration.MaxCountCharsPassword}]");//$"Too long password(max{} characters)!" } if (prop.Length < configuration.MinCountCharsPassword) { ctx.Valid.Add($"[str-too-sh, [pn-{ctx.PropName}], {configuration.MaxCountCharsPassword}]");//$"Password must have {_configuration.MinCountCharsPassword} and more chars! } if (!prop.Any(c => char.IsDigit(c))) { ctx.Valid.Add($"[str-no-dig, [pn-{ctx.PropName}]]");//$"Password must have minimum one digit!" } }); validatingService.AddValidateFunc("str-password-rep", (string prop, PropValidateContext ctx) => { if (prop == null || ctx.TypeDto.GetProperty("Password") == null || ctx.TypeDto.GetProperty("Password").GetValue(ctx.Dto) == null) { return; } if (prop != (string)ctx.TypeDto.GetProperty("Password").GetValue(ctx.Dto)) { ctx.Valid.Add($"[str-inc-rep, [pn-{ctx.PropName}]]"); //$"Incorrect repeat password!" } }); validatingService.AddValidateFunc("str-email", (string prop, PropValidateContext context) => { if (prop == null) { return; } if (!Regex.IsMatch(prop, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$")) { context.Valid.Add($"[v-str-email, [pn-{context.PropName}]]"); } }); }
public ErrorsController(ClientErrorManager clientErrorManager) => _clientErrorManager = clientErrorManager;
public static void OnInit(ClientErrorManager manager, IValidatingService validatingService, LanguageStringServiceConfiguration configuration) { manager.AddErrors(new ClientErrors("LanguageStringService", new Dictionary <string, ClientError> { { "lss-inc-lang-str", new ClientError("Incorrect language string!") }, { "lss-lng-ald-reg", new ClientError("Language already registered!") }, { "lss-lng-no-reg", new ClientError("Incorrect language!") }, { "lss-type-ald-reg", new ClientError("Type already registered!") }, { "lss-type-no-reg", new ClientError("Incorrect type!") }, { "lss-strid-ald-reg", new ClientError("String id already registered!") }, { "lss-strid-no-reg", new ClientError("Incorrect string id!") }, { "lss-baseupateid-inc", new ClientError("Incorrect base update id!") } })); validatingService.AddValidateFunc("lss-lng-name", (string som, PropValidateContext ctx) => { if (som == null) { return; } else if (som.Length != 2) { ctx.Valid.Add($"[lss-inc-lang-str]"); } }); validatingService.AddValidateFunc("lss-lng-type", (string som, PropValidateContext ctx) => { if (som == null) { return; } else if (som.Length > configuration.MaxTypeNameLength) { ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {configuration.MaxTypeNameLength}]"); //"Too long login(max {_configuration.MaxCountCharsLogin} characters)!" } }); validatingService.AddValidateFunc("lss-str-id-name", (string som, PropValidateContext ctx) => { if (som == null) { return; } else if (som.Length > configuration.MaxStringIdNameLength) { ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {configuration.MaxStringIdNameLength}]"); } }); validatingService.AddValidateFunc("lss-str-name", (string som, PropValidateContext ctx) => { if (som == null) { return; } else if (som.Length > configuration.MaxStringLength) { ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {configuration.MaxStringLength}]"); } }); validatingService.AddValidateFunc("lss-lng-full-name", (string som, PropValidateContext ctx) => { if (som == null) { return; } else if (som.Length > configuration.MaxLangFullNameLength) { ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {configuration.MaxLangFullNameLength}]"); } }); }