public JsonResult AddSendAuth(InputTemeplate inputTemeplate) { var userInfo = DBManager.Instance.GetUser(UserName); if (userInfo != null && inputTemeplate.Type != null && inputTemeplate.Name != null) { var barkKey = typeof(BarkSendTemplate).GetCustomAttributes(typeof(SendMethodKeyAttribute), false).OfType <SendMethodKeyAttribute>().First().Key; if (barkKey == inputTemeplate.Type) { return(Fail(406, "BARK通道勿手动添加,请使用APP添加BARK地址绑定")); } else { var authInfo = inputTemeplate.TemplateToAuth(); var sendAuth = new SendAuthInfo() { UserId = userInfo.Id, SendMethodTemplate = inputTemeplate.Type, AuthData = authInfo, Name = inputTemeplate.Name, Key = Guid.NewGuid().ToString("N").ToUpper(), CreateTime = DateTime.Now, ModifyTime = DateTime.Now, }; DBManager.Instance.DBase.Insert(sendAuth); return(OK(sendAuth)); } } return(Fail()); }
public JsonResult AddSendAuth(InputTemeplate inputTemeplate) { var userInfo = DBManager.Instance.GetUser(UserName); if (userInfo != null && inputTemeplate.Key != null && inputTemeplate.Name != null) { var authInfo = inputTemeplate.TemplateToAuth(); var sendAuth = new SendAuthInfo() { UserId = userInfo.Id, SendMethodTemplate = inputTemeplate.Key, AuthData = authInfo, Name = inputTemeplate.Name, CreateTime = DateTime.Now, ModifyTime = DateTime.Now, }; DBManager.Instance.DBase.Insert(sendAuth); return(OK(sendAuth)); } return(Fail()); }
public JsonResult Register(string?act, string?device_key, string?device_token) { if (string.IsNullOrEmpty(act)) { return(Fail(400, "request bind failed : act is empty")); } if (string.IsNullOrEmpty(device_token)) { return(Fail(400, "request bind failed : device_token is empty")); } var userInfo = DBManager.Instance.DBase.Query <SendUserInfo>().FirstOrDefault(e => e.Token == act); if (userInfo == null) { return(Fail(400, "request bind failed : act is not registered")); } else { BarkAuth barkAuth = null; SendAuthInfo barkSendAuthInfo = null; var barkTemplateAttribute = typeof(BarkSendTemplate).GetCustomAttributes(typeof(SendMethodKeyAttribute), false).OfType <SendMethodKeyAttribute>().First(); if (!string.IsNullOrEmpty(device_key)) { barkSendAuthInfo = DBManager.Instance.DBase.Query <SendAuthInfo>().FirstOrDefault(e => e.Key == device_key); if (barkSendAuthInfo != null) { barkAuth = JsonConvert.DeserializeObject <BarkAuth>(barkSendAuthInfo.AuthData); barkAuth.DeviceToken = device_token; barkSendAuthInfo.AuthData = JsonConvert.SerializeObject(barkAuth); barkSendAuthInfo.ModifyTime = DateTime.Now; DBManager.Instance.DBase.Update(barkSendAuthInfo); } } if (barkSendAuthInfo == null) { if (string.IsNullOrEmpty(device_key)) { device_key = Guid.NewGuid().ToString("N").ToUpper(); } barkAuth = new BarkAuth() { DeviceKey = device_key, DeviceToken = device_token, IsArchive = "1", AutoMaticallyCopy = "1", Sound = "1107" }; barkSendAuthInfo = new SendAuthInfo() { Name = barkTemplateAttribute.Name, SendMethodTemplate = barkTemplateAttribute.Key, Key = device_key, AuthData = JsonConvert.SerializeObject(barkAuth), UserId = userInfo.Id, CreateTime = DateTime.Now, ModifyTime = DateTime.Now, Active = true, }; DBManager.Instance.DBase.Insert(barkSendAuthInfo); } return(Json(new { key = device_key, device_key = device_key, device_token = device_token })); } }