protected void btnChange_Click(object sender, EventArgs e) { TblAdmin obj = new TblAdmin(TblAdmin.Columns.Contact, txtContact.Text); if (!String.IsNullOrEmpty(obj.Contact)) { if (obj.VerificationCode == txtCode.Text) { obj.IsNew = false; obj.Password = txtNewPassword.Text; obj.Save(); h1.InnerText = "Login Form!"; lblHeading.Text = "Please sign in to your account"; divReset.Visible = false; divPasswordUpdate.Visible = false; divLogin.Visible = true; lblmsg.ForeColor = Color.Green; lblmsg.Text = "Password has been updated!"; } else { lblmsg.ForeColor = Color.Red; lblmsg.Text = "Invalid Code.!"; } } else { lblmsg.ForeColor = Color.Red; lblmsg.Text = "Invalid account contact no.!"; } }
public ActionResult AdminSil(int id) { TblAdmin t = repo.Find(x => x.ID == id); repo.TDelete(t); return(RedirectToAction("Index")); }
protected void btnSend_Click(object sender, EventArgs e) { TblAdmin obj = new TblAdmin(TblAdmin.Columns.Contact, txtContact.Text); if (ConfigurationManager.AppSettings["PinCode"] == txtPinCode.Text) { if (!String.IsNullOrEmpty(obj.Contact)) { obj.IsNew = false; obj.VerificationCode = generateRandomCode(6); // SendSms.SendMessage(txtContact.Text, "Your password verification code is " + obj.VerificationCode); obj.Save(); lblHeading.Text = "Please fill out these fields!"; divReset.Visible = false; divPasswordUpdate.Visible = true; h1.InnerText = "Update your password!"; lblmsg.Text = ""; } else { lblmsg.ForeColor = Color.Red; lblmsg.Text = "Invalid account contact no!"; } } else { lblmsg.ForeColor = Color.Red; lblmsg.Text = "Invalid Pin code!"; } }
protected void btnSignIN_Click(object sender, EventArgs e) { DataTable dt = TblAdmin.AdminLogin(txtUserName.Text, txtPassword.Text); if (dt.Rows.Count > 0) { if (chkremember.Checked) { Response.Cookies["UserName"].Value = txtUserName.Text; Response.Cookies["Password"].Value = txtPassword.Text; Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(30); Response.Cookies["Password"].Expires = DateTime.Now.AddDays(30); } Session.Clear(); Session["AdminID"] = dt.Rows[0]["AdminID"].ToString(); Session["Email"] = dt.Rows[0]["AdminEmail"].ToString(); Session["UserName"] = dt.Rows[0]["AdminName"].ToString(); Response.Redirect("Index.aspx"); } else { lblmsg.ForeColor = Color.Red; lblmsg.Text = "Invalid UserName or Password!"; } }
public async Task TestAddAdmin() { var admin = new TblAdmin(); admin.AdminId = Guid.NewGuid(); admin.UserId = Guid.NewGuid(); Assert.True(await repo.Add(admin)); }
public ActionResult AdminDuzenle(TblAdmin p) { TblAdmin t = repo.Find(x => x.ID == p.ID); t.KullaniciAdi = p.KullaniciAdi; t.Sifre = p.Sifre; repo.TUpdate(t); return(RedirectToAction("Index")); }
protected void btnSavePassword_Click(object sender, EventArgs e) { TblAdmin obj = new TblAdmin(Session["AdminID"]); obj.IsNew = false; obj.Password = txtNewPassword.Text; obj.Save(); lblmsg.Text = MessageBox.Show(msgDiv, "Password has been updated!", "alert alert-success"); }
public bool DoesExist(Guid id) { TblAdmin admin = _context.TblAdmin.FirstOrDefault(x => x.AdminId == id); if (admin != null) { return(true); } return(false); }
public ActionResult AdminDuzenle(TblAdmin p) { TblAdmin t = repo.Find(x => x.ID == p.ID); //parametreden gelen değerlere eşitliyoruz. t.KullaniciAdi = p.KullaniciAdi; t.Sifre = p.Sifre; repo.TUpdate(t); return(RedirectToAction("Index"));//index'e yönlendirsin }
protected void btnSubmit_Click(object sender, EventArgs e) { TblAdmin obj = new TblAdmin(Session["AdminID"]); obj.IsNew = false; obj.AdminName = txtAdminName.Text; obj.AdminEmail = txtUserName.Text; obj.Contact = txtContact.Text; obj.Save(); lblmsg.Text = MessageBox.Show(msgDiv, "Profile has been updated!", "alert alert-success"); }
public IActionResult tLogin(TblAdmin tbladmin) { TblAdmin admin = dBEXAMContext.TblAdmin.Where(i => i.AdName == tbladmin.AdName && i.AdPassword == tbladmin.AdPassword).SingleOrDefault(); if (admin != null) { return(RedirectToAction("DashBoard")); } else { ViewBag.msg = "Imvalid username or password"; } return(View()); }
public async Task <bool> Add(TblAdmin item) { await _context.TblAdmin.AddAsync(item); var result = await _context.SaveChangesAsync(); if (result == 1) { return(true); } else { return(false); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["AdminID"] == null) { Response.Redirect("Login.aspx"); } if (!IsPostBack) { TblAdmin obj = new TblAdmin(Session["AdminID"]); txtAdminName.Text = obj.AdminName; txtUserName.Text = obj.AdminEmail; txtContact.Text = obj.Contact; hfCurrentPassword.Value = obj.Password; cmpPass.ValueToCompare = obj.Password; } }
public ActionResult Index(TblAdmin p) { DbCvEntities db = new DbCvEntities(); var bilgi = db.TblAdmin.FirstOrDefault(x => x.KullaniciAdi == p.KullaniciAdi && x.Sifre == p.Sifre); if (bilgi != null) { FormsAuthentication.SetAuthCookie(bilgi.KullaniciAdi, false); Session["KullaniciAdi"] = bilgi.KullaniciAdi.ToString(); return(RedirectToAction("Index", "Deneyim")); } else { return(RedirectToAction("Index", "Login")); } }
public async Task <bool> Delete(Guid id) { TblAdmin admin = _context.TblAdmin.FirstOrDefault(x => x.AdminId == id); _context.TblAdmin.Remove(admin); var result = await _context.SaveChangesAsync(); if (result == 1) { return(true); } else { return(false); } }
public async Task <IActionResult> Create([Bind("AdminId,UserId")] TblAdmin tblAdmin) { if (ModelState.IsValid) { if (_adminRepository.IsAdmin(tblAdmin.UserId.ToString())) { TempData["message"] = "Selected user is already an admin"; return(RedirectToAction("Index")); } tblAdmin.AdminId = Guid.NewGuid(); await _adminRepository.Add(tblAdmin); return(RedirectToAction(nameof(Index))); } ViewData["UserId"] = new SelectList(_adminRepository.GetAllUsers(), "UserId", "Email", tblAdmin.UserId); return(View(tblAdmin)); }
public async Task <bool> Delete(Guid id) { TblUser user = _context.TblUser.FirstOrDefault(x => x.UserId == id); _context.TblUser.Remove(user); // Check if one is admin TblAdmin tblAdmin = _context.TblAdmin.FirstOrDefault(m => m.UserId == id); if (tblAdmin != null) { _context.TblAdmin.Remove(tblAdmin); } var result = await _context.SaveChangesAsync(); if (result == 1) { return(true); } else { return(false); } }
public ActionResult AdminDuzenle(int id) { TblAdmin t = repo.Find(x => x.ID == id); return(View(t)); }
public ActionResult AdminEkle(TblAdmin p) { //parametreden gelen değeri ekle ve indexe yönlendir repo.TAdd(p); return(RedirectToAction("Index")); }
public APIReturn UpdateOrCreateAdmin(AdminModel UpdateAdminModel) { string returnMsg = String.Empty; var result = new APIReturn(APIReturnCode.Fail, returnMsg); try { //檢查條件 var isNameEmpty = String.IsNullOrEmpty(UpdateAdminModel.Name); var isAccountEmpty = String.IsNullOrEmpty(UpdateAdminModel.Account); var isEmailEmpty = String.IsNullOrEmpty(UpdateAdminModel.Email); if (isNameEmpty || isAccountEmpty || isEmailEmpty) { var errMsgList = new List <string>(); if (isNameEmpty) { errMsgList.Add("姓名必填"); } if (isAccountEmpty) { errMsgList.Add("帳號必填"); } if (isEmailEmpty) { errMsgList.Add("信箱必填"); } result = new APIReturn(APIReturnCode.Fail, String.Join('、', errMsgList)); return(result); } if (!isEmailEmpty && !Regex.IsMatch(UpdateAdminModel.Email, @"^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$")) { result = new APIReturn(APIReturnCode.Fail, "Email 格式不正確"); return(result); } //找出該筆 admin var admin = db.TblAdmin.Find(UpdateAdminModel.Id); //編輯 if (admin != null) { var _tempAccount = UpdateAdminModel.Account.Trim().ToUpper(); if (_tempAccount != admin.Account.Trim().ToUpper() && //如果不是原本的那個帳號,改成已存在的帳號 db.TblAdmin.Where(a => a.Account.ToUpper() == _tempAccount).FirstOrDefault() != null) { result = new APIReturn(APIReturnCode.Fail, "帳號已存在"); return(result); } //更新資料 admin.Name = UpdateAdminModel.Name; admin.Account = UpdateAdminModel.Account; admin.Email = UpdateAdminModel.Email; admin.Phone = UpdateAdminModel.Phone; admin.EmployeeId = UpdateAdminModel.EmployeeId; admin.IsEnable = UpdateAdminModel.IsEnable; //權限mapping表,先刪除再新增 var delmap = db.MapUserPermission .Where(x => x.AdminId == UpdateAdminModel.Id); db.MapUserPermission.RemoveRange(delmap); //新增 權限 Mapping var maps = new List <MapUserPermission>(); var groups = UpdateAdminModel.Groups.Where(x => x.IsChecked == true); foreach (var group in groups) { maps.Add(new MapUserPermission() { AdminId = UpdateAdminModel.Id, PermissionId = group.Id }); } db.MapUserPermission.AddRange(maps); //寫入 DB db.SaveChanges(); returnMsg = "編輯成功"; } else { var _tempAccount = UpdateAdminModel.Account.Trim().ToUpper(); if (db.TblAdmin.Where(a => a.Account.ToUpper() == _tempAccount).FirstOrDefault() != null) { result = new APIReturn(APIReturnCode.Fail, "帳號已存在"); return(result); } var initPassword = new Random().Next(0, 99999999).ToString("00000000").ToUpper(); //新增 var newadmin = new TblAdmin() { Name = UpdateAdminModel.Name, Account = UpdateAdminModel.Account, Email = UpdateAdminModel.Email, Phone = UpdateAdminModel.Phone, EmployeeId = UpdateAdminModel.EmployeeId, IsEnable = UpdateAdminModel.IsEnable, Password = SecurityTools.MD5encrypt(initPassword), //建立隨機預設密碼 IsPasswordConfirmed = true, //重置密碼用的,表示密碼沒有重置 }; //新增 權限 Mapping var maps = new List <MapUserPermission>(); var groups = UpdateAdminModel.Groups.Where(x => x.IsChecked); foreach (var group in groups) { newadmin.MapUserPermission.Add(new MapUserPermission() { AdminId = UpdateAdminModel.Id, PermissionId = group.Id }); } db.TblAdmin.Add(newadmin); //寫入 DB db.SaveChanges(); returnMsg = "新增成功"; //發通知 //NotificationService.AddNotificationWithSend( // new TblNotification() // { // //Id // Type = "新增後台帳號通知", // Subject = "新增後台帳號通知", // Body = $"您的帳號 {newadmin.Account} 已開通,預設密碼為: {initPassword},如須變更預設密碼,請至後台點選忘記密碼。", // Recipient = !String.IsNullOrEmpty(newadmin.Email) ? // JsonConvert.SerializeObject(new string[] { newadmin.Email }) : JsonConvert.SerializeObject(new string[] { }), // Parameter = JsonConvert.SerializeObject(new string[] { }), // } // , true); } result = new APIReturn(APIReturnCode.Success, returnMsg); return(result); } catch (Exception ex) { result = new APIReturn(APIReturnCode.Exception, ex); return(result); } }
public ActionResult AdminEkle(TblAdmin p) { repo.TAdd(p); return(RedirectToAction("Index")); }