public string[] GetRoleNamesByLogin(string login) { using (WDB w = new WDB()) { return(w.User.GetRoleNamesByLogin(login)); } }
// GET: api/Cells public IEnumerable <DataModels.Cell> Get() { using (WDB w = new WDB()) { return(w.Cells.GetCellsListByPageId(1)); } }
public IEnumerable <DataModels.Depart> GetDepartList(int id) { using (WDB w = new WDB()) { return(w.Dict.GetDepartList().Where(o => o.OtdId == (id == 0 ? o.OtdId : id)).ToList()); } }
public IEnumerable <DataModels.Otd> GetOtdList(int id) { using (WDB w = new WDB()) { return(w.Dict.GetOtdList(id)); } }
public IEnumerable <DataModels.Access> GetAccessList() { using (WDB w = new WDB()) { return(w.Dict.GetAccessList()); } }
public void Change(int id, [FromBody] dynamic value) { using (WDB w = new WDB()) { w.User.UpdPwd(id, value.ToString()); } }
// GET: api/Goods/5 public DataModels.VGoodsTemplate Get(int id) { using (WDB w = new WDB()) { return(w.Good.GetGoodTmpById(id)); } }
public void DeleteUser(int id) { using (WDB w = new WDB()) { w.User.Delete(id); } }
// GET: api/Login public string Get() { //return new string[] { "value1", "value2" }; using (WDB w = new WDB()) { IPrincipal prcpal = RequestContext.Principal; long userId = w.User.GetUserByLogin(prcpal.Identity.Name); return(w.User.GetNewToken(userId, string.Format("{0}{1}", prcpal.Identity.Name, DateTime.Now.ToString()))); } }
// POST: api/Goods новый public long Post([FromBody] dynamic value) { using (WDB w = new WDB()) { var o = value.ToString(); JavaScriptSerializer jss = new JavaScriptSerializer(); DataModels.VGoodsTemplate good = jss.Deserialize <DataModels.VGoodsTemplate>(o); long GoodTmpId = w.Good.CreateGoodTmp(good); return(GoodTmpId); } }
public bool IsAuthenticated(string login, string password) { using (WDB w = new WDB()) { using (CryptA.Cryptor cryptor = new Cryptor()) { string wp = cryptor.Crypt(password); return(w.User.Autentificate(login, wp)); } } }
public object GetGoodsSizes() { using (WDB w = new WDB()) { var o = new { total = 0, data = w.Dict.GetGoodsSizes() }; return(o); } }
//[Authorize] // GET: api/User public IEnumerable <DataModels.User> Get() { var queryparams = Request.GetQueryNameValuePairs(); var page = Convert.ToInt32(queryparams.Where(w => w.Key == "page").FirstOrDefault().Value); var start = Convert.ToInt32(queryparams.Where(w => w.Key == "start").FirstOrDefault().Value); var limit = Convert.ToInt32(queryparams.Where(w => w.Key == "limit").FirstOrDefault().Value); using (WDB w = new WDB()) { return(w.User.GetUserList(start, limit).ToList()); } }
// PUT: api/Goods/5 обновлення public void Put(int id, [FromBody] dynamic value) { var o = value.ToString(); JavaScriptSerializer jss = new JavaScriptSerializer(); DataModels.VGoodsTemplate good = jss.Deserialize <DataModels.VGoodsTemplate>(o); using (WDB w = new WDB()) { w.Good.SetGoodTmp(good); } }
// POST: api/Cells public void Post([FromBody] object value) { string o = value.ToString(); JavaScriptSerializer jss = new JavaScriptSerializer(); DataModels.Cell cell = jss.Deserialize <DataModels.Cell>(o); using (WDB w = new WDB()) { w.Cells.SetCell(cell); } }
public async void RefreshDataTimer() { WDB wDB = new WDB(); var strHabrXml = await GetData(httpHabr); AParser aParser = new ParserHabr(); var SDocHabr = await Pars(strHabrXml, aParser); wDB.UpdateData(SDocHabr); var strInterfaxXml = await GetData(httpInterfax); AParser aParserInterfax = new ParserInterfax(); var SDocInterfax = await Pars(strInterfaxXml, aParserInterfax); wDB.UpdateData(SDocInterfax); }
// GET: api/Goods public object Get() { var queryparams = Request.GetQueryNameValuePairs(); var page = Convert.ToInt32(queryparams.Where(w => w.Key == "page").FirstOrDefault().Value); var start = Convert.ToInt32(queryparams.Where(w => w.Key == "start").FirstOrDefault().Value); var limit = Convert.ToInt32(queryparams.Where(w => w.Key == "limit").FirstOrDefault().Value); using (WDB w = new WDB()) { var goods = w.Good.GetGoodsTemplateList(start, limit).ToList(); var o = new { total = w.Good.GetGoodsCount(), data = goods }; return(o); } }
// POST: api/User public long Post([FromBody] dynamic value) { var o = value.ToString(); JavaScriptSerializer jss = new JavaScriptSerializer(); DataModels.User user = jss.Deserialize <DataModels.User>(o); using (WDB w = new WDB()) { if (user.UserId != 0) { w.User.SetUser(user); } else { user.UserId = w.User.CreateUser(user); } } return(user.UserId); }
// GET: api/Papers public object Get() { using (WDB wdb = new WDB()) { var queryparams = Request.GetQueryNameValuePairs(); var page = Convert.ToInt32(queryparams.Where(w => w.Key == "page").FirstOrDefault().Value); var start = Convert.ToInt32(queryparams.Where(w => w.Key == "start").FirstOrDefault().Value); var limit = Convert.ToInt32(queryparams.Where(w => w.Key == "limit").FirstOrDefault().Value); var year = Convert.ToInt32(queryparams.Where(w => w.Key == "year").FirstOrDefault().Value); var month = Convert.ToInt32(queryparams.Where(w => w.Key == "month").FirstOrDefault().Value); int qty = 0; var list = wdb.Paper.GetPapersList(year, month, start, limit, out qty).ToList(); return(new { data = list, total = qty }); } }
// PUT: api/User/5 public void Put(int id, [FromBody] dynamic value) { using (WDB w = new WDB()) { var o = value.ToString(); JavaScriptSerializer jss = new JavaScriptSerializer(); UserTmp UserTmp = jss.Deserialize <UserTmp>(o); using (Cryptor cryptor = new Cryptor()) { DataModels.User user = new DataModels.User { UserId = id, Name1 = UserTmp.name1, Name2 = UserTmp.name2, Name3 = UserTmp.name3, AccessId = UserTmp.AccessId, Login = UserTmp.login, OtdId = UserTmp.OtdId //Password = new Guid(cryptor.Crypt(UserTmp.password)) }; w.User.SetUser(user); } } }
public string LoginVerificated(int id) { string returned = "IsNotExists"; var parameters = Request.GetQueryNameValuePairs(); var login = parameters.Where(o => o.Key == "login").FirstOrDefault().Value.ToString(); if (login != null) { using (WDB w = new WDB()) { DataModels.User user = w.User.LoginVerificated(login); if (user != null) { returned = "IsExists"; } } } else { returned = "IsExists"; } return(returned); }
public async Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken) { await Task.Factory.StartNew(() => { HttpRequestMessage request = context.Request; AuthenticationHeaderValue authorization = request.Headers.Authorization; using (WDB w = new WDB()) { w.DbLoger.SetRequest(context.Request.ToString()); w.DbLoger.SetRequest(request.Headers.Authorization.ToString()); } //return true; if (authorization == null) { context.ErrorResult = new AuthenticationFailureResult("Missing authorization header", request); return; } if (authorization.Scheme != "tk") { if (authorization.Scheme != "Basic") { context.ErrorResult = new AuthenticationFailureResult("Authorization scheme not supported", request); return; } } if (authorization.Scheme == "tk") { // По токену шукаємо користувача, перевіряємо його валідність, і формуємо GenericPrincipal string token = GetTokenFromBase64String(authorization.Parameter); if (token != string.Empty) { using (WDB w = new WDB()) { DataModels.VUsers user = w.User.GetUserByToken(token); if (user != null) { var identity = new GenericIdentity(user.Login, "Basic"); context.Principal = new GenericPrincipal(identity, GetRoleNamesByLogin(user.Login)); return; } else { return; } } } } if (authorization.Scheme == "Basic") { Tuple <string, string> userNameAndPasword = ExtractUserNameAndPassword(authorization.Parameter); if (userNameAndPasword == null) { context.ErrorResult = new AuthenticationFailureResult("Invalid credentials", request); } else { string login = userNameAndPasword.Item1; string password = userNameAndPasword.Item2; if (IsAuthenticated(login, password)) { var identity = new GenericIdentity(login, "Basic"); //if you need authorization as well, then fetch the roles and add it here context.Principal = new GenericPrincipal(identity, GetRoleNamesByLogin(login)); } else { context.ErrorResult = new UnauthorizedResult(new AuthenticationHeaderValue[0], context.Request); } } } }); }
private static DBEntry <T> Read <T>(FileStream stream, string dbFile, DBHeader counterpart = null) where T : class { FileName = dbFile; stream.Position = 0; using (var dbReader = new BinaryReader(stream, Encoding.UTF8)) { DBHeader header = ReadHeader(dbReader, counterpart); long pos = dbReader.BaseStream.Position; ValidationChecks <T>(header, out uint build); DBEntry <T> entry = new DBEntry <T>(header, dbFile, build); if (entry.TableStructure == null) { throw new Exception("Definition missing."); } if (header.IsTypeOf <WDBC>() || header.IsTypeOf <WDB2>()) { long stringTableStart = dbReader.BaseStream.Position += header.RecordCount * header.RecordSize; Dictionary <int, string> StringTable = new StringTable().Read(dbReader, stringTableStart); //Get stringtable dbReader.Scrub(pos); ReadIntoTable(ref entry, dbReader, StringTable); //Read data stream.Dispose(); return(entry); } else if (header.IsTypeOf <WDB5>() || header.IsTypeOf <WCH5>() || header.IsTypeOf <WDB6>()) { int CopyTableSize = header.CopyTableSize; //Only WDB5 has a copy table uint CommonDataTableSize = header.CommonDataTableSize; //Only WDB6 has a CommonDataTable //StringTable - only if applicable long copyTablePos = dbReader.BaseStream.Length - CommonDataTableSize - CopyTableSize; long indexTablePos = copyTablePos - (header.HasIndexTable ? header.RecordCount * 4 : 0); long wch7TablePos = indexTablePos - (header.UnknownWCH7 * 4); long stringTableStart = wch7TablePos - header.StringBlockSize; Dictionary <int, string> StringTable = new Dictionary <int, string>(); if (!header.HasOffsetTable) //Stringtable is only present if there isn't an offset map { dbReader.Scrub(stringTableStart); StringTable = new StringTable().Read(dbReader, stringTableStart, stringTableStart + header.StringBlockSize); dbReader.Scrub(pos); } //Read the data using (MemoryStream ms = new MemoryStream(header.ReadData(dbReader, pos, entry.Build))) using (BinaryReader dataReader = new BinaryReader(ms, Encoding.UTF8)) { ReadIntoTable(ref entry, dataReader, StringTable); } //Cleanup header.OffsetLengths = null; stream.Dispose(); return(entry); } else if (header.IsTypeOf <WDB>()) { WDB wdb = (WDB)header; using (MemoryStream ms = new MemoryStream(wdb.ReadData(dbReader))) using (BinaryReader dataReader = new BinaryReader(ms, Encoding.UTF8)) { ReadIntoTable(ref entry, dataReader, new Dictionary <int, string>()); } stream.Dispose(); return(entry); } else if (header.IsTypeOf <HTFX>()) { HTFX htfx = (HTFX)header; using (MemoryStream ms = new MemoryStream(htfx.ReadData(counterpart as WDB6))) using (BinaryReader dataReader = new BinaryReader(ms, Encoding.UTF8)) { ReadIntoTable(ref entry, dataReader, new Dictionary <int, string>()); } stream.Dispose(); return(entry); } else { stream.Dispose(); throw new Exception($"Invalid filetype."); } } }
private static DBHeader ReadHeader(BinaryReader dbReader, DBHeader counterpart = null) { DBHeader header = null; string signature = dbReader.ReadString(4); if (string.IsNullOrWhiteSpace(signature)) { return(null); } if (signature[0] != 'W') { signature = signature.Reverse(); } switch (signature) { case "WDBC": header = new WDBC(); break; case "WDB2": case "WCH2": header = new WDB2(); break; case "WDB5": header = new WDB5(); break; case "WDB6": header = new WDB6(); break; case "WCH5": header = new WCH5(counterpart); break; case "WCH7": header = new WCH7(counterpart); break; case "WCH8": header = new WCH8(counterpart); break; case "WMOB": case "WGOB": case "WQST": case "WIDB": case "WNDB": case "WITX": case "WNPC": case "WPTX": case "WRDN": header = new WDB(); break; case "HTFX": header = new HTFX(); break; } header?.ReadHeader(ref dbReader, signature); return(header); }