public ActionResult User_Edit(Model_UserEdit model) { Tbl_Login _Login = db.Tbl_Login.Where(a => a.Login_ID == model.ID).SingleOrDefault(); Tbl_User _User = _Login.Tbl_User; _Login.Login_Email = model.Email; _Login.Login_Mobile = model.Mobile; _User.User_GenderCodeID = Rep_CodeGroup.Get_CodeIDWithGUID(Guid.Parse(model.Gender)); _User.User_Name = model.Name; _User.User_Family = model.Family; db.Entry(_Login).State = EntityState.Modified; db.Entry(_User).State = EntityState.Modified; if (Convert.ToBoolean(db.SaveChanges() > 0)) { TempData["TosterState"] = "success"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "عملیات با موفقیت انجام شد"; return(RedirectToAction("index")); } else { TempData["TosterState"] = "error"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "عملیات با موفقیت انجام نشد"; return(RedirectToAction("index")); } }
public static void DeleteUsers(int loginid) { using (AdminDataContext db = new AdminDataContext()) { Tbl_Login obj = db.Tbl_Logins.Where(c => c.loginID == loginid).SingleOrDefault(); db.Tbl_Logins.DeleteOnSubmit(obj); db.SubmitChanges(); } }
public ActionResult Register(RegisterModel model) { //if (Password != MatchPassword) //{ // return View(); //} if (!ModelState.IsValid) { ViewBag.State = "Error"; return(View("Register", model)); } Tbl_User ur = new Tbl_User(); ur.User_Name = model.Name; ur.User_Family = model.Family; ur.User_Email = model.Email; ur.User_Mobile = model.Mobile; ur.User_Date = DateTime.Now; ur.User_BranchID = model.Branch; ur.User_SABAlloow = false; db.Tbl_User.Add(ur); Tbl_Login login = new Tbl_Login(); string s = Session["User"].ToString(); login = db.Tbl_Login.Where(a => a.Login_UserName == s).SingleOrDefault(); login.Login_UserID = ur.User_ID; var Salt = Guid.NewGuid().ToString("N"); var SaltPassword = model.Password + Salt; var SaltPasswordBytes = Encoding.UTF8.GetBytes(SaltPassword); var SaltPasswordHush = Convert.ToBase64String(SHA512.Create().ComputeHash(SaltPasswordBytes)); login.Login_PasswordHush = SaltPasswordHush; login.Login_PasswordSalt = Salt; login.Login_RegisterActive = false; db.Entry(login).State = System.Data.Entity.EntityState.Modified; if (Convert.ToBoolean(db.SaveChanges() > 0)) { Session["Register"] = "Deactive"; return(RedirectToAction("Login", "Account")); } else { } return(View()); }
public ActionResult Slider_Add(Model_SliderAdd model) { if (model.Document != null && model.Document.ContentLength > 0) { Tbl_Document _Document = new Tbl_Document(); Tbl_Slider _Slider = new Tbl_Slider(); Tbl_Login _Login = db.Tbl_Login.Where(a => a.Login_Email == User.Identity.Name || a.Login_Mobile == User.Identity.Name).FirstOrDefault(); _Slider.Slider_Tital = model.Tital; _Slider.Slider_Guid = Guid.NewGuid(); _Slider.Slider_Subject = model.Subject; _Slider.Slider_Link = model.Link; _Slider.Slider_Description = model.Description; _Slider.Slider_IsActive = model.IsActive; _Slider.Slider_CreateDate = DateTime.Now; _Slider.Tbl_Login = _Login; _Document.Document_FileName = model.Document.FileName; _Document.Document_FolderName = "Slider"; _Document.Document_TypeCodeID = 5; _Document.Tbl_Login = _Login; _Document.Document_CreateDate = DateTime.Now; _Document.Document_Guid = Guid.NewGuid(); _Document.Document_Path = Guid.NewGuid().ToString(); model.Document.SaveAs(Path.Combine(Server.MapPath("~/App_Data/Slider/"), _Document.Document_Path)); db.Tbl_Document.Add(_Document); _Slider.Tbl_Document = _Document; db.Tbl_Slider.Add(_Slider); if (Convert.ToBoolean(db.SaveChanges() > 0)) { TempData["TosterState"] = "success"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "عملیات با موفقیت انجام شد"; return(RedirectToAction("Slider_List")); } else { TempData["TosterState"] = "error"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "عملیات با موفقیت انجام نشد"; return(RedirectToAction("Slider_List")); } } return(View()); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int myloginID = Convert.ToInt32(Session["UID"].ToString()); using (AdminDataContext db = new AdminDataContext()) { Tbl_Login obj = db.Tbl_Logins.Where(c => c.loginID == myloginID).SingleOrDefault(); txtFirst.Text = obj.FirstName.ToString(); txtLast.Text = obj.LastName.ToString(); txtEmail.Text = obj.Email.ToString(); } } }
public static string Getemail(string uid) { using (AdminDataContext adb = new AdminDataContext()) { Tbl_Login obj = adb.Tbl_Logins.Where(c => c.loginID == Convert.ToInt32(uid)).SingleOrDefault(); if (obj != null) { if (obj.Email != "") { return(obj.Email); } } return(""); } }
public ActionResult User_Add(Model_UserAdd model) { if (ModelState.IsValid) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Tbl_Login _Login = new Tbl_Login { Login_Guid = Guid.NewGuid(), Login_Email = model.Email, Login_Name = model.Name, Login_Family = model.Family, Login_Mobile = model.Mobile, Login_RoleID = model.Role, Login_CreateDate = DateTime.Now, Login_Modify = DateTime.Now }; var Salt = Guid.NewGuid().ToString("N"); var SaltPassword = model.Password + Salt; var SaltPasswordBytes = Encoding.UTF8.GetBytes(SaltPassword); var SaltPasswordHush = Convert.ToBase64String(SHA512.Create().ComputeHash(SaltPasswordBytes)); _Login.Login_PasswordHash = SaltPasswordHush; _Login.Login_PasswordSalt = Salt; db.Tbl_Login.Add(_Login); if (Convert.ToBoolean(db.SaveChanges() > 0)) { TempData["TosterState"] = "success"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "کاربر جدید با موفقیت اضافه شد."; return(RedirectToAction("User_List")); } else { TempData["TosterState"] = "error"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "کاربر جدید با موفقیت اضافه نشد."; return(View()); } }
public ActionResult Register(Model_Register model) { if (!ModelState.IsValid) { return(View("Register", model)); } Tbl_Login _Login = new Tbl_Login(); _Login.Login_Guid = Guid.NewGuid(); _Login.Login_Email = model.Email; _Login.Login_Name = model.Name; _Login.Login_Family = model.Family; _Login.Login_Mobile = model.Mobile; _Login.Login_RoleID = 1; _Login.Login_CreateDate = DateTime.Now; _Login.Login_Modify = DateTime.Now; var Salt = Guid.NewGuid().ToString("N"); var SaltPassword = model.Password + Salt; var SaltPasswordBytes = Encoding.UTF8.GetBytes(SaltPassword); var SaltPasswordHush = Convert.ToBase64String(SHA512.Create().ComputeHash(SaltPasswordBytes)); _Login.Login_PasswordHash = SaltPasswordHush; _Login.Login_PasswordSalt = Salt; db.Tbl_Login.Add(_Login); if (Convert.ToBoolean(db.SaveChanges() > 0)) { TempData["TosterState"] = "success"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "ثبت نام با موفقیت انجام شده"; return(RedirectToAction("Login")); } else { TempData["TosterState"] = "error"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "خطا"; return(View()); } }
public ActionResult Login(Tbl_Login model, string returnUrl) { dbQuanlycuahangdienmayEntities1 db = new dbQuanlycuahangdienmayEntities1(); //var dataItem = db.Tbl_Login.Where(x=>x.Username == model.Username && x.Password).First(); var dataItem = db.Tbl_Login.Where(x => x.Username == model.Username && x.Password == model.Password).SingleOrDefault(); if (dataItem != null) { if (dataItem.Role == "user") { HttpCookie cookie = new HttpCookie("userName", dataItem.Username); //cookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(cookie); return(Redirect("/")); } else { HttpCookie cookie = new HttpCookie("userName", dataItem.Username); cookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(cookie); return(Redirect("/Admin/Dashboard")); } //FormsAuthentication.SetAuthCookie(dataItem.Username, false); //if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") // && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("//")) //{ // return Redirect(returnUrl); //} //else //{ // return Redirect("/Admin/Dashboard"); //} } else { ModelState.AddModelError("", "Invalid user/pass"); return(View()); } }
private void button1_Click(object sender, EventArgs e) { Tbl_Login lo = new Tbl_Login(); RepoLogin repo = new RepoLogin(); EncriptacionPassword ecp = new EncriptacionPassword(); lo.Usuario = txtUsuario.Text; lo.Contrasenia = txtPassword.Text; if (txtUsuario.Text == "" && txtPassword.Text == "") { MessageBox.Show("Los campos deben ser llenados", "¡ADVERTENCIA!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { if (repo.LogearUsuario(lo.Usuario)) { var password = ecp.DesencriptarPassword(repo.ObtenerEncriptacion(lo.Usuario)); if (password == lo.Contrasenia) { var Id_Perfil = repo.ObtenerPerfil(lo.Usuario); if (Id_Perfil > 0) { if (Id_Perfil == 1) { MessageBox.Show("Bienvenido administrador: " + lo.Usuario, "¡BIENVENIDO!", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); ControlPrincipal cp = new ControlPrincipal(lo.Usuario); cp.Show(); } } } else { MessageBox.Show("Usuario o Contraseña incorrectos!", "¡ADVERTENCIA!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
//public static int Insertion_ManageUsers(int userid, string fname, string lname, string middlename, string suffix, string isstatus, string isadmin, string Email, string username, string password, string ExpiryDate, string LastLogin, string isTemp, string Usertype) //{ // using (AdminDataContext manageusers = new AdminDataContext()) // { // Tbl_User users; // if (userid == 0) // users = new Tbl_User(); // else // users = manageusers.Tbl_Users.Where(c => c.User_ID == userid).SingleOrDefault(); // users.User_ID = userid; // users.FirstName = fname; // users.LastName = lname; // users.MiddleName = middlename; // users.Suffix = suffix; // users.isstatus = isstatus; // users.isadmin = isadmin; // users.Email = Email; // users.UserName = username; // users.Password = password; // users.ExpireDate = ExpiryDate; // users.LastLogin = LastLogin; // users.IsTemp = isTemp; // users.UserType = Usertype; // if (userid == 0) // manageusers.Tbl_Users.InsertOnSubmit(users); // manageusers.SubmitChanges(); // return users.User_ID; // } //} public static int Insertion_ManageUsers(int userid, string fname, string lname, string middlename, string suffix, string isstatus, string isadmin, string Email, string username, string password, string ExpiryDate, string LastLogin, string isTemp, int Usertype) { using (AdminDataContext manageusers = new AdminDataContext()) { Tbl_Login users; if (userid == 0) { users = new Tbl_Login(); } else { users = manageusers.Tbl_Logins.Where(c => c.loginID == userid).SingleOrDefault(); } users.loginID = userid; users.FirstName = fname; users.LastName = lname; users.MiddleName = middlename; users.Suffix = suffix; users.isstatus = isstatus; users.isadmin = isadmin; users.Email = Email; users.UserName = username; users.Password = password; users.ExpireDate = Convert.ToDateTime(ExpiryDate); users.LastLogin = LastLogin; users.IsTemp = isTemp; users.UserType = Usertype; if (userid == 0) { manageusers.Tbl_Logins.InsertOnSubmit(users); } manageusers.SubmitChanges(); return(users.loginID); } }
public ActionResult User_Add(Model_UserAdd model) { if (User.Identity.IsAuthenticated) { return(RedirectToAction("Dashboard", "Dashboard")); } if (!ModelState.IsValid) { return(View("Register", model)); } Tbl_User _User = new Tbl_User(); Tbl_Login _Login = new Tbl_Login(); _Login.Login_Email = model.Email; _Login.Login_CreateDate = DateTime.Now; _Login.Login_ModifyDate = DateTime.Now; _Login.Login_Guid = Guid.NewGuid(); _Login.Login_Mobile = model.Mobile; _Login.Login_BaseRoleID = 2; _User.User_Guid = Guid.NewGuid(); _User.User_Name = model.Name; _User.User_Family = model.Family; _User.User_GenderCodeID = Rep_CodeGroup.Get_CodeIDWithGUID(Guid.Parse(model.Gender)); _User.User_Birtday = DateTime.Now; var Salt = Guid.NewGuid().ToString("N"); var SaltPassword = model.Password + Salt; var SaltPasswordBytes = Encoding.UTF8.GetBytes(SaltPassword); var SaltPasswordHush = Convert.ToBase64String(SHA512.Create().ComputeHash(SaltPasswordBytes)); _Login.Login_PasswordHash = SaltPasswordHush; _Login.Login_PasswordSalt = Salt; db.Tbl_User.Add(_User); _Login.Tbl_User = _User; db.Tbl_Login.Add(_Login); if (Convert.ToBoolean(db.SaveChanges() > 0)) { //if (new SMSPortal().SendServiceable(model.Mobile, model.Mobile, model.Password, "", model.Name + " " + model.Family, SMSTemplate.Register) != "ارسال به مخابرات") //{ // TempData["TosterState"] = "warning"; // TempData["TosterType"] = TosterType.Maseage; // TempData["TosterMassage"] = "خطا در ارسال پیامک"; // return RedirectToAction("Login"); //}; TempData["TosterState"] = "success"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "ثبت نام با موفقیت انجام شد"; return(RedirectToAction("index")); } else { TempData["TosterState"] = "error"; TempData["TosterType"] = TosterType.Maseage; TempData["TosterMassage"] = "ثبت نام با موفقیت انجام نشد"; return(RedirectToAction("index")); } }