public ActionResult DemoNews(string userName) { string result = ""; try { List <UserNewsUrls> demounls = new List <UserNewsUrls>(); UserNewsUrls unus = new UserNewsUrls { UserNewsTitle = "寶碩投資績效系統", UserNewsUrl = Url.Action("Index", "Default", new { area = "" }), UserNewsCSS = "btn btn-warning" }; demounls.Add(unus); NewsHub.SendMessageToUser(true, userName, "Demo通知", "向您介紹寶碩投資績效系統網站,詳情如連結:", Url.Action("Index", "Default", new { area = "" }), demounls); result = "發送Demo成功"; } catch { result = "發送Demo失敗"; } return(Content(result)); }
public ActionResult UserConfirmUserPower(string needConfirmUserID, int?needConfirmPowerID, int?ConfirmResult, int?userNewsSn) { if (needConfirmUserID != "" && needConfirmPowerID.HasValue && ConfirmResult.HasValue && userNewsSn.HasValue) { ConfirmUserPowerMethod CUPM = new ConfirmUserPowerMethod(); int?returnConfirmEndurpchSn = CUPM.UserConfirmUserPowerM(User.Identity.GetUserName(), needConfirmUserID, needConfirmPowerID.Value, ConfirmResult.Value); //將通知轉為核准/否決並轉到已讀 UserNews un = db.UserNews.Where(n => n.sn == userNewsSn.Value).FirstOrDefault(); IEnumerable <UserNewsUrls> unuie = db.UserNewsUrls.Where(n => n.UserNewsSn == userNewsSn.Value); un.read = true; string strCResult = ConfirmResult.Value == 1 ? "核准" : "否決"; un.msgUrl = ""; //un.msgContent += "<br/><button class='btn btn-info' disabled>" + strCResult + "</button>"; foreach (var unu in unuie) { db.UserNewsUrls.Remove(unu); } UserNewsUrls resultunus = new UserNewsUrls { UserNewsSn = un.sn, UserNewsCSS = "btn btn-info disabled", UserNewsTitle = strCResult, UserNewsUrl = "" }; db.UserNewsUrls.Add(resultunus); db.SaveChanges(); if (returnConfirmEndurpchSn.HasValue) { CUPM.ExecConfirmIsEnd(returnConfirmEndurpchSn.Value); } } //TODO return(RedirectToAction("UserMessage", "Account", new { area = "" })); }
public ActionResult RemoveUserMessage(UserNews model) { string result = ""; //檢查員工 if (cm.checkIsEmployee(User.Identity.GetUserName())) { //檢查權限刪除通知的權限ID為5 if (cm.checkHasPower(User.Identity.GetUserName(), 5)) { //檢查覆核 UserNews userNews = db.UserNews.Find(model.sn); List <UserNewsUrls> userNewsUrls = db.UserNewsUrls.Where(n => n.UserNewsSn == model.sn).ToList(); string userName = db.AspNetUsers.Where(n => n.UserName == userNews.fromUser).Select(n => n.Name).First(); string confirmDescription = ""; confirmDescription += "<div style='border:1px solid black;margin: 2px'>"; confirmDescription += "<p>欲移除通知:</p>"; confirmDescription += "<div style='border:1px solid black;margin: 2px'>"; confirmDescription += "<p>寄送者:" + userName + "<" + userNews.fromUser + ">" + "</p>"; confirmDescription += "<p>標題:" + userNews.msgTitle + "</p>"; confirmDescription += "<p>內容:" + userNews.msgContent + "</p>"; confirmDescription += "<p>發送時間:" + userNews.time + "</p>連結:"; confirmDescription += "<a href='" + userNews.msgUrl + "' class='btn btn-success'>連結</a>"; foreach (var unus in userNewsUrls) { confirmDescription += "<a href='" + unus.UserNewsUrl + "' class='" + unus.UserNewsCSS + "'>" + unus.UserNewsTitle + "</a>"; } confirmDescription += "</div>"; confirmDescription += "</div>"; int? outurpchSn; string ckConfirm = cm.checkNeedConfirm(out outurpchSn, User.Identity.GetUserName(), 5, Url.Action("UserConfirmUserPower", "ConfirmUserPower", new { area = "" }), confirmDescription); if (ckConfirm == "") { //UserNews userNews = db.UserNews.Find(model.sn); if (userNews.UserId == User.Identity.GetUserName()) { IEnumerable <UserNewsUrls> unus = db.UserNewsUrls.Where(n => n.UserNewsSn == userNews.sn); foreach (var unu in unus) { db.UserNewsUrls.Remove(unu); } db.UserNews.Remove(userNews); db.SaveChanges(); } } else { result = ckConfirm; if (outurpchSn.HasValue) { string tableName1 = ""; string primaryColumnName1 = ""; string primaryColumnValue1 = ""; SaveExecConfirmDataModelActionEnum execAction1; string primaryColumnType1 = ""; List <SaveExecConfirmDataModel> cecdm2 = new List <SaveExecConfirmDataModel>(); //UserNews userNews = db.UserNews.Find(model.sn); tableName1 = "UserNews"; primaryColumnName1 = "sn"; primaryColumnValue1 = userNews.sn.ToString(); execAction1 = SaveExecConfirmDataModelActionEnum.Remove; primaryColumnType1 = "int"; List <string> cColumnEmtry = new List <string>(); if (userNews.UserId == User.Identity.GetUserName()) { IEnumerable <UserNewsUrls> unus = db.UserNewsUrls.Where(n => n.UserNewsSn == userNews.sn); foreach (var unu in unus) { string tableName2 = "UserNewsUrls"; string primaryColumnName2 = "UserNewsUrlsID"; string primaryColumnValue2 = unu.UserNewsUrlsID.ToString(); SaveExecConfirmDataModelActionEnum execAction2 = SaveExecConfirmDataModelActionEnum.Remove; string primaryColumnType2 = "int"; SaveExecConfirmDataModel cecdm2t = new SaveExecConfirmDataModel { urpchSn = outurpchSn.Value, tableName = tableName2, primaryColumnName = primaryColumnName2, primaryColumnValue = primaryColumnValue2, primaryColumnType = primaryColumnType2, execAction = execAction2, cColumnName = cColumnEmtry, cColumnValue = cColumnEmtry, cColumnType = cColumnEmtry }; cecdm2.Add(cecdm2t); } } cm.SaveExecConfirmData(cecdm2); SaveExecConfirmDataModel cecdm1 = new SaveExecConfirmDataModel { urpchSn = outurpchSn.Value, tableName = tableName1, primaryColumnName = primaryColumnName1, primaryColumnValue = primaryColumnValue1, primaryColumnType = primaryColumnType1, execAction = execAction1, cColumnName = cColumnEmtry, cColumnValue = cColumnEmtry, cColumnType = cColumnEmtry }; cm.SaveExecConfirmData(cecdm1); } } } else { result = "沒有權限"; } } else { UserNews userNews = db.UserNews.Find(model.sn); if (userNews.UserId == User.Identity.GetUserName()) { bool checkUrls = true; while (checkUrls) { UserNewsUrls unus = db.UserNewsUrls.Where(n => n.UserNewsSn == userNews.sn).FirstOrDefault(); if (unus != null) { db.UserNewsUrls.Remove(unus); } else { checkUrls = false; } } db.UserNews.Remove(userNews); db.SaveChanges(); } } return(Content(result)); }
public async Task <ActionResult> Login(LoginViewModel modal, string returnUrl, string EmailLoginCode, FormCollection form) { IRecaptcha <RecaptchaV2Result> recaptcha = new RecaptchaV2(new RecaptchaV2Data() { Secret = "6LfqzzcUAAAAAHgafe6oixzCCTIZOzvbPbGta8fT" }); RecaptchaV2Result recaptchaResult = recaptcha.Verify(); string dontcheckgrc = form["dontcheckgrc"]; if (!(dontcheckgrc == "on" || recaptchaResult.Success) || !ModelState.IsValid) //if (!ModelState.IsValid) { return(View(modal)); } //Email Login Code //UserTwoFactor utf = db.UserTwoFactor.Where(c=>c.UserId== form.Email).FirstOrDefault(); //if (utf != null&& utf.EmailLogin.HasValue&&utf.EmailLogin.Value) //{ // if (Session["EmailLoginCode"] == null) // return View(form); // if (Session["EmailLoginCode"].ToString() != EmailLoginCode) // return View(form); //} //var result = await SignInManager.PasswordSignInAsync(form.Email, form.Password, form.RememberMe, shouldLockout: false); var result = await SignInManager.PasswordSignInAsync(modal.Email, modal.Password, modal.RememberMe, shouldLockout : true); //Email Confirm // If it was a successful login if (result == SignInStatus.Success || result == SignInStatus.RequiresVerification) { // check that their email address is confirmed: var user = await UserManager.FindByNameAsync(modal.Email); //Email認證 if (!await UserManager.IsEmailConfirmedAsync(user.Id)) { // sign them out! AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); TempData["UserId"] = user.Id; return(RedirectToAction("UnconfirmedEmail", "Account", new { area = "" })); } // reset their login } switch (result) { case SignInStatus.Success: List <UserNewsUrls> testUrls = new List <UserNewsUrls>(); UserNewsUrls testUrl1 = new UserNewsUrls { UserNewsTitle = "管理", UserNewsUrl = Url.Action("Index", "Manage", new { area = "" }), UserNewsCSS = "btn btn-warning" }; UserNewsUrls testUrl2 = new UserNewsUrls { UserNewsTitle = "通知", UserNewsUrl = Url.Action("UserMessage", "Account", new { area = "" }), UserNewsCSS = "btn btn-success" }; UserNewsUrls testUrl3 = new UserNewsUrls { UserNewsTitle = "測試登入", UserNewsUrl = Url.Action("TestSuccessLogin", "Account", new { area = "" }), UserNewsCSS = "btn btn-info" }; testUrls.Add(testUrl1); testUrls.Add(testUrl2); testUrls.Add(testUrl3); //NewsHub.SendMessageToAll("使用者登入", string.Format("{0}已登入", modal.Email),Url.Action("Index","Manage"),testUrls); NewsHub.SendMessageToUser(true, "*****@*****.**", "使用者登入", string.Format("{0}已登入", modal.Email), Url.Action("Index", "Manage", new { area = "" }), testUrls); //NewsHub.SendMessageToUser(modal.Email, "*****@*****.**", "使用者登入", string.Format("{0}已登入", modal.Email), ""); return(RedirectToLocal(returnUrl)); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", "Account", new { area = "", ReturnUrl = returnUrl, RememberMe = modal.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "登入嘗試失試。"); if (db.AspNetUsers.Where(n => n.UserName == modal.Email).ToList().Count() == 1) { LoginErrorEmail.SendEmail(modal.Email, Request.Browser); } return(View(modal)); } }