public async Task <ActionResult> CreateKey(AccessKeyModel model) { if (!ModelState.IsValid) { return(View(model)); } Repository r = new Repository(); try { if (!await r.TryCreateNewAccessKeyAsync(model)) { ModelState.AddModelError("Key", "Provided key is not valid!"); return(View(model)); } } catch (Exception ex) { Savonia.Web.ErrorReporter.ErrorReporterModule.HandleException(ex, System.Web.HttpContext.Current.Request); ModelState.AddModelError("Key", "Unknown error occurred!"); return(View(model)); } return(RedirectToAction("Details", new { id = model.ProviderID })); }
public async Task <ActionResult> EditAccessKey(AccessKeyModel model) { if (model.KeyId.HasValue) { Helpers.ManageHelper mh = new Helpers.ManageHelper(); model.Key = mh.GetAccessKeyFromSession(this.HttpContext, model.KeyId.Value, false); if (model.Key != null) { ModelState.Remove("key"); ModelState.Add("Key", new ModelState()); ModelState.SetModelValue("Key", new ValueProviderResult(model.Key, model.Key, System.Globalization.CultureInfo.CurrentCulture)); } } if (!ModelState.IsValid) { return(View(model)); } Repository r = new Repository(); try { await r.UpdateAccessKeyAsync(model); } catch (Exception ex) { Savonia.Web.ErrorReporter.ErrorReporterModule.HandleException(ex, System.Web.HttpContext.Current.Request); ModelState.AddModelError("Key", "Unknown error occurred!"); model.Key = "*****"; return(View(model)); } return(RedirectToAction("Details", new { id = model.ProviderID })); }
public async Task <ActionResult> EditAccessKey(int providerID, short?id) { Repository r = new Repository(); Helpers.ManageHelper mh = new Helpers.ManageHelper(); AccessKeyModel model = new AccessKeyModel(); try { var key = mh.GetAccessKeyFromSession(this.HttpContext, id.Value); if (key == null) { return(RedirectToAction("Index")); } model = await r.GetAccessKeyAsync(key); if (model.ProviderID != providerID) { return(RedirectToAction("Details", new { id = providerID })); } } catch (Exception ex) { Savonia.Web.ErrorReporter.ErrorReporterModule.HandleException(ex, System.Web.HttpContext.Current.Request); return(RedirectToAction("Index")); } model.Key = "*****"; model.KeyId = id; return(View(model)); }
public ActionResult CreateKey(int providerID) { AccessKeyModel model = new AccessKeyModel() { ProviderID = providerID, ValidFrom = DateTime.Now, Key = this.GetKey() }; return(View(model)); }
public static AccessKey ToAccessKey(this AccessKeyModel model) { return(new AccessKey() { AccessControl = (int)model.AccessControl, KeyEncrypt = model.Key.Encrypt(model.ProviderID.ToString()), Key = model.Key.Hash(model.ProviderID.ToString()), ValidFrom = model.ValidFrom, ValidTo = model.ValidTo, ProviderID = model.ProviderID, KeyId = model.KeyId, Info = model.Info }); }
public async Task <ActionResult> ConfirmDeleteKey(AccessKeyModel model) { Repository r = new Repository(); try { await r.DeleteAccessKeyAsync(model); } catch (Exception ex) { Savonia.Web.ErrorReporter.ErrorReporterModule.HandleException(ex, System.Web.HttpContext.Current.Request); return(View(model)); } return(RedirectToAction("Details", new { id = model.ProviderID })); }
public static Query ToQuery(this MeasurementQueryModel model, AccessKeyModel access) { return(new Query() { Key = access.Key.Hash(access.ProviderID.ToString()), ProviderID = access.ProviderID, Object = model.Obj, Tag = model.Tag, Take = model.Take, From = model.From, To = model.To, Sensors = model.Sensors, Name = model.Name, ID = model.ID }); }
public static AccessKeyModel ToAccessKeyModel(this AccessKey key, bool decryptKey = false) { AccessKeyModel akm = new AccessKeyModel() { AccessControl = (AccessControl)key.AccessControl, ProviderID = key.ProviderID, ValidFrom = key.ValidFrom, ValidTo = key.ValidTo, KeyId = key.KeyId, Info = key.Info }; if (decryptKey) { akm.Key = key.KeyEncrypt.Decrypt(key.ProviderID.ToString()); } return(akm); }
public DataAccess(AccessKeyModel key) { this.key = key; }