public ActionResult Index(ChangeProfileModel adObj1) { Administrator adObj = adObj1.administrator; if (ModelState.IsValid) { string adminID = ""; try { adminID = ((Administrator)Session["AdministratorRegistery"]).id_Admin; } catch (Exception exception) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.sessionAuth, "IN Controller : {AdministratorGeneralController}\nMethod : {public ActionResult Index(ChangeProfileModel adObj1)}") { EXOBJ = exception }; } //If Session Doesent work try { HttpCookie cookie = HttpContext.Request.Cookies.Get(ProjectProperies.AuthCoockieCode()); adminID = CoockieController.SayMyName(cookie.Value).id_Admin; } catch (Exception EX) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.coockieAuth, "IN Controller : {AdministratorGeneralController}\nMethod : {public ActionResult Index(ChangeProfileModel adObj1)}") { EXOBJ = EX }; } if (string.IsNullOrEmpty(adminID)) { adminID = "NO-ID"; } PDBC db = new PDBC(); List <ExcParameters> dbparams = new List <ExcParameters>(); adObj.ad_avatarprofile = "/AdminDesignResource/app/media/img/users/100_12.jpg"; ExcParameters param = new ExcParameters() { _VALUE = adminID, _KEY = "@id_Admin" }; dbparams.Add(param); param = new ExcParameters() { _VALUE = adObj.ad_firstname, _KEY = "@ad_firstname" }; dbparams.Add(param); param = new ExcParameters() { _VALUE = adObj.ad_lastname, _KEY = "@ad_lastname" }; dbparams.Add(param); param = new ExcParameters() { _VALUE = adObj.ad_avatarprofile, _KEY = "@ad_avatarprofile" }; dbparams.Add(param); param = new ExcParameters() { _VALUE = adObj.ad_email, _KEY = "@ad_email" }; dbparams.Add(param); param = new ExcParameters() { _VALUE = adObj.ad_phone, _KEY = "@ad_phone" }; dbparams.Add(param); param = new ExcParameters() { _VALUE = adObj.ad_mobile, _KEY = "@ad_mobile" }; dbparams.Add(param); param = new ExcParameters() { _VALUE = adObj.ad_NickName, _KEY = "@ad_NickName" }; dbparams.Add(param); db.Connect(); string result = db.Script( "UPDATE [tbl_ADMIN_main] SET [ad_firstname] = @ad_firstname ,[ad_lastname] = @ad_lastname ,[ad_avatarprofile] = @ad_avatarprofile ,[ad_email] = @ad_email ,[ad_phone] = @ad_phone ,[ad_mobile] = @ad_mobile ,[ad_NickName] = @ad_NickName WHERE id_Admin=@id_Admin", dbparams); db.DC(); if (result == "1") { try { var sessionChanger = (Administrator)Session["AdministratorRegistery"]; sessionChanger.ad_avatarprofile = adObj.ad_avatarprofile; sessionChanger.ad_NickName = adObj.ad_NickName; sessionChanger.ad_firstname = adObj.ad_firstname; sessionChanger.ad_lastname = adObj.ad_lastname; sessionChanger.ad_email = adObj.ad_email; sessionChanger.ad_phone = adObj.ad_phone; sessionChanger.ad_mobile = adObj.ad_mobile; Session["AdministratorRegistery"] = sessionChanger; } catch (Exception EX) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.sessionAuth, "IN Controller : {AdministratorGeneralController}\nMethod : {public ActionResult Index(ChangeProfileModel adObj LINE 126)}") { EXOBJ = EX }; } try { HttpCookie cookie = HttpContext.Request.Cookies.Get(ProjectProperies.AuthCoockieCode()); var sessionChanger = CoockieController.SayMyName(cookie.Value); sessionChanger.ad_avatarprofile = adObj.ad_avatarprofile; sessionChanger.ad_NickName = adObj.ad_NickName; sessionChanger.ad_firstname = adObj.ad_firstname; sessionChanger.ad_lastname = adObj.ad_lastname; sessionChanger.ad_email = adObj.ad_email; sessionChanger.ad_phone = adObj.ad_phone; sessionChanger.ad_mobile = adObj.ad_mobile; var userCookieIDV = new HttpCookie(ProjectProperies.AuthCoockieCode()); userCookieIDV.Value = CoockieController.SetCoockie(sessionChanger);; userCookieIDV.Expires = DateTime.Now.AddYears(5); Response.SetCookie(userCookieIDV); } catch (Exception EX) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.coockieAuth, "IN Controller : {AdministratorGeneralController}\nMethod : {public ActionResult Index(ChangeProfileModel adObj LINE 126)}") { EXOBJ = EX }; } var ModelSender = new ErrorReporterModel { ErrorID = "SX101", Errormessage = "اطلاعات کاربری با موفقیت ویرایش شد!", Errortype = "Success" }; return(Json(ModelSender)); } else { PPBugReporter rep = new PPBugReporter(BugTypeFrom.SQL, result); var ModelSender = new ErrorReporterModel { ErrorID = "EX103", Errormessage = $"عدم توانایی در ویرایش اطلاعات با پشتیبانی تماس حاصل فرمایید! کد پیگیری برای شما :{rep.CodeGenerated}", Errortype = "Error" }; ViewBag.EXLogin = ModelSender; return(Json(ModelSender)); } } else { List <ModelErrorReporter> allErrors = new List <ModelErrorReporter>(); //foreach (ModelError error in ModelState.Values.) var AllValues = ModelState.Values.ToList(); var AllKeys = ModelState.Keys.ToList(); int errorsCount = AllValues.Count; for (int i = 0; i < errorsCount; i++) { if (AllValues[i].Errors.Count > 0) { ModelErrorReporter er = new ModelErrorReporter() { IdOfProperty = AllKeys[i].Replace("administrator.", "administrator_"), ErrorMessage = AllValues[i].Errors[0].ErrorMessage }; allErrors.Add(er); } } var ModelSender = new ErrorReporterModel { ErrorID = "EX104", Errormessage = $"عدم رعایت استاندارد ها!", Errortype = "ErrorWithList", AllErrors = allErrors }; return(Json(ModelSender)); } }
public ActionResult LoginAuth(LoginAuthForm adObj) { if (ModelState.IsValid) { EncDec dn = new EncDec(); adObj.Password = dn.HMACMD5Generator(adObj.Password); PDBC db = new PDBC(); List <ExcParameters> parasms = new List <ExcParameters>(); ExcParameters parameters = new ExcParameters() { _KEY = "@username", _VALUE = adObj.Username }; parasms.Add(parameters); parameters = new ExcParameters() { _KEY = "@password", _VALUE = adObj.Password }; parasms.Add(parameters); db.Connect(); using (DataTable dt = db.Select("SELECT * FROM [tbl_ADMIN_main] WHERE ad_username LIKE @username AND ad_password LIKE @password", parasms)) { db.DC(); int dtrowcount = dt.Rows.Count; if (dtrowcount > 0) { if (dt.Rows[0]["ad_isActive"].ToString() == "1") { Administrator AdminSession = new Administrator() { id_Admin = dt.Rows[0]["id_Admin"].ToString() , ad_typeID = dt.Rows[0]["ad_typeID"].ToString() , ad_firstname = dt.Rows[0]["ad_firstname"].ToString() , ad_lastname = dt.Rows[0]["ad_lastname"].ToString() , ad_avatarprofile = dt.Rows[0]["ad_avatarprofile"].ToString() , ad_email = dt.Rows[0]["ad_email"].ToString() , ad_phone = dt.Rows[0]["ad_phone"].ToString() , ad_mobile = dt.Rows[0]["ad_mobile"].ToString() , ad_has2stepSecurity = dt.Rows[0]["ad_has2stepSecurity"].ToString() , ad_isActive = dt.Rows[0]["ad_isActive"].ToString() , ad_isDelete = dt.Rows[0]["ad_isDelete"].ToString() , ad_lastseen = dt.Rows[0]["ad_lastseen"].ToString() , ad_lastlogin = dt.Rows[0]["ad_lastlogin"].ToString() , ad_loginIP = dt.Rows[0]["ad_loginIP"].ToString() , ad_regdate = dt.Rows[0]["ad_regdate"].ToString() , ad_personalColorHexa = dt.Rows[0]["ad_personalColorHexa"].ToString() , AdminModeID = dt.Rows[0]["AdminModeID"].ToString() , ad_NickName = dt.Rows[0]["ad_NickName"].ToString(), Username = adObj.Username }; try { Session["AdministratorRegistery"] = AdminSession; try { var userCookieIDV = new HttpCookie(ProjectProperies.AuthCoockieCode()); userCookieIDV.Value = CoockieController.SetCoockie(AdminSession);; userCookieIDV.Expires = DateTime.Now.AddYears(5); Response.SetCookie(userCookieIDV); } catch (Exception coockieEXception) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.coockieAuth) { EXOBJ = coockieEXception }; var ModelSender = new ErrorReporterModel { ErrorID = "EX103", Errormessage = $"عدم توانایی در ایجاد نشست فعال برای شما با پشتیبانی تماس حاصل فرمایید کد ارور شما {rep.CodeGenerated}", Errortype = "Error" }; ViewBag.EXLogin = ModelSender; return(View("Index")); } if (string.IsNullOrEmpty(adObj.urlRedirection)) { return(RedirectToAction("Logs", "AdminLoginAuth")); } else { string[] GotToPage = adObj.urlRedirection.Split('-'); string actionname = ""; string controllername = ""; for (int i = 0; i < 2; i++) { if (GotToPage[i].Contains("A_")) { actionname = GotToPage[i].Replace("A_", ""); } else { controllername = GotToPage[i]; } } return(RedirectToAction(actionname, controllername)); } } catch (Exception SessionException) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.sessionAuth) { EXOBJ = SessionException }; var ModelSender = new ErrorReporterModel { ErrorID = "EX103", Errormessage = $"عدم توانایی در ایجاد نشست فعال برای شما با پشتیبانی تماس حاصل فرمایید کد ارور شما {rep.CodeGenerated}", Errortype = "Error" }; ViewBag.EXLogin = ModelSender; return(View("Index")); } } else { var ModelSender = new ErrorReporterModel { ErrorID = "EX101", Errormessage = "کاربر پیدا شده در وضعیت غیر فعال میباشد و اجازه دسترسی به پنل را نخواهد داشت", Errortype = "Error" }; ViewBag.EXLogin = ModelSender; return(View("Index")); } } else { var ModelSender = new ErrorReporterModel { ErrorID = "EX102", Errormessage = "کاربری با این مشخصات یافت نشد!", Errortype = "Error" }; ViewBag.EXLogin = ModelSender; return(View("Index")); } } db.DC(); return(View("Index")); } else { var ModelSender = new ErrorReporterModel { ErrorID = "EX100", Errormessage = "درخواست ارسال شده مطابق با ساختار امنیتی نمیباشد", Errortype = "Error" }; ViewBag.EXLogin = ModelSender; return(View("Index")); } }
public ActionResult ChangeAuthInformations(ChangeProfileModel informations) { changeAuthInformation information = informations.authInformation; if (ModelState.IsValid) { string adminID = ""; try { adminID = ((Administrator)Session["AdministratorRegistery"]).id_Admin; } catch (Exception exception) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.sessionAuth, "IN Controller : {AdministratorGeneralController}\nMethod : {public ActionResult Index(ChangeProfileModel adObj1)}") { EXOBJ = exception }; } //If Session Doesent work try { HttpCookie cookie = HttpContext.Request.Cookies.Get(ProjectProperies.AuthCoockieCode()); adminID = CoockieController.SayMyName(cookie.Value).id_Admin; } catch (Exception EX) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.coockieAuth, "IN Controller : {AdministratorGeneralController}\nMethod : {public ActionResult Index(ChangeProfileModel adObj1)}") { EXOBJ = EX }; } if (string.IsNullOrEmpty(adminID)) { adminID = "NO-ID"; } PDBC db = new PDBC(); List <ExcParameters> dbparams = new List <ExcParameters>(); ExcParameters param = new ExcParameters() { _VALUE = adminID, _KEY = "@id_Admin" }; dbparams.Add(param); db.Connect(); using (DataTable dt = db.Select("SELECT [ad_password] FROM [tbl_ADMIN_main] WHERE [id_Admin] = @id_Admin", dbparams)) { db.DC(); if (dt.Rows.Count > 0) { EncDec en = new EncDec(); string md5GeneratedPW = en.HMACMD5Generator(information.OLDpassword); if (md5GeneratedPW == dt.Rows[0]["ad_password"].ToString()) { if (string.IsNullOrEmpty(information.Newpassword1)) { param = new ExcParameters() { _VALUE = information.Username, _KEY = "@ad_username" }; dbparams.Add(param); db.Connect(); string result = db.Script("UPDATE [tbl_ADMIN_main] SET [ad_username] = @ad_username WHERE [id_Admin] = @id_Admin", dbparams); db.DC(); if (result == "1") { try { var sessionChanger = (Administrator)Session["AdministratorRegistery"]; sessionChanger.Username = information.Username; Session["AdministratorRegistery"] = sessionChanger; } catch (Exception EX) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.sessionAuth, "IN Controller : {AdministratorGeneralController}\nMethod : {public ActionResult Index(ChangeProfileModel adObj LINE 298)}") { EXOBJ = EX }; } try { HttpCookie cookie = HttpContext.Request.Cookies.Get(ProjectProperies.AuthCoockieCode()); var sessionChanger = CoockieController.SayMyName(cookie.Value); sessionChanger.Username = information.Username; var userCookieIDV = new HttpCookie(ProjectProperies.AuthCoockieCode()); userCookieIDV.Value = CoockieController.SetCoockie(sessionChanger);; userCookieIDV.Expires = DateTime.Now.AddYears(5); Response.SetCookie(userCookieIDV); } catch (Exception EX) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.coockieAuth, "IN Controller : {AdministratorGeneralController}\nMethod : {public ActionResult Index(ChangeProfileModel adObj LINE 315)}") { EXOBJ = EX }; } var ModelSender = new ErrorReporterModel { ErrorID = "SX102", Errormessage = "نام کاربری با موفقیت ویرایش شد!", Errortype = "Success" }; return(Json(ModelSender)); } else { PPBugReporter rep = new PPBugReporter(BugTypeFrom.SQL, result); var ModelSender = new ErrorReporterModel { ErrorID = "EX108", Errormessage = "عدم توانایی در ایجاد نشست فعال برای شما با پشتیبانی تماس حاصل فرمایید", Errortype = "Error" }; return(Json(ModelSender)); } } else { if (information.Newpassword1 == information.Newpassword2) { param = new ExcParameters() { _VALUE = information.Username, _KEY = "@ad_username" }; dbparams.Add(param); param = new ExcParameters() { _VALUE = md5GeneratedPW, _KEY = "@ad_password" }; dbparams.Add(param); db.Connect(); string result = db.Script("UPDATE [tbl_ADMIN_main] SET [ad_password] = @ad_password,[ad_username] = @ad_username WHERE [id_Admin] = @id_Admin", dbparams); db.DC(); if (result == "1") { try { var sessionChanger = (Administrator)Session["AdministratorRegistery"]; sessionChanger.Username = information.Username; Session["AdministratorRegistery"] = sessionChanger; } catch (Exception EX) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.sessionAuth, "IN Controller : {AdministratorGeneralController}\nMethod : {public ActionResult Index(ChangeProfileModel adObj LINE 126)}") { EXOBJ = EX }; } try { HttpCookie cookie = HttpContext.Request.Cookies.Get(ProjectProperies.AuthCoockieCode()); var sessionChanger = CoockieController.SayMyName(cookie.Value); sessionChanger.Username = information.Username; var userCookieIDV = new HttpCookie(ProjectProperies.AuthCoockieCode()); userCookieIDV.Value = CoockieController.SetCoockie(sessionChanger);; userCookieIDV.Expires = DateTime.Now.AddYears(5); Response.SetCookie(userCookieIDV); } catch (Exception EX) { PPBugReporter rep = new PPBugReporter(BugTypeFrom.coockieAuth, "IN Controller : {AdministratorGeneralController}\nMethod : {public ActionResult Index(ChangeProfileModel adObj LINE 126)}") { EXOBJ = EX }; } var ModelSender = new ErrorReporterModel { ErrorID = "SX103", Errormessage = "اطلاعات ورود با موفقیت ویرایش شد!", Errortype = "Success" }; return(Json(ModelSender)); } else { PPBugReporter rep = new PPBugReporter(BugTypeFrom.SQL, result); var ModelSender = new ErrorReporterModel { ErrorID = "EX110", Errormessage = $"عدم توانایی در ویرایش اطلاعات با پشتیبانی تماس حاصل فرمایید! کد پیگیری برای شما :{rep.CodeGenerated}", Errortype = "Error" }; return(Json(ModelSender)); } } else { List <ModelErrorReporter> allErrors = new List <ModelErrorReporter>(); ModelErrorReporter er = new ModelErrorReporter() { IdOfProperty = "authInformation_Newpassword1", ErrorMessage = "عدم یکسانی کلمه های عبور" }; allErrors.Add(er); er = new ModelErrorReporter() { IdOfProperty = "authInformation_Newpassword2", ErrorMessage = "عدم یکسانی کلمه های عبور" }; allErrors.Add(er); var ModelSender = new ErrorReporterModel { ErrorID = "EX109", Errormessage = "عدم یکسانی کلمه های عبور", Errortype = "ErrorWithList", AllErrors = allErrors }; return(Json(ModelSender)); } } } else { List <ModelErrorReporter> allErrors = new List <ModelErrorReporter>(); ModelErrorReporter er = new ModelErrorReporter() { IdOfProperty = "authInformation_OLDpassword", ErrorMessage = "کلمه عبور بدرستی وارد نشده است" }; allErrors.Add(er); var ModelSender = new ErrorReporterModel { ErrorID = "EX105", Errormessage = $"کلمه عبور حال شما کلید شما برای ایجاد تغییرات میباشد", Errortype = "ErrorWithList", AllErrors = allErrors }; return(Json(ModelSender)); } } else { var ModelSender = new ErrorReporterModel { ErrorID = "EX107", Errormessage = $"کاربر یافت نشد با پشتیبانی تماس بفرمایید", Errortype = "Error", }; return(Json(ModelSender)); } } } else { List <ModelErrorReporter> allErrors = new List <ModelErrorReporter>(); var AllValues = ModelState.Values.ToList(); var AllKeys = ModelState.Keys.ToList(); int errorsCount = AllValues.Count; for (int i = 0; i < errorsCount; i++) { if (AllValues[i].Errors.Count > 0) { ModelErrorReporter er = new ModelErrorReporter() { IdOfProperty = AllKeys[i].Replace("authInformation.", "authInformation_"), ErrorMessage = AllValues[i].Errors[0].ErrorMessage }; allErrors.Add(er); } } var ModelSender = new ErrorReporterModel { ErrorID = "EX106", Errormessage = $"عدم رعایت استاندارد ها!", Errortype = "ErrorWithList", AllErrors = allErrors }; return(Json(ModelSender)); } }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { if (Session["AdministratorRegistery"] != null) { ProfileProperty propfileinfo = new ProfileProperty() { avatarImageSrc = ((Administrator)Session["AdministratorRegistery"]).ad_avatarprofile, name = ((Administrator)Session["AdministratorRegistery"]).ad_NickName, fullname = ((Administrator)Session["AdministratorRegistery"]).ad_firstname + " " + ((Administrator)Session["AdministratorRegistery"]).ad_lastname, ipAdmin = Request.UserHostAddress, Firstname = ((Administrator)Session["AdministratorRegistery"]).ad_firstname, Lastname = ((Administrator)Session["AdministratorRegistery"]).ad_lastname, email = ((Administrator)Session["AdministratorRegistery"]).ad_email, phone = ((Administrator)Session["AdministratorRegistery"]).ad_phone, mobile = ((Administrator)Session["AdministratorRegistery"]).ad_mobile, Username = ((Administrator)Session["AdministratorRegistery"]).Username }; ViewBag.ProfileInfo = propfileinfo; //End of Admin Profile //start PAGE - TITLE string actionName = filterContext.RouteData.Values["action"].ToString(); string controllerName = filterContext.RouteData.Values["controller"].ToString(); ViewBag.pageTitle = TitleFounder.GetAdminPanelTitle(controllerName, actionName); //END of PAGE - TITLE base.OnActionExecuting(filterContext); } else if (HttpContext.Request.Cookies.Get(ProjectProperies.AuthCoockieCode()) != null) { var coockie = HttpContext.Request.Cookies.Get(ProjectProperies.AuthCoockieCode()); Administrator administratorobj = CoockieController.SayMyName(coockie.Value); if ((DateTime.Now - administratorobj.SayMyTime).TotalHours > 6) { string actionName1 = filterContext.RouteData.Values["action"].ToString(); string controllerName1 = filterContext.RouteData.Values["controller"].ToString(); string urlRedirection = controllerName1 + "-A_" + actionName1; if (!urlRedirection.Contains("AdminLoginAuth-A_index")) { TempData["urlRedirection"] = urlRedirection; filterContext.Result = RedirectToAction("index", "AdminLoginAuth", new { @urlRedirection = urlRedirection }); } else { filterContext.Result = RedirectToAction("index", "AdminLoginAuth"); } } ProfileProperty propfileinfo = new ProfileProperty() { avatarImageSrc = administratorobj.ad_avatarprofile, name = administratorobj.ad_NickName, fullname = administratorobj.ad_firstname + " " + administratorobj.ad_lastname, ipAdmin = Request.UserHostAddress, Firstname = administratorobj.ad_firstname, Lastname = administratorobj.ad_lastname, email = administratorobj.ad_email, phone = administratorobj.ad_phone, mobile = administratorobj.ad_mobile, Username = administratorobj.Username }; administratorobj.SayMyTime = DateTime.Now; var userCookieIDV = new HttpCookie(ProjectProperies.AuthCoockieCode()); userCookieIDV.Value = CoockieController.SetCoockie(administratorobj);; userCookieIDV.Expires = DateTime.Now.AddYears(5); Response.SetCookie(userCookieIDV); ViewBag.ProfileInfo = propfileinfo; //End of Admin Profile //start PAGE - TITLE string actionName = filterContext.RouteData.Values["action"].ToString(); string controllerName = filterContext.RouteData.Values["controller"].ToString(); ViewBag.pageTitle = TitleFounder.GetAdminPanelTitle(controllerName, actionName); //END of PAGE - TITLE base.OnActionExecuting(filterContext); } else { string actionName = filterContext.RouteData.Values["action"].ToString(); string controllerName = filterContext.RouteData.Values["controller"].ToString(); string urlRedirection = controllerName + "-A_" + actionName; if (!urlRedirection.Contains("AdminLoginAuth-A_index")) { TempData["urlRedirection"] = urlRedirection; filterContext.Result = RedirectToAction("index", "AdminLoginAuth", new { @urlRedirection = urlRedirection }); } else { filterContext.Result = RedirectToAction("index", "AdminLoginAuth"); } } }