public async Task <IActionResult> Create([Bind("Id,AdminEmail,AdminPassword,CreatedDate,LastLogin,IPAddress,UserAgent")] AdminAuth adminAuth) { if (string.IsNullOrEmpty(HttpContext.Session.GetString("_logged"))) { HttpContext.Session.SetString("_logged", "masuk"); } if (ModelState.IsValid) { var insertdb = new AdminAuth(); var message = adminAuth.AdminPassword; var salt = Salt.Create(); var hash = Hash.Create(message, salt); insertdb.AdminEmail = adminAuth.AdminEmail; insertdb.Salt = salt; insertdb.AdminPassword = hash; insertdb.CreatedDate = DateTime.Now; insertdb.IPAddress = adminAuth.IPAddress; insertdb.IsActive = 1; insertdb.UserAgent = Request.Headers["User-Agent"]; _context.Add(insertdb); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(adminAuth)); }
public async Task <IActionResult> Edit(long id, [Bind("Id,AdminEmail,AdminPassword,CreatedDate,LastLogin,IPAddress,UserAgent")] AdminAuth adminAuth) { if (string.IsNullOrEmpty(HttpContext.Session.GetString("_logged"))) { HttpContext.Session.SetString("_logged", "masuk"); } if (id != adminAuth.Id) { return(NotFound()); } if (ModelState.IsValid) { try { var updatedb = await _context.AdminAuth.FindAsync(id); if (adminAuth.AdminPassword.Length > 0) { var message = adminAuth.AdminPassword; var salt = Salt.Create(); var hash = Hash.Create(message, salt); updatedb.Salt = salt; updatedb.AdminPassword = hash; } updatedb.IPAddress = adminAuth.IPAddress; updatedb.CreatedDate = DateTime.Now; updatedb.UserAgent = Request.Headers["User-Agent"]; _context.Update(updatedb); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AdminAuthExists(adminAuth.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(adminAuth)); }
public void MultiSave(List <string> Values, int AdminId) { List <AdminAuth> AdminAuthEntities = new List <AdminAuth>(); AdminAuth adminAuthEntity; foreach (var item in Values) { adminAuthEntity = new AdminAuth(); adminAuthEntity.AdminId = AdminId; adminAuthEntity.ModulId = Int32.Parse(item); AdminAuthEntities.Add(adminAuthEntity); } foreach (var item in AdminAuthEntities) { Save(item); } }
/// <summary> /// 判断用户权限(是否有模块权限) /// </summary> /// <param name="modalNo">模块编号</param> /// <returns></returns> public static bool IsAuthority(AdminAuth modalNo) { DB.Model.M_AdminUser adminModel = (DB.Model.M_AdminUser)HttpContext.Current.Session[SESSION_ADMIN]; //从sesion获取当前用户相关信息 List <DB.Model.M_Modal> modalAuthVal = GetModalAuth(); //获取当前用户的模块权限信息 if (adminModel != null) //判断当前用户信息是否为空,既是否登录 { if (modalAuthVal != null) //判断模块信息是否为空,如果为空,返回false { for (int j = 0; j < modalAuthVal.Count; j++) //遍历循环,寻找当模块为相应编号的时候的相应模块权限是否为我们传入的值 { if (modalAuthVal[j].ModalNo == (int)modalNo) { return(true); } } return(false); } return(false); } return(false); }
public void Save(AdminAuth entity) { repository.Save(entity); }
private async void SignInExecute(object obj) { LoginStatus = string.Empty; if (CheckUsernameAndPassword()) { User a = new User(); ContentPage view = new ContentPage(); if (UserType == UserTypeVM.AdminUT) { a = await AdminAuth.GetAdmin(User); view = new Views.AdminMainPage(); } else if (UserType == UserTypeVM.RecyclerUT) { a = await RecyclerAuth.GetRecycler(User); view = new Views.RecyclerMainPage(); } else { a = await CollectorAuth.GetCollector(User); view = new Views.CollectorMainPage(); } if (a != null) { if (a.Password == Password) { if (Application.Current.Properties.ContainsKey("loggedIn")) { Application.Current.Properties["loggedIn"] = 1; } else { Application.Current.Properties.Add("loggedIn", 1); await Application.Current.SavePropertiesAsync(); } if (a is Recycler) { RecyclerVM.Recycler = (Recycler)a; } else if (a is Collector) { CollectorVM.Collector = (Collector)a; } Username = string.Empty; Password = string.Empty; Application.Current.MainPage = new NavigationPage(view); } else { Application.Current.Properties["loggedIn"] = 0; LoginStatus = "Username or password is wrong!"; } } else { LoginStatus = "Username or password not found!"; } } }