From 5b40cf6fb0afba6cee4c66c422198c254793b660 Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Thu, 28 Dec 2017 16:36:48 +0100 Subject: [PATCH] * Fix Web api exception manager * Added language support api * Added canRead canWrite to functions Access api --- Step.Config/StartupConfigController.cs | 2 + Step.Config/serverConfigValidator.xsd | 1 - .../Controllers/FunctionAccessController.cs | 10 +- Step.Database/Controllers/UsersController.cs | 6 +- Step.Database/DatabaseContext.cs | 4 + .../DTOModels/DTOFunctionAccessModel.cs | 4 + Step.Model/DTOModels/DTOLanguageModel.cs | 14 + Step.Model/DTOModels/DTOUserModel.cs | 19 + Step.Model/DatabaseModels/UserModel.cs | 17 + Step.Model/DatabaseModels/UserModel.cs.d.ts | 118 +++ Step.Model/Step.Model.csproj | 2 + Step.Utils/Constants.cs | 5 +- Step.Utils/LanguageController.cs | 116 +++ Step.Utils/Step.Utils.csproj | 11 + Step.Utils/languageValidator.xsd | 12 + Step.Utils/languages/IT.xml | 716 ++++++++++++++++++ Step.Utils/languages/en.xml | 6 + .../WebApi/ConfigurationController.cs | 16 +- Step/Controllers/WebApi/LanguageController.cs | 45 ++ Step/Controllers/WebApi/LoginController.cs | 19 +- Step/Listeners/Database/DatabaseTest.cs | 2 +- Step/Step.csproj | 1 + Step/WebApiUnhandledExceptionHandler.cs | 39 +- 23 files changed, 1158 insertions(+), 27 deletions(-) create mode 100644 Step.Model/DTOModels/DTOLanguageModel.cs create mode 100644 Step.Model/DTOModels/DTOUserModel.cs create mode 100644 Step.Utils/LanguageController.cs create mode 100644 Step.Utils/languageValidator.xsd create mode 100644 Step.Utils/languages/IT.xml create mode 100644 Step.Utils/languages/en.xml create mode 100644 Step/Controllers/WebApi/LanguageController.cs diff --git a/Step.Config/StartupConfigController.cs b/Step.Config/StartupConfigController.cs index e8db1725..75b68c8e 100644 --- a/Step.Config/StartupConfigController.cs +++ b/Step.Config/StartupConfigController.cs @@ -6,6 +6,7 @@ using static Step.Config.StartupConfig; using Step.Model.ConfigModels; using static Step.Utils.Constants; using Step.Utils; +using System.Collections.Generic; namespace Step.Config { @@ -58,6 +59,7 @@ namespace Step.Config } } + private static void SetAreaValueByName(XElement element) { // Choose which area to be set diff --git a/Step.Config/serverConfigValidator.xsd b/Step.Config/serverConfigValidator.xsd index 911ea8d4..fa86031e 100644 --- a/Step.Config/serverConfigValidator.xsd +++ b/Step.Config/serverConfigValidator.xsd @@ -24,7 +24,6 @@ - diff --git a/Step.Database/Controllers/FunctionAccessController.cs b/Step.Database/Controllers/FunctionAccessController.cs index b03a8df8..59cfa29e 100644 --- a/Step.Database/Controllers/FunctionAccessController.cs +++ b/Step.Database/Controllers/FunctionAccessController.cs @@ -26,20 +26,22 @@ namespace Step.Database.Controllers { return dbCtx .FunctionsAccess - .Where(x => x.Name == functionName && x.Enabled == true) + .Where(x => x.Name == functionName && x.Enabled == true) // Find by name and enabled functions .FirstOrDefault(); } - public List GetFunctionAccess() + public List GetFunctionAccess(int roleLevel) { return dbCtx .FunctionsAccess - .Select(f => new DTOFunctionAccessModel() + .Select(f => new DTOFunctionAccessModel() // Convert from database model to data transfer model { Id = f.FunctionAccessId, Name = f.Name, Area = f.Area, - Enabled = f.Enabled + Enabled = f.Enabled, + CanRead = f.ReadLevelMin < roleLevel, + CanWrite = f.WriteLevelMin < roleLevel }) .ToList() ; } diff --git a/Step.Database/Controllers/UsersController.cs b/Step.Database/Controllers/UsersController.cs index 3ed3cbba..bc38996f 100644 --- a/Step.Database/Controllers/UsersController.cs +++ b/Step.Database/Controllers/UsersController.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using System.Linq; using System.Web.Helpers; using Step.Model.DatabaseModels; @@ -21,7 +22,7 @@ namespace Step.Database.Controllers dbCtx.Dispose(); } - public void Create(string username, string password, string firstName, string lastName, int roleId) + public void Create(string username, string password, string firstName, string lastName, int roleId, CultureInfo language) { // Create a new user model with params UserModel user = new UserModel() @@ -31,7 +32,8 @@ namespace Step.Database.Controllers FirstName = firstName, LastName = lastName, RoleId = roleId, - SecurityStamp = Guid.NewGuid().ToString() + SecurityStamp = Guid.NewGuid().ToString(), + Language = language }; // Add to database dbCtx.Users.Add(user); diff --git a/Step.Database/DatabaseContext.cs b/Step.Database/DatabaseContext.cs index 8111c0f4..a4491052 100644 --- a/Step.Database/DatabaseContext.cs +++ b/Step.Database/DatabaseContext.cs @@ -46,5 +46,9 @@ namespace Step.Database } } } + protected override void OnModelCreating(DbModelBuilder modelBuilder) + { + System.Data.Entity.Database.SetInitializer(null); + } } } diff --git a/Step.Model/DTOModels/DTOFunctionAccessModel.cs b/Step.Model/DTOModels/DTOFunctionAccessModel.cs index a48eac33..dbb5849f 100644 --- a/Step.Model/DTOModels/DTOFunctionAccessModel.cs +++ b/Step.Model/DTOModels/DTOFunctionAccessModel.cs @@ -9,5 +9,9 @@ public string Area { get; set; } public bool Enabled { get; set; } + + public bool CanWrite { get; set; } + + public bool CanRead { get; set; } } } diff --git a/Step.Model/DTOModels/DTOLanguageModel.cs b/Step.Model/DTOModels/DTOLanguageModel.cs new file mode 100644 index 00000000..586475de --- /dev/null +++ b/Step.Model/DTOModels/DTOLanguageModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Step.Model.DTOModels +{ + public class DTOLanguageModel + { + public string Name; + public string IsoId; + } +} diff --git a/Step.Model/DTOModels/DTOUserModel.cs b/Step.Model/DTOModels/DTOUserModel.cs new file mode 100644 index 00000000..2ea571cd --- /dev/null +++ b/Step.Model/DTOModels/DTOUserModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Step.Model.DTOModels +{ + public class DTOUserModel + { + public int Id { get; set; } + public string Username { get; set; } + public string FirstName { get; set; } + public string LastName { get; set; } + public CultureInfo Language { get; set; } + public int RoleId { get; set; } + } +} diff --git a/Step.Model/DatabaseModels/UserModel.cs b/Step.Model/DatabaseModels/UserModel.cs index 45ab6eaf..fbd0bf2b 100644 --- a/Step.Model/DatabaseModels/UserModel.cs +++ b/Step.Model/DatabaseModels/UserModel.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Globalization; using System.Linq; using System.Runtime.Serialization; using System.Text; @@ -26,6 +27,22 @@ namespace Step.Model.DatabaseModels public string Password { get; set; } [Column("security_stamp")] public string SecurityStamp { get; set; } + [Column("language")] + public string _language { get; set; } + + [NotMapped] + public CultureInfo Language { + get { + if (_language != null) + return new CultureInfo(_language); + else + return new CultureInfo("en-US"); + } + set { + _language = value.TwoLetterISOLanguageName; + } + } + [Column("role_id")] public int RoleId { get; set; } [ForeignKey("RoleId")] diff --git a/Step.Model/DatabaseModels/UserModel.cs.d.ts b/Step.Model/DatabaseModels/UserModel.cs.d.ts index 1a48fd35..6293daa4 100644 --- a/Step.Model/DatabaseModels/UserModel.cs.d.ts +++ b/Step.Model/DatabaseModels/UserModel.cs.d.ts @@ -6,6 +6,124 @@ declare module server { lastName: string; password: string; securityStamp: string; + _language: string; + language: { + parent: any; + lCID: number; + keyboardLayoutId: number; + name: string; + ietfLanguageTag: string; + displayName: string; + nativeName: string; + englishName: string; + twoLetterISOLanguageName: string; + threeLetterISOLanguageName: string; + threeLetterWindowsLanguageName: string; + compareInfo: { + name: string; + lCID: number; + version: { + fullVersion: number; + sortId: any; + }; + }; + textInfo: { + aNSICodePage: number; + oEMCodePage: number; + macCodePage: number; + eBCDICCodePage: number; + lCID: number; + cultureName: string; + isReadOnly: boolean; + listSeparator: string; + isRightToLeft: boolean; + }; + isNeutralCulture: boolean; + cultureTypes: any; + numberFormat: { + currencyDecimalDigits: number; + currencyDecimalSeparator: string; + isReadOnly: boolean; + currencyGroupSizes: number[]; + numberGroupSizes: number[]; + percentGroupSizes: number[]; + currencyGroupSeparator: string; + currencySymbol: string; + naNSymbol: string; + currencyNegativePattern: number; + numberNegativePattern: number; + percentPositivePattern: number; + percentNegativePattern: number; + negativeInfinitySymbol: string; + negativeSign: string; + numberDecimalDigits: number; + numberDecimalSeparator: string; + numberGroupSeparator: string; + currencyPositivePattern: number; + positiveInfinitySymbol: string; + positiveSign: string; + percentDecimalDigits: number; + percentDecimalSeparator: string; + percentGroupSeparator: string; + percentSymbol: string; + perMilleSymbol: string; + nativeDigits: string[]; + digitSubstitution: any; + }; + dateTimeFormat: { + aMDesignator: string; + calendar: { + minSupportedDateTime: Date; + maxSupportedDateTime: Date; + algorithmType: any; + isReadOnly: boolean; + eras: number[]; + twoDigitYearMax: number; + }; + dateSeparator: string; + firstDayOfWeek: any; + calendarWeekRule: any; + fullDateTimePattern: string; + longDatePattern: string; + longTimePattern: string; + monthDayPattern: string; + pMDesignator: string; + rFC1123Pattern: string; + shortDatePattern: string; + shortTimePattern: string; + sortableDateTimePattern: string; + timeSeparator: string; + universalSortableDateTimePattern: string; + yearMonthPattern: string; + abbreviatedDayNames: string[]; + shortestDayNames: string[]; + dayNames: string[]; + abbreviatedMonthNames: string[]; + monthNames: string[]; + isReadOnly: boolean; + nativeCalendarName: string; + abbreviatedMonthGenitiveNames: string[]; + monthGenitiveNames: string[]; + }; + calendar: { + minSupportedDateTime: Date; + maxSupportedDateTime: Date; + algorithmType: any; + isReadOnly: boolean; + eras: number[]; + twoDigitYearMax: number; + }; + optionalCalendars: { + minSupportedDateTime: Date; + maxSupportedDateTime: Date; + algorithmType: any; + isReadOnly: boolean; + eras: number[]; + twoDigitYearMax: number; + }[]; + useUserOverride: boolean; + isReadOnly: boolean; + }; roleId: number; role: server.RoleModel; } diff --git a/Step.Model/Step.Model.csproj b/Step.Model/Step.Model.csproj index bb74478a..07c60cdd 100644 --- a/Step.Model/Step.Model.csproj +++ b/Step.Model/Step.Model.csproj @@ -68,7 +68,9 @@ + + DtsGenerator diff --git a/Step.Utils/Constants.cs b/Step.Utils/Constants.cs index b2ea08fc..3183c39d 100644 --- a/Step.Utils/Constants.cs +++ b/Step.Utils/Constants.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using System.Reflection; namespace Step.Utils @@ -53,6 +54,8 @@ namespace Step.Utils public const string STARTUP_CONFIG_SCHEMA_PATH = "serverConfigValidator.xsd"; public const string STARTUP_CONFIG_PATH = "serverConfig.xml"; public static string WEBSITE_DIRECTORY = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..", "wwwroot"); + public static string LANGUAGE_PACK_DIRECTORY = Environment.CurrentDirectory + "\\languages\\"; + public static string LANGUAGE_SCHEMA_PATH = Environment.CurrentDirectory + "\\LanguageValidator.xsd"; // MVVM Messages names public const string STOP_SERVER = "STOP_SERVER"; diff --git a/Step.Utils/LanguageController.cs b/Step.Utils/LanguageController.cs new file mode 100644 index 00000000..5e93823e --- /dev/null +++ b/Step.Utils/LanguageController.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; +using System.Xml.Schema; +using Step.Model.DTOModels; +using static Step.Utils.Constants; + +namespace Step.Utils +{ + public static class LanguageController + { + private static bool FileIsValid = true; + + public static bool LanguageIsAvailable(string language) + { + // Create a valid language + CultureInfo lang = CultureInfo.CreateSpecificCulture(language); + // File path with 2 letter iso language + string filePath = LANGUAGE_PACK_DIRECTORY + lang.TwoLetterISOLanguageName + ".xml"; + + if (!File.Exists(filePath)) + return false; + + return true; + } + + public static Dictionary GetTranslationsFromFile(string language) + { + CultureInfo lang = CultureInfo.CreateSpecificCulture(language); + + // File path with 2 letter iso language + string filePath = LANGUAGE_PACK_DIRECTORY + lang.TwoLetterISOLanguageName + ".xml"; + + // Open file reader + XDocument xmlLanguageFile = XDocument.Load(filePath); + + if (!ValidateTranslationsFile(xmlLanguageFile, LANGUAGE_SCHEMA_PATH)) + return null; + + // Read file content + return xmlLanguageFile + .Root + .Elements() + .ToDictionary(x => x.Name.ToString(), x => x.Value); // Populate dictionary + } + + public static List GetLanguageListFromDirectory() + { + // Check if directory exists + if (Directory.Exists(LANGUAGE_PACK_DIRECTORY)) + { + // Check if directory is empty + if (Directory.EnumerateFileSystemEntries(LANGUAGE_PACK_DIRECTORY).Any()) + { + // Read all the files in the lang directory + return Directory.GetFiles(LANGUAGE_PACK_DIRECTORY, "*.xml", SearchOption.TopDirectoryOnly) + .Select(Path.GetFileNameWithoutExtension) // Get only fileName without extensions + .Where(x => IsValidLanguage(x)) // Filter file names by valid language + .Select(x => + { + CultureInfo info = new CultureInfo(x); + DTOLanguageModel language = new DTOLanguageModel() // Create language model + { + IsoId = info.TwoLetterISOLanguageName, + Name = info.DisplayName + }; + return language; + }) + .ToList(); + } + } + + return null; + } + + public static bool IsValidLanguage(string language) + { + CultureInfo info = CultureInfo + .GetCultures(CultureTypes.AllCultures) + .FirstOrDefault(l => l.TwoLetterISOLanguageName == language.ToLower()); // Find user language from system language + + if (info == null) + return false; + + return true; + } + + private static bool ValidateTranslationsFile(XDocument xmlLanguageFile, string validatorFilePath) + { + FileIsValid = true; + + // Read validation file + XmlSchemaSet readerSettings = new XmlSchemaSet(); + + // Add Schema + readerSettings.Add(null, validatorFilePath); + + // Validate file + xmlLanguageFile.Validate(readerSettings, ValidationHandler); + + return FileIsValid; + } + + // Validation XML Callback + private static void ValidationHandler(object sender, ValidationEventArgs e) + { + if (e.Severity == XmlSeverityType.Error) + FileIsValid = false; + } + } +} diff --git a/Step.Utils/Step.Utils.csproj b/Step.Utils/Step.Utils.csproj index 966e2ab3..a0e45b95 100644 --- a/Step.Utils/Step.Utils.csproj +++ b/Step.Utils/Step.Utils.csproj @@ -57,6 +57,7 @@ + @@ -72,12 +73,22 @@ + + PreserveNewest + + + PreserveNewest + Always + + Designer + Always + Designer diff --git a/Step.Utils/languageValidator.xsd b/Step.Utils/languageValidator.xsd new file mode 100644 index 00000000..8791855d --- /dev/null +++ b/Step.Utils/languageValidator.xsd @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Step.Utils/languages/IT.xml b/Step.Utils/languages/IT.xml new file mode 100644 index 00000000..111d594b --- /dev/null +++ b/Step.Utils/languages/IT.xml @@ -0,0 +1,716 @@ + + + y/HFegHd + -2066498719 + 1860685434 + F5.- + <_jB-Kq0>deWZ#Bk8 + dsa + bce27MH + 2039088846 + aHMu'P2 + 1554429099 + R(FU{ + rLU6>d + w + + -212065089 + -1794801079.4703789 + 1012923155 + 62047108 + -1912608737.9336748 + +>Ga{]p + a + -1528878816 + 934194442 + 596993723.0300894 + + -8021282.129535198 + -823028280 + -1654039332 + -140825365.5927081 + -523119210 + -1080120520.784854 + -782822402.7251472 + 791852407.8211055 + Vnv + T + + -1719513217.9226694 + -762625776 + a>3 + 580806708.6443667 + + bo$fmb1(q + 1302652843.6182518 + 1325190456 + 864190376.9637222 + s + J zSckiC# + SMg + 1692413639 + l!Jq + Dp + 985999149 + K + -2094873448.2246876 + 1037301505 + lw$ + 4H{zE +614757124 +dY +7795790.926300049 +1207636378 +./QC +MAcFg +3e #E +Q +899108421.5259352 +1k OcPKTm +-1347859185.4381137 +

rl

+724434956 +-1936986856 +-343841438 +-2017165171.625389 +l>. +1264410702.3540845 +14021243 +-1988950205.069065 +CWea:g +-1326828555.354495 +2123439227 +Do[qpD + +1500211908.2668328 +Pz(mT}] + 6 + + 121376390 + edfM!+KH6 + -743758178.3693652 + -1628113861 + 1081990458 + 2087668800 + -2028109903.5773087 + 5rg0] + -1456952944 + au + 705321403.7867756 + bIS + aQgaU3Rfr + G?E:N + 1008293035.0852075 + -1461059270 + <_FPQk>TVGt@mr + -16635248 + 1062663098.2465863 + loQ>daHi + + gIO_TpJ: + [G + cYruN1B1S + -1939098853.981094 + KhS=DJ + la0V Am + qaaUqkC + + -874109009.2931776 + 1101436211 + 710772295.5882163 + ?j + 1887695682 + > + vE + 455439159.3777385 + 1857006180 + qI|iUnISH3 + 2051911684.9417243 + G + 1870097297.7620058 + dsa + 134456409.83928823 + !i7%bg{ + -636760692 + ]oCMJ + rN5[v'PS1/ + <_>8dPaa$X_ + 542019375.4165163 + 539777644.9207253 + WJ*./ + <_nn>-667280154.149219 + dK>d + ?9vF + -1677955836.128992 + 1319029938.0105343 + 391683969 + -298142307.94438124 + 1938582123.138022 + -2013717156.8798795 + 1045450214.2276983 + B. + 'kypv%Aoc + 988731875.2232418 + -2007128709.17421 + .wMc + -782429457.9704385 + -741753922 + + ku5? + -1637172905 + + 928965655.0342155 + 1370081768 + 1160005300 + fBn1ZN| + Kj + + 1587355193 + 565561646.697865 + 1723880396 + o.iPe'J + ntcQ + <_EEXIBo>TWf7 + + 1757313975.6840825 + 625561068 + + 236822624.8007679 + yef + -1719292510 + 2026242426 + BV-XmAy + mlYh}=e + 998231718 + 1253659329.231821 + -1089418720 + + dzbkq# + C + "f + <_DO2GMtlJ>-815667175.7918596 + <_uUu7-ExR>-333202163.3843498 + 0aOR + ap + VX%|]-E + -780818193 + -1192352790.3759956 + -1561230957.6635509 + 1895126526.3335605 + <_iM>-1276081954 + B + 1101094306 + 607776324 + 1324482825.4559765 + S0s + GY + ZCcp + 162970583 + -1200576521.6070485 + w0bx + pR$wpTB + -2065143210.5175118 + k5Vo@k + bN= + 25750141 + da + + 1025954690.8285728 + 1175664493.914415 + 1917843907 + 24734122.78042555 + !h| + -856046079 + 800376293 + aqk + 1838473922.3714938 + 2Wu1eNBD + 1918467505.4194236 + ci@?L + Q%jP"X0" + x9 + 154604863.41065216 + If4 + T}RBPn1 Z + 7iZ!_w2 + 2125363297.265583 + gUS + 280581659.2681775 + 508791731.0057411 + M6w]Y + -1463641597.6668296 + (H CKcYuY + + -1821747293.4638553 + 1273147662.012371 + 121477028.26737022 + -307713571 + .Q1c + (NHaXjQkNs + 6]poiEe4R + -362112673.4976716 + $+7 + Fk3 rrk + X-+ EZL + eb6e + 1472825728.432279 + od1/n$V -c + >xX + 1+uHU + + + 1621142990 + AexD + <_t3Aeu9x>-1679679108 + -345611992.14594984 + 616493139 + -225349268.56022167 + -904697958 + + 523729377.9066148 + -1971746037 + p + -194695400 + -387248282 + -293409494.542222 + }$xg{PBD@L + + 861600309 + + + dsad/| + D"Nc + + 1131290310 + b6e=| + c:/7mR + >]|n3 + U0? + a.Eed + RDl$V + 1621369933 + K#'za-% + -1377749154.4182882 + + -1548374889.5947247 + + $Ny + -17771399.193180084 + *eNH + -781266320 + + hyaWR62 + <_jOBElKTjX>-140025682 + (LeHhFvE + ?v?d + eb + -1381332872 + e + 387676359 + {a#csr + 593687457 + -754826879 + -943022755 + G{S@T% + =mbla + wsT + U + > + k + 1752710269 + -1674217128 + 1557768876.589839 + @ + 1489266832.5545983 + -116261699 + P#LHcY + kaL + <_w4yV>2047800758 + GU#DS + k + >:C5ll1w + 1562625613 + ]e*n + 3U8CaK + *q + zQf2Nsf + d + 1640670350 + hs]_oY + 1248495359.87637 + SSkK3m0Zs + 6T+'KKIL + -75185066.21870518 + -57471492 + g7Y + 1231857963 + + 1442199441.6588354 + Bn + oH fEH + #2[++ + -142985905.23829126 + q{RRVSxcjE + 650262835 + -2024170252 + -1495138186 + =Hk}5tS5 + a!YaQcA + -539122966 + -362171231 + tGu|r32?K + 4 + <_XvV4>eIat:7(@ + uYacjTH + =y}9 + -1674600918 + . + K!__3_S + 668784823 + [ + 1106623829.9086795 + 2105072458 + *2] + 1778004056 + 9aOx* + uA. + <_5IEj9Xxk>-723958431 + Q + y + Bk/rhlD + -2043557258.476581 + -901459201.1049943 + *Q3 + 562798007.1969137 + fd + + -2064402795 + T]czt + 265150190.3554716 + nxO/djx + <_dJ>-1777394095.1931577 + 2134455862.1668372 + 1415934789.4898276 + -1110446195 + *Z.G5(] + 1392026899 + f0ig + $o2lT'4XW$ + 1086669334 + 1275202113 + + B6AWdAGd + + 292119690 + 1202489203.001278 + -364415643 + i=l|aSab + -413350962 + $HlG + 1044894652.8120313 + 2080362882 + C9 + >zfp + pxx5 + Xc| + -b>Q"%GeMH + -444306210 + 5D-i + -1583030936 + p%!h + (@%sAmahW + 548385111.1802545 + 1705248297 + <_p>153268313 + -1034706746.4163527 + -8SaUi:{T + k uzh]h:n + 1039018139 + ]"{ + tk3i>I + oGb$cde7 + -1416166209 + ZHt1h/} + -1175720091 + H:R*oyd{| + R{lWb + nL + -1783987497.7754045 + -558245207.8176942 + -37187376.966434956 + -1054331522 + 295613609 + -63043179 + 3R[_jd{w + 9M]cqB + -282962179 + m'I'}wdT7O + *D + 773580395.4962468 + 630878080.0353551 + -285132628.0263343 + ll4BSYesS + 1569584137 + nUm_}4Xb + 2024589873.8369856 + $eFv + 958488357 + 345908125 + + OaaM$44 + 1777983013.930757 + -1527675342.5925145 + R5@N? + -2067037475 + 1907258817.7024498 + <_z_X>-190223905.6631813 + !bLi=7 + E + -1543385477.9222417 + -1880579253 + 1210187770 + w4Tg0 +

645360592

+ b3aA r% + 2131721854 + -513281063.42213345 + -1610507654 + #ptv.!r + 1951949339.419662 + 781810219.7073197 + afJ + LJw9Uxj + -1767703086 + 1336548128 + B.A + wrJ + + #ih5dx#TA + -1843807268 + 851641601 + P + -13029054 + Q?# + l#T= + + 2VzgmhVc + 511640407 + 4vv + j=vmw|#. + e + 1259240018 + HzG1ggM?H + 056u+ + 152126662.98062086 + h + 568696777.2994442 + 665549380.6073685 + 0aY?Df(2 + o + ]]*aZh + YK + 3?j}_4lR + GzRO + 1322865096 + 418059163 + Ub5fjr1 + + 2098650165.2776895 + he/B%/E + kAXhDx + -886076109.5690174 + 259905092 + fourwPG + S + 1875836782 + 0jV + 1172034461 + 1* + -48843166.8945322 + X64QDI + cpKU1. + -2015405564 + 715876348 + CQ"> + "TCFxKr + 1022386234 + 744084086 + -1393893170.7757607 + -1315839449 +
CqMVDy?%
+ z|b + v + b> + -264614902 + |5a[{kkd + + -1175403940 + 3AT/Xdle + 1491285516 + 677201021.1878247 + + 1782193288 + a + 301475287 + -679731723 + D + 1840045569.3863845 + -598026537.3166237 + -946771716.7143898 + 39280517 + 614465087.7473693 + -690289164.2914844 + + 1380875773 + L% + hB + ?k+BR*. + + -941204254.708816 + $g]cn-% + 2 K!b[AM + 804827495.4964151 + 8o + 1780843673.2497535 + rMhE|X(:3 + 1214007196 + -948666217.3109522 + + >km1v + <_ywAjt>192731044 + -1913994356.5676866 + 1119771246.5819716 + S.Zj + 2034584421 + 011a + aMU + -523569350.15442467 + 12287816.680968761 + p#{cZaRT + DBNwr + -664453229 + xdv + jR@R}M + + mNH" + <_H>-1096066951.2440042 + -274152722 + 1113982661.2369614 + -1582873939.207334 + |had-AJ + 00V + 1647327136.0982676 + ycUWS.4t + bb_ + 1176488731 + H8DH + Ok + O*na + -1067691607.5286503 + e + M + d8*Rdg + + ZHCd_U2a + 2089898408.0595765 + <_XE>614457988.4056082 + Ox(G*YJ> + dc=ac + -995471719.9233518 + 1625704208.8778324 + -1542687440 + 489021533.5693426 + fe:rha + C + -893751242 + -1429146432 + a + (ztvrzT + -40960158 + + 4(*Q + 1047841560 + 5K!a 43 + + 88585436.40124273 + 1041139516.040988 + xmVlQp + -826178402 + 1808056972.318603 + mY:*aQ + !%-Y{coqnJ + 196457875 + Fi + @bvNB?R.X + 1872950781.3618746 + 1128207387.6186914 + >bW!t_db + UTi1#+Hswu + d/hUI$eq- + @o + -652351981.7723665 + -828861356.8656125 + 1128326285.873783 + 851191010 + 495428011 + -1654477324.62144 + Mbn + c:B + <_YJmL1Wjh>837879635.0597463 + C4|rBc5c + 6d@jnB + -2001098549 + ZI|Dh + -265703271.48578358 + -567583995.7209473 + ]{=YaC[gpq + 1933666333.017025 + 1075975900.9077 + :a-1edZ + -1918048936.5776062 + 2001833805 + % + ?%KM + -496474688 + 1985172095 + zUZ14n + 1471347124.4876738 + 6:J!b.cJ + 1328315148 + (zwB2s._Ex + b>:v + 1317288245 + 789013460.9537563 + -662759082.4752245 + -88643671.23276329 + 494562544.5273886 + 40497452.87018967 + 1720101626 + C + -2065529383.4908118 + -2101520264 + 1017787395 + -1981137598 + -484342581.3202882 + 96809486.05808067 + ds' + VOGdgJb> + -1537137698.2530046 + WG>uG+2* + 1970694829 + ja. + 2045987077.172608 + + -135661418.3977747 + YxPJ!M+6[ + 37283496 + [m + S7dui4 + 740927833.5952845 + 1049913111 + 1719808986 + 1816905756 + yBk6axO + be{UylF[ + -1012169035.7079787 + 279484996 +
\ No newline at end of file diff --git a/Step.Utils/languages/en.xml b/Step.Utils/languages/en.xml new file mode 100644 index 00000000..e35cbde2 --- /dev/null +++ b/Step.Utils/languages/en.xml @@ -0,0 +1,6 @@ + + + ciao + ugo + test + \ No newline at end of file diff --git a/Step/Controllers/WebApi/ConfigurationController.cs b/Step/Controllers/WebApi/ConfigurationController.cs index 8f892602..104342c0 100644 --- a/Step/Controllers/WebApi/ConfigurationController.cs +++ b/Step/Controllers/WebApi/ConfigurationController.cs @@ -1,7 +1,11 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Claims; using System.Web.Http; using Step.Database.Controllers; using Step.Model.DTOModels; +using static Step.Utils.Constants; namespace Step.Controllers.WebApi { @@ -10,11 +14,17 @@ namespace Step.Controllers.WebApi public class ConfigurationController : ApiController { [Route("functions"), HttpGet] + [WebApiAuthorize(FunctionAccess = "test", Action = ACTIONS.READ)] public IHttpActionResult GetFunctionsConfig() - { + { using (FunctionAccessController functionController = new FunctionAccessController()) { - List functionsList = functionController.GetFunctionAccess(); + var identity = User.Identity as ClaimsIdentity; + + var userRoleLevel = identity.Claims.Where(c => c.Type == ROLE_LEVEL_KEY).SingleOrDefault(); + + + List functionsList = functionController.GetFunctionAccess(Convert.ToInt32(userRoleLevel.Value)); if (functionsList == null) return NotFound(); diff --git a/Step/Controllers/WebApi/LanguageController.cs b/Step/Controllers/WebApi/LanguageController.cs new file mode 100644 index 00000000..671f5b37 --- /dev/null +++ b/Step/Controllers/WebApi/LanguageController.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; +using Step.Model.DTOModels; +using static Step.Utils.Constants; +using static Step.Utils.LanguageController; + +namespace Step.Controllers.WebApi +{ + [RoutePrefix("api/language")] + public class LanguageController : ApiController + { + [WebApiAuthorize(FunctionAccess = "test", Action = ACTIONS.READ)] + [Route("languages"), HttpGet] + public IHttpActionResult GetLanguageList() + { + List availableLanguages = GetLanguageListFromDirectory(); + if (availableLanguages == null) + return NotFound(); + + return Ok(availableLanguages); + } + + [WebApiAuthorize(FunctionAccess = "test", Action = ACTIONS.READ)] + [Route("{language}"), HttpGet()] + public IHttpActionResult GetTranslations(string language) + { + if (!IsValidLanguage(language)) + return BadRequest("Language not exists"); + + if (!LanguageIsAvailable(language)) + return NotFound(); + + Dictionary translations = GetTranslationsFromFile(language); + + if (translations == null) + return InternalServerError(); + + return Ok(translations); + } + } +} diff --git a/Step/Controllers/WebApi/LoginController.cs b/Step/Controllers/WebApi/LoginController.cs index af9fb199..2fc2b89f 100644 --- a/Step/Controllers/WebApi/LoginController.cs +++ b/Step/Controllers/WebApi/LoginController.cs @@ -1,8 +1,8 @@ -using Step.Model.DatabaseModels; using System.Web.Http; using static Step.Utils.Constants; using Step.Database.Controllers; using System; +using Step.Model.DatabaseModels; namespace Step.Controllers.WebApi { @@ -28,23 +28,16 @@ namespace Step.Controllers.WebApi [Route("crash"), HttpGet] public IHttpActionResult Crash() { - UsersController users = new UsersController(); - return Ok(users.Find(13)); + UsersController users = new UsersController(); + return Ok(users.Find(13)); } [Route("register"), HttpPost] public IHttpActionResult CreateUser(UserModel model) { - try - { - UsersController users = new UsersController(); - users.Create(model.Username, model.Password, model.FirstName, model.LastName, model.RoleId); - return Ok(); - } - catch (Exception ex) - { - return InternalServerError(ex); - } + UsersController users = new UsersController(); + users.Create(model.Username, model.Password, model.FirstName, model.LastName, model.RoleId, model.Language); + return Ok(); } } } diff --git a/Step/Listeners/Database/DatabaseTest.cs b/Step/Listeners/Database/DatabaseTest.cs index 17645b3b..c83b2167 100644 --- a/Step/Listeners/Database/DatabaseTest.cs +++ b/Step/Listeners/Database/DatabaseTest.cs @@ -18,7 +18,7 @@ namespace Step.Listeners.Database stopwatch.Start(); using (UsersController user = new UsersController()) { - user.Create("test", "nuova", "nome", "last", 1); + //user.Create("test", "nuova", "nome", "last", 1, "italian"); Console.WriteLine("DB scritto " + taskName + " Thread:" + Thread.CurrentThread.ManagedThreadId + " " + stopwatch.ElapsedMilliseconds); } } diff --git a/Step/Step.csproj b/Step/Step.csproj index fab8933c..95e9c4d7 100644 --- a/Step/Step.csproj +++ b/Step/Step.csproj @@ -164,6 +164,7 @@ + diff --git a/Step/WebApiUnhandledExceptionHandler.cs b/Step/WebApiUnhandledExceptionHandler.cs index 295e6e51..c5c54ec0 100644 --- a/Step/WebApiUnhandledExceptionHandler.cs +++ b/Step/WebApiUnhandledExceptionHandler.cs @@ -1,4 +1,12 @@ -using System.Web.Http.ExceptionHandling; +using System; +using System.Net; +using System.Net.Http; +using System.Net.Http.Formatting; +using System.Threading; +using System.Threading.Tasks; +using System.Web.Http; +using System.Web.Http.ExceptionHandling; +using System.Web.Http.Filters; using static Step.Utils.ExceptionManager; namespace Step @@ -7,7 +15,34 @@ namespace Step { public override void Handle(ExceptionHandlerContext context) { - Manage(context.Exception); + context.Result = new TextPlainErrorResult + { + Request = context.ExceptionContext.Request, + Exception = context.Exception, + HttpStatusCode = HttpStatusCode.InternalServerError + }; + } + + private class TextPlainErrorResult : IHttpActionResult + { + public HttpRequestMessage Request { get; set; } + + public Exception Exception { get; set; } + + public HttpStatusCode HttpStatusCode { get; set; } + + public Task ExecuteAsync(CancellationToken cancellationToken) + { + HttpError error = new HttpError(Exception, true); + HttpResponseMessage response = new HttpResponseMessage() + { + Content = new ObjectContent(error, new JsonMediaTypeFormatter()), + StatusCode = HttpStatusCode, + RequestMessage = Request + }; + + return Task.FromResult(response); + } } } }