/// <summary> /// 驳回 /// </summary> /// <param name="id"></param> /// <param name="inStanceId"></param> public IActionResult NoApprove(int id, int inStanceId) { string user = HttpContext.Session.GetString("user"); UserAndRole userAndRole = JsonConvert.DeserializeObject <UserAndRole>(user); int userID = userAndRole.ID; Approve approve = _approve.GetApproveById(id); approve.ApprovePeopleId = userID; approve.State = "3"; approve.Time = DateTime.Now; int result = _approve.UpdateApprove(approve); if (result > 0) { Instance instance = _policeCase.GetInstanceById(inStanceId); instance.ApproveState = 3; int i = _policeCase.UpdateinStance(instance); if (i > 0) { return(Content("<script>alert('已驳回!');location.href='/BackWebSet/Index'</script>", "text/html;charset=utf-8")); } } else { return(Content("<script>alert('驳回失败!');location.href='/BackWebSet/Index'</script>", "text/html;charset=utf-8")); } return(View()); }
public IActionResult Login(string name, string pwd) { UserAndRole users = _student.Login(name, pwd); if (users == null) { return(Content("<script>alert('登录失败,请检查账号密码!');location.href='/BackWebSet/Login'</script>", "text/html;charset=utf-8")); } //Session存储用户信息 HttpContext.Session.SetString("user", JsonConvert.SerializeObject(users)); //构造ClaimsIdentity 对象 var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme); //创建 Claim 类型,传入 ClaimsIdentity 中 identity.AddClaim(new Claim(ClaimTypes.Name, users.ID.ToString())); //创建ClaimsPrincipal对象,传入ClaimsIdentity 对象,调用HttpContext.SignInAsync完成登录 HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity)); ////存Redis //RedisHelper.Set<UserAndRole>(users.LoginName, users); ////取Redis //var user2 = RedisHelper.Get<UserAndRole>(users.LoginName); ////存储redis //_cacheService.Add(users.LoginName, JsonConvert.SerializeObject(users)); ////取Redis //var result = _cacheService.Get(HttpContext.User.Claims.First().Value); //.net Core返回一个弹窗需要制定文本类型与编码格式 return(Content("<script>alert('登录成功');location.href='/BackWebSet/Index'</script>", "text/html;charset=utf-8")); }
/// <summary> /// 审核通过 /// </summary> /// <param name="id"></param> /// <param name="bussiness"></param> /// <returns></returns> public IActionResult PassApprove(int id, int bussiness, int inStanceId) { string user = HttpContext.Session.GetString("user"); UserAndRole userAndRole = JsonConvert.DeserializeObject <UserAndRole>(user); int userID = userAndRole.ID; Approve approve = _approve.GetApproveById(id); Instance instance = _policeCase.GetInstanceById(inStanceId); ApproveCourse approveCourse = new ApproveCourse(); if (approve.PlaceID != 0) { approveCourse = _approve.GetApproveCoursesList(approve.PlaceID); string str = approveCourse.Condition; if (!str.Contains(instance.InstanceState.ToString())) { approve.PlaceID = 0; } } //approve.Ideas = ""; //approve.State = "2"; //approve.ApprovePeopleId = userID; //approve.Time = DateTime.Now; //int i = _approve.UpdateApprove(approve); //if (i > 0) //{ if (approve.PlaceID == 0) { approve.Ideas = ""; approve.State = "2"; approve.ApprovePeopleId = userID; approve.Time = DateTime.Now; int result = _approve.UpdateApprove(approve); if (result > 0) { //Instance instance = _policeCase.GetInstanceById(inStanceId); instance.ApproveState = 2; int a = _policeCase.UpdateinStance(instance); if (a > 0) { return(Content("<script>alert('审核通过!');location.href='/BackWebSet/Index'</script>", "text/html;charset=utf-8")); } } } else { //ApproveCourse approveCourse = _approve.GetApproveCoursesList(approve.PlaceID); //Approve approves = new Approve() { BusinesstypeId = approve.BusinesstypeId, OriginalId = approve.OriginalId, PlaceID = approveCourse.PostpositionID, RoleId = approveCourse.ApproveRoleId, State = "1" }; approve.PlaceID = approveCourse.PostpositionID; approve.RoleId = approveCourse.ApproveRoleId; int result = _approve.UpdateApprove(approve); if (result > 0) { return(Content("<script>alert('您的审核通过!正在进行下一级审核');location.href='/BackWebSet/Index'</script>", "text/html;charset=utf-8")); } } //} return(View()); }
public long Create(UserAndRole o) { using (var db = new BillingDbContext()) { db.Entry(o).State = EntityState.Added; db.SaveChanges(); return(o.No); } }
public async Task <IActionResult> AddOrRemoveUsersRole(UserAndRole model) { if (await _roleService.insertUserRole(model.userId, model.roleName)) { return(Json(new { result = "User role added.", url = Url.Action("control", "role") })); } else if (await _roleService.removeUserRole(model.userId, model.roleName)) { return(Json(new { result = "User role removed.", url = Url.Action("control", "role") })); } else { return(BadRequest(Json(new { error = "Already is in role" }))); } }
public IActionResult NextPage(int id = 1) { string user = HttpContext.Session.GetString("users"); UserAndRole userAndRole = JsonConvert.DeserializeObject <UserAndRole>(user); pageParams.CurPage = id; pageParams.Filter += " and Approve.RoleId=" + userAndRole.RID; pageParams.PageSize = pageSize; PageList <ApproveDataModel> pageList = _approve.GetApproveList(userAndRole.RID); PagedList <ApproveDataModel> pagedList = new PagedList <ApproveDataModel>(pageList.ListData, id, pageParams.PageSize); pagedList = pageList.ListData.ToPagedList(id - 1, pageParams.PageSize); pagedList.TotalItemCount = pageList.TotalCount; pagedList.CurrentPageIndex = id; return(PartialView("_ShowApprove", pagedList)); }
public async Task <IActionResult> List() { //Define an active user is in "Admin" role or not bool isAdminRole = await UserAndRole.IsAdminRole(_userManager, User.Identity.Name); if (isAdminRole == true) { ViewBag.IsAdminRole = 1; } ViewBag.ActiveUser = User.Identity.Name; IEnumerable <CustomUser> customUsers = _userManager.Users.ToList(); return(View(customUsers)); }
public async Task <IActionResult> Register() { //Create default user("Admin") and roles("Admin", "İstifadəçi") if not existed while sending a request the page bool succeeded = await UserAndRole.DbInitializer(_userManager, _roleManager); if (succeeded == false) { return(NotFound()); } if (User.Identity.IsAuthenticated) { return(RedirectToAction("List", "Employee")); } return(View()); }
public async Task <IActionResult> AddToRole([FromBody] UserAndRole userAndRole) { //if (!await IsAdmin()) //{ // return BadRequest(); //} User user = await userManager.FindByNameAsync(userAndRole.userName); if (await roleManager.FindByNameAsync(userAndRole.role) == null || user == null) { return(BadRequest()); } await userManager.AddToRoleAsync(user, userAndRole.role); return(Ok()); }
public async Task <int> UpdateUserAndRole(UserAndRole input) { using (IDbConnection conn = Connection) { try { string sQuery = "UPDATE " + UserAndRole.tableName + " SET RoleId = @RoleId WHERE UserId = @UserId; "; conn.Open(); var result = await conn.ExecuteAsync(sQuery, new { UserId = input.UserId, RoleId = input.RoleId }); return(result); } catch (Exception) { throw; } finally { conn.Close(); } } }
public JsonResult CheckResetPassword(string newPassword2, string UserId) { var CurrentUser = new UserAndRole(); CurrentUser.UserId = UserId; CurrentUser.UserName = _ServicesSoapClient.GetUserName(UserId); CurrentUser.Role = _ServicesSoapClient.GetClassByUserId(UserId); //CurrentUser.UserName = UserName; CurrentUser.TerminalName = Dns.GetHostName(); string hostAddress = Request.ServerVariables.Get("Local_Addr").ToString(); if (hostAddress == "::1") { hostAddress = "127.0.0.1"; } CurrentUser.TerminalIP = hostAddress; CurrentUser.DeviceType = 1; Session["CurrentUser"] = CurrentUser; var res = new JsonResult(); // if (newPassword2 != null) { ResetPasswordFlag = _ServicesSoapClient.ResetPassword(UserId, "#*bme319*#", newPassword2, CurrentUser.UserId, CurrentUser.TerminalName, CurrentUser.TerminalIP, CurrentUser.DeviceType); if (ResetPasswordFlag == 1) { res.Data = true; } else { res.Data = false; } } res.JsonRequestBehavior = JsonRequestBehavior.AllowGet; return(res); }
public static bool SetSymptomsInfo(ServicesSoapClient _ServicesSoapClient, SymptomsViewModel sy, int RecordDate, int RecordTime, UserAndRole user) { string symptomtype = sy.SymptomsTypeSelected; //string symptom = Request.Form["SymptomsNameSelected"]; string symptom = sy.SymptomsNameSelected; string Description = sy.Description; string UserId = sy.PId; string VisitId = _ServicesSoapClient.GetNoByNumberingType(6); bool SetSymptomsInfoFlag = _ServicesSoapClient.SetSymptomsInfo(UserId, VisitId, symptomtype, symptom, Description, RecordDate, RecordTime, user.UserId, user.TerminalName, user.TerminalIP, user.DeviceType); return(SetSymptomsInfoFlag); }
/// <summary> /// /// </summary> public UserController() { userAndRole = new UserAndRole(); }
partial void OnOwnerChanging(UserAndRole value);
public ActionResult LogOn(LogOnModel LogOnModel, string control, string page) { try { if (ModelState.IsValid) { var UserId = LogOnModel.UserId; var Password = LogOnModel.Password; var Type = ""; var EmailFlag = Regex.IsMatch(UserId, @"(^[-_A-Za-z0-9]+@([_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}$)"); var PhoneFlag = Regex.IsMatch(UserId, @"(^1[3-8]\d{9}$)"); if (EmailFlag == true) { Type = "EmailAdd"; } if (PhoneFlag == true) { Type = "PhoneNo"; } if (Type != "") { UserId = _ServicesSoapClient.GetIDByInput(Type, UserId); } if (_ServicesSoapClient.CheckUserExist(UserId) == true) { if (_ServicesSoapClient.CheckPassword(UserId, Password) == 1) { var CurrentUser = new UserAndRole(); CurrentUser.UserId = UserId; CurrentUser.UserName = _ServicesSoapClient.GetUserName(UserId); //CurrentUser.Role = _ServicesSoapClient.GetClassByUserId(UserId); var RoleList = _ServicesSoapClient.GetAllRoleMatch(UserId); //var Role = RoleList.Tables[0].Rows[0]["RoleClass"]; var length = RoleList.Tables[0].Rows.Count; string[] RoleClass = new string[length]; for (int i = 0; i < length; i++) { RoleClass[i] = RoleList.Tables[0].Rows[i]["RoleClass"].ToString(); if (RoleClass[i] == "Administrator") { CurrentUser.Role = "Administrator"; } else if (RoleClass[i] == "Doctor") { CurrentUser.Role = "Doctor"; } } string hostAddress = Request.ServerVariables.Get("Remote_Addr").ToString(); if (hostAddress == "::1") { hostAddress = "127.0.0.1"; } CurrentUser.TerminalIP = hostAddress; //CurrentUser.TerminalName = Dns.GetHostName(); //CurrentUser.TerminalName = Request.ServerVariables.Get("Remote_Host").ToString(); string hostName = ""; try { System.Net.IPHostEntry host = new System.Net.IPHostEntry(); host = System.Net.Dns.GetHostEntry(hostAddress); hostName = host.HostName; } catch { } finally { if (hostName == "") { hostName = Request.ServerVariables.Get("Remote_Host").ToString(); } } CurrentUser.TerminalName = hostName; CurrentUser.DeviceType = 1; var ChangeLastLogOnTimeFlag = _ServicesSoapClient.UpdateLastLoginDateTime(CurrentUser.UserId, CurrentUser.UserName, CurrentUser.TerminalIP, CurrentUser.TerminalName, CurrentUser.DeviceType); Session["CurrentUser"] = CurrentUser; FormsAuthentication.SetAuthCookie(UserId, true); if (control == null && page == null) { if (CurrentUser.Role == "Administrator") { return(RedirectToAction("Index", "Management")); } else if (CurrentUser.Role == "Doctor") { var ActivitionFlag = _ServicesSoapClient.GetActivatedState(UserId, "Doctor"); if (ActivitionFlag == "0") { return(RedirectToAction("PatientList", "DoctorHome")); } else { return(RedirectToAction("Activition", "Account")); } } else { ModelState.AddModelError("errorConnection", "该用户没有权限登录本系统"); return(View()); } //switch (CurrentUser.Role) //{ // case "Administrator": return RedirectToAction("Index", "Dict"); // case "Doctor": return RedirectToAction("PatientList", "DoctorHome"); // //case "Patient": return RedirectToAction("HealthParameters", "PatientHome"); // default: ModelState.AddModelError("", "该用户没有权限登录本系统"); // return View(); //} } else { return(RedirectToAction(page, control)); } } else { ModelState.AddModelError("errorPassword", "密码错误,请重新输入密码"); return(View(LogOnModel)); } } else { ModelState.AddModelError("errorUserId", "用户不存在,请重新输入用户ID"); return(View(LogOnModel)); } } else { return(View(LogOnModel)); } } catch (Exception) { ModelState.AddModelError("errorConnection", "数据库连接失败"); return(View(LogOnModel)); } }
public static void SomeFunction() { Role[] roles = new Role[3] { new Role() { Id = 1, Name = "Admin" }, new Role() { Id = 2, Name = "User" }, new Role() { Id = 3, Name = "Analyst" }, }; User[] users = new User[3] { new User() { FirstName = "John", LastName = "Doe", UserName = "******", Id = 1 }, new User() { FirstName = "Tim", LastName = "Niu", UserName = "******", Id = 2 }, new User() { FirstName = "Den", LastName = "Kim", UserName = "******", Id = 3 }, }; UserAndRole[] userAndRoles = new UserAndRole[7] { new UserAndRole() { RoleId = 1, UserId = 1 }, new UserAndRole() { RoleId = 1, UserId = 2 }, new UserAndRole() { RoleId = 1, UserId = 3 }, new UserAndRole() { RoleId = 2, UserId = 1 }, new UserAndRole() { RoleId = 2, UserId = 2 }, new UserAndRole() { RoleId = 2, UserId = 3 }, new UserAndRole() { RoleId = 3, UserId = 1 }, }; // problem - get all admin users var resut = (from userAndRole in userAndRoles join role in roles on userAndRole.RoleId equals role.Id join user in users on userAndRole.UserId equals user.Id where role.Name == "Admin" select new { userName = user.UserName } ); }
public static bool SetTreatmentInfo(ServicesSoapClient _ServicesSoapClient, TreatmentViewModel Tr, UserAndRole user) { string UserId = Tr.PId; string TreatmentGoal = Tr.TreatmentInfo.TreatmentGoal; string TreatmentAction = Tr.TreatmentInfo.TreatmentAction; string Group = Tr.TreatmentInfo.Group; string TreatmentPlan = Tr.TreatmentInfo.TreatmentPlan; string Description = string.Empty; //取数据库时间 DateTime TreatTime = DateTime.Now; //输入无效,数据库取当前时间自动存入 string Duration = Tr.TreatmentInfo.Duration; bool SetTreatmentInfoFlag = _ServicesSoapClient.SetTreatmentInfo(UserId, Convert.ToInt32(TreatmentGoal), Convert.ToInt32(TreatmentAction), Convert.ToInt32(Group), TreatmentPlan, Description, TreatTime, Duration, user.UserId, user.TerminalName, user.TerminalIP, user.DeviceType); return(SetTreatmentInfoFlag); }
public async Task <IActionResult> EditStaffRole(UserAndRole input) { await _adminRepo.UpdateUserAndRole(input); return(RedirectToAction(nameof(ViewAllStaffs))); }
public ActionResult LogOn(LogOnModel LogOnModel, string control, string page) { try { if (ModelState.IsValid) { var UserId = LogOnModel.UserId; var Password = LogOnModel.Password; var Type = ""; var EmailFlag = Regex.IsMatch(UserId, @"(^[-_A-Za-z0-9]+@([_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}$)"); var PhoneFlag = Regex.IsMatch(UserId, @"(^1[3-8]\d{9}$)"); if (EmailFlag == true) { Type = "EmailAdd"; } if (PhoneFlag == true) { Type = "PhoneNo"; } if (Type != "") { UserId = _ServicesSoapClient.GetIDByInput(Type, UserId); } //判断用户是否存在 if (_ServicesSoapClient.CheckUserExist(UserId) == true)//如果用户存在 { //判断密码是否正确 if (_ServicesSoapClient.CheckPassword(UserId, Password) == 1) {//如果密码正确 var RoleList = _ServicesSoapClient.GetAllRoleMatch(UserId); var length = RoleList.Tables[0].Rows.Count; string[] RoleClass = new string[length]; bool isRoleMatch = false; for (int i = 0; i < length; i++) { RoleClass[i] = RoleList.Tables[0].Rows[i]["RoleClass"].ToString(); if (RoleClass[i] == LogOnModel.UserRole)//判断登录类型是否和用户的其中一个角色相符 { isRoleMatch = true; } } //判断是否有角色权限 if (isRoleMatch) {//如果有角色权限 var CurrentUser = new UserAndRole(); CurrentUser.UserId = UserId; CurrentUser.UserName = _ServicesSoapClient.GetUserName(UserId); CurrentUser.Role = LogOnModel.UserRole; string hostAddress = Request.ServerVariables.Get("Remote_Addr").ToString(); if (hostAddress == "::1") { hostAddress = "127.0.0.1"; } CurrentUser.TerminalIP = hostAddress; string hostName = ""; try { System.Net.IPHostEntry host = new System.Net.IPHostEntry(); host = System.Net.Dns.GetHostEntry(hostAddress); hostName = host.HostName; } catch {} finally { if (hostName == "") { hostName = Request.ServerVariables.Get("Remote_Host").ToString(); } } CurrentUser.TerminalName = hostName; CurrentUser.DeviceType = 1; var ChangeLastLogOnTimeFlag = _ServicesSoapClient.UpdateLastLoginDateTime(CurrentUser.UserId, CurrentUser.UserName, CurrentUser.TerminalIP, CurrentUser.TerminalName, CurrentUser.DeviceType); Session["CurrentUser"] = CurrentUser; FormsAuthentication.SetAuthCookie(UserId, true); if (control == null && page == null) { if (CurrentUser.Role == "Administrator" && LogOnModel.UserRole == "Administrator") {//如果是管理员 return(RedirectToAction("Index", "Management")); } else {//判断状态是否被激活 var ActivitionFlag = _ServicesSoapClient.GetActivatedState(UserId, LogOnModel.UserRole); if (ActivitionFlag == "0") {//如果被激活 CurrentUser.Role = LogOnModel.UserRole; if (CurrentUser.Role == "Doctor") { return(RedirectToAction("PatientList", "DoctorHome")); } else { return(RedirectToAction("HealthCoachPatientList", "DoctorHome")); } } else {//如果未被激活 ModelState.AddModelError("errorConnection", "该用户尚未激活"); return(View(LogOnModel)); } } } else { return(RedirectToAction(page, control)); } } else {//如果没有角色权限 ModelState.AddModelError("errorConnection", "该用户没有权限登录本系统"); return(View(LogOnModel)); } } else {//如果密码不正确 ModelState.AddModelError("errorPassword", "密码错误,请重新输入密码"); return(View(LogOnModel)); } } else {//如果用户不存在 ModelState.AddModelError("errorUserId", "用户不存在,请重新输入用户ID"); return(View(LogOnModel)); } } else { return(View(LogOnModel)); } } catch (Exception) { ModelState.AddModelError("errorConnection", "数据库连接失败"); return(View(LogOnModel)); } }