public ActionResult changePassword(string oldPwd, string newPwd) { string curentUser = ControllerContext.HttpContext.User.Identity.Name; string hashPassword = HashPassword.GetHashPassword(oldPwd); string newPassword = HashPassword.GetHashPassword(newPwd); sys_user _user = Uof.Isys_userService.GetAll(item => item.user_name == curentUser && item.password == hashPassword).FirstOrDefault(); if (_user != null || string.IsNullOrEmpty(curentUser)) { _user.password = newPassword; bool b = Uof.Isys_userService.UpdateEntity(_user); var ret = new { result = b }; if (b) { FormsAuthentication.SignOut(); } AddLog("修改密码", "修改密码", "成功"); return(Json(ret)); } else { AddLog("修改密码", "修改密码", "失败"); return(Json(new { result = false })); } }
public ActionResult Index(string userName, string email) { //检测邮箱和密码是否相符 var item = _sysUserService.GetAll().SingleOrDefault( a => a.UserName.Equals(userName) && a.Email.Equals(email)); if (item == null) { ModelState.AddModelError("", "您输入的用户名或邮箱错误!"); return(View()); } //发送加密验证邮件 将加密字符串保存 到SysUserResetPassword var sysUserResetPassword = new SysUserResetPassword { SysUserId = item.Id }; var key = HashPassword.GetHashPassword(item.Id + item.Password + sysUserResetPassword.CreatedDate); sysUserResetPassword.Key = key; _sysUserResetPasswordService.Add(sysUserResetPassword); var url = Url.Action("Reset", "ForgotPassword", new { area = "Login", id = item.Id, key }, "http"); url = "<a href='" + url + "'>点此找回密码</a>"; Email.SendEmail(email, "密码找回", url); ModelState.AddModelError("", string.Format("找回密码邮件已经发送到您的{0}邮箱中!", email)); return(View()); }
public override void Update(SysUser entity) { if (entity.Password != entity.OldPassword) { entity.Password = HashPassword.GetHashPassword(entity.Password); entity.OldPassword = entity.Password; } base.Update(entity); }
public SysUser GetByUserNamePassword(Guid enterpriseId, string userName, string password) { password = HashPassword.GetHashPassword(password); return (base.GetAllEnt() .FirstOrDefault( a => a.EnterpriseId == enterpriseId && a.UserName.Equals(userName) && a.Password.Equals(password))); }
public SysUser GetByUserNamePassword(string enterpriseShortName, string userName, string password) { password = HashPassword.GetHashPassword(password); //return // base.GetAllEnt() // .FirstOrDefault( // a => // a.SysEnterprise.EnterpriseShortName == enterpriseShortName && a.UserName.Equals(userName) && // a.Password.Equals(password)); return (base.GetAllEnt() .FirstOrDefault( a => a.UserName.Equals(userName) && a.Password.Equals(password))); }
public ActionResult CreateUser([Bind(Include = "Id,Name,Phone,Email,Password,RoleId,CreatedOn,ModifiedOn,DeletedOn,IsDeleted,EmployeeId")] Users users) { try { if (ModelState.IsValid) { //validate if user all ready registered Users sucess = _UsersRepositeryObject.GetUserDetailUsingEmailAndEmployeeId(users.Email, users.EmployeeId); if (sucess == null) { users.CreatedOn = DateTime.Now; users.ModifiedOn = DateTime.Now; //To get the hash password string password = users.Password; string hashPassword = _HashPasswordObject.GetHashPassword(users.Password); users.Password = hashPassword; _UsersRepositeryObject.CreateUser(users); //Send Email to emplyee //With login credentials for task tracker _EmailQueueRepositeryObject.InsertEmailDeatailsInEmailQueue("*****@*****.**", users.Email, "Task Tracker Login Credentials", "<html>Dear " + users.Name + ",<br/><br/><br/>Your account for Task Tracker has been created. Please submit your task details befor leaving the office.<br/><br/><b>Login Id: </b>" + users.Email + "<br/><b>Password: </b>" + password + "<br/><br/><br/>Thanks & regards<br/><br/><img width=196 height=153 src=" + "http://" + Request.Url.Authority + "/Content/Image/logo.jpg" + "></b><br/><br><address><b>Adderss:</b><br/>G-282 , Sector-63<br/> Noida -201301 ,<br/>Gautam Buddh Nagar<br/>U.P, India<br><br><b>Website: </b><a href=" + "https://clanstech.com" + ">www.clanstech.com</a><br/><b>Phone:</b> <phone>+91-7042.615.658</phone><br/><b>Maps: </b><a href=" + "https://www.google.com/maps/place/Clanstech+%7C+Providing+Online+Presence/@28.614499,77.3887193,17z/data=!3m1!4b1!4m5!3m4!1s0x390cef928e84423b:0xde8604eb59d84354!8m2!3d28.614499!4d77.390908" + ">Google Maps</a></address></html>"); TempData["Message"] = "Employee Created Successfully"; return(RedirectToAction("UserIndex")); } else { TempData["Message"] = "Error : User All ready registered : Try Again"; return(RedirectToAction("CreateUser")); } } } catch (Exception ex) { MethodBase site = MethodBase.GetCurrentMethod(); string url = Request.Url.ToString(); _ExceptionLogsRepositeryObject.InsertException(ex, url, site.Name); } ViewBag.RoleId = new SelectList(db.Role, "Id", "Type", users.RoleId); return(View(users)); }
public ActionResult Login(string username, string password, string return_url) { string hashPassword = HashPassword.GetHashPassword(password); sys_user _user = Uof.Isys_userService.GetAll(item => item.user_name == username && item.password == hashPassword).FirstOrDefault(); if (_user != null) { FormsAuthentication.SetAuthCookie(username, true); Session["UserName"] = username; var url = ""; if (return_url.Trim().Length != 0) { url = return_url; } else { url = "/index.html"; } var returnObj = new { username = username, message = "", result = true, url = url }; return(Json(returnObj)); } else { var returnObj = new { message = "用户名或者密码错误", result = false, url = "" }; return(Json(returnObj)); } }
public SysUser GetByUserNamePassword(Guid userId, string password) { password = HashPassword.GetHashPassword(password); return(base.GetAllEnt().FirstOrDefault(a => a.Id.Equals(userId) && a.Password.Equals(password))); }
public override void Add(SysUser entity) { entity.Password = HashPassword.GetHashPassword(entity.Password); entity.OldPassword = entity.Password; base.Add(entity); }
public ActionResult Index(InitializeModel item) { if (applicationDbContext.SysEnterprises.Any(u => !u.Deleted && u.EnterpriseName == item.EnterpriseName)) { ModelState.AddModelError("EnterpriseName", @"该企业名称已存在"); } if (applicationDbContext.SysEnterprises.Any(u => !u.Deleted && u.EnterpriseShortName == item.EnterpriseShortName)) { ModelState.AddModelError("EnterpriseShortName", @"该企业简称已存在"); } if (!ModelState.IsValid) { return(View(item)); } try { #region SysEnterprise var host = Spell.MakeSpellCode(item.EnterpriseShortName, SpellOptions.FirstLetterOnly); //检查Host是否已经被占用 while (applicationDbContext.SysEnterprises.Any(a => a.Host == host)) { host = host + new Random().Next(11, 99); } host = host + ".wjw1.com"; var sysEnterprise = new SysEnterprise { EnterpriseName = item.EnterpriseName, EnterpriseShortName = item.EnterpriseShortName, Host = host }; applicationDbContext.SysEnterprises.Add(sysEnterprise); #endregion //添加管理员权限栏位 #region SysRole //var sysRole = new SysRole { RoleName = "管理员", EnterpriseId = sysEnterprise.Id }; var sysRole = new SysRole() { RoleName = "管理员" }; applicationDbContext.SysRoles.Add(sysRole); #endregion //添加管理员账号 #region Add Administrator User var sysUser = new SysUser { //EnterpriseId = sysEnterprise.Id, UserName = item.UserName, DisplayName = "系统管理员", Email = item.Email, Password = HashPassword.GetHashPassword(item.Password), OldPassword = HashPassword.GetHashPassword(item.Password), }; applicationDbContext.SysUsers.Add(sysUser); #endregion //对应管理员账号和管理员权限 #region SysRoleSysUser var sysRoleSysUser = new SysRoleSysUser { //EnterpriseId = sysEnterprise.Id, SysUserId = sysUser.Id, SysRoleId = sysRole.Id }; applicationDbContext.SysRoleSysUsers.Add(sysRoleSysUser); #endregion //添加详细权限给予管理员角色 #region SysRoleSysControllerSysAction var sysRoleSysControllerSysAction = new List <SysRoleSysControllerSysAction>(); foreach (var sysControllerSysAction in applicationDbContext.SysControllerSysActions) { sysRoleSysControllerSysAction.Add(new SysRoleSysControllerSysAction { //EnterpriseId = sysEnterprise.Id, SysControllerSysActionId = sysControllerSysAction.Id, SysRoleId = sysRole.Id }); } sysRoleSysControllerSysAction.ForEach(a => applicationDbContext.SysRoleSysControllerSysActions.Add(a)); #endregion applicationDbContext.SaveChanges(); TempData[Alerts.SUCCESS] = "注册成功!"; return(RedirectToAction("Index", "Succes", new { Id = sysEnterprise.Id })); } catch (Exception e) { ModelState.AddModelError("", e.Message); return(View(item)); } }
protected override void Seed(ApplicationDb context) { // This method will be called after migrating to the latest version. #region SysArea var sysAreas = new[] { new SysArea { AreaName = "Login", AreaDisplayName = "用户登录", SystemId = "000" }, new SysArea { AreaName = "Platform", AreaDisplayName = "操作平台", SystemId = "001" }, new SysArea { AreaName = "Admin", AreaDisplayName = "管理平台", SystemId = "002" } }; context.SysAreas.AddOrUpdate(a => new { a.AreaName, a.AreaDisplayName, a.SystemId }, sysAreas); #endregion #region SysAction var sysActions = new[] { new SysAction { ActionDisplayName = "列表", ActionName = "Index", SystemId = "001" }, new SysAction { ActionDisplayName = "详细", ActionName = "Details", SystemId = "003" }, new SysAction { ActionDisplayName = "新建", ActionName = "Create", SystemId = "004" }, new SysAction { ActionDisplayName = "编辑", ActionName = "Edit", SystemId = "005" }, new SysAction { ActionDisplayName = "删除", ActionName = "Delete", SystemId = "006" }, new SysAction { ActionDisplayName = "导入", ActionName = "Import", SystemId = "007" }, new SysAction { ActionDisplayName = "导出", ActionName = "Export", SystemId = "008" } }; context.SysActions.AddOrUpdate(a => new { a.ActionName, a.SystemId, a.ActionDisplayName }, sysActions); #endregion #region SysController var sysControllers = new[] { // Platform new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "操作平台", ControllerName = "Index", SystemId = "100", Display = false, }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "通知公告", ControllerName = "Message", SystemId = "101", Display = false, }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "在线沟通", ControllerName = "Chat", SystemId = "102", Display = false, }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Admin").Id, ControllerDisplayName = "管理平台", ControllerName = "Index", SystemId = "100", Display = false, }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "桌面", ControllerName = "Desktop", SystemId = "100100", Display = false, }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Admin").Id, ControllerDisplayName = "桌面", ControllerName = "Desktop", SystemId = "100100", Display = false, }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "使用帮助", ControllerName = "Help", SystemId = "100200", Display = false, }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Admin").Id, ControllerDisplayName = "使用帮助", ControllerName = "Help", SystemId = "100200", Display = false, }, //前台新的功能 new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "计划", ControllerName = "MyPlan", SystemId = "200", Ico = "fa-clock-o" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "我的计划", ControllerName = "MyPlan", SystemId = "200100", Ico = "fa-clock-o" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "我的任务", ControllerName = "MyProjectTask", SystemId = "200200", Ico = "fa-tasks" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "我的日历", ControllerName = "MyCalendar", SystemId = "200300", Ico = "fa-calendar" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "任务回复", ControllerName = "ProjectTaskReply", SystemId = "200400", Display = false, }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "项目", ControllerName = "MyParticipateWork", SystemId = "300", Ico = "fa-list-ul" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "我负责的", ControllerName = "MyCreateWork", SystemId = "300100", Ico = "fa-list-ul" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "我参与的", ControllerName = "MyParticipateWork", SystemId = "300200", Ico = "fa-list-ul" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "项目回复 ", ControllerName = "ProjectInfoReply", SystemId = "300250", Display = false, }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "我关注的", ControllerName = "MyFollowWork", SystemId = "300300", Ico = "fa-list-ul" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "公开项目", ControllerName = "AllWork", SystemId = "300400", Ico = "fa-list-ul" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "项目统计", ControllerName = "ProjectInfoCount", SystemId = "300500", Ico = "fa-list-ul" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "项目文件", ControllerName = "ProjectFile", SystemId = "300600", Display = false, Ico = "fa-file-o" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "市场", ControllerName = "Customer", SystemId = "350", Ico = "fa-shopping-cart" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "客户信息", ControllerName = "Customer", SystemId = "350050", Ico = "fa-user" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "联系人", ControllerName = "Contact", SystemId = "350100", Ico = "fa-user" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "沟通记录", ControllerName = "CustomerCommunication", SystemId = "350150", Ico = "fa-comments-o" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "业务统计", ControllerName = "CustomerCount", SystemId = "350200", Ico = "fa-cogs" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "活动管理", ControllerName = "Activity", SystemId = "350300", Ico = "fa-car" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "活动管理报名", ControllerName = "ActivityUser", Display = false, SystemId = "350300100", Ico = "fa-car" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "财务", ControllerName = "ProjectFinancial", SystemId = "360", Ico = "fa-cny" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "财务信息", ControllerName = "ProjectFinancial", SystemId = "360300", Ico = "fa-cny" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "财务汇总", ControllerName = "ProjectFinancialReport", SystemId = "360400", Ico = "fa-list-alt" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "文档", ControllerName = "Knowledge", SystemId = "400", Ico = "fa-file-o" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "知识库", ControllerName = "Knowledge", SystemId = "400200", Ico = "fa-file-text" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "知识库回复", ControllerName = "KnowledgeReply", SystemId = "400200100", Display = false, }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "同事", ControllerName = "Colleague", SystemId = "520", Ico = "fa-users" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "所有同事", ControllerName = "Colleague", SystemId = "520100", Ico = "fa-users" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "流程", ControllerName = "Flow", SystemId = "550", Ico = "fa-align-left" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "流程", ControllerName = "Flow", SystemId = "550100", Ico = "fa-align-left" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "统计", ControllerName = "ProjectInfoReport", SystemId = "600", Ico = "fa-bar-chart-o" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "项目报表", ControllerName = "ProjectInfoReport", SystemId = "600100", Ico = "fa-list" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "工作总结", ControllerName = "WorkReport", SystemId = "600200", Ico = "fa-list-ol" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "字典", ControllerName = null, SystemId = "650", Ico = "fa-book" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "项目状态", ControllerName = "ProjectInfoState", SystemId = "650100", Ico = "fa-info-circle" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "业务状态", ControllerName = "BusinessState", SystemId = "650200", Ico = "fa-circle" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "业务机会", ControllerName = "BusinessChance", SystemId = "650150", Ico = "fa-dot-circle-o" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "客户类型", ControllerName = "CustomerType", SystemId = "650300", Ico = "fa-group" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "客户等级", ControllerName = "CustomerLevel", SystemId = "650400", Ico = "fa-thumbs-up" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "管理", ControllerName = "SysUser", SystemId = "700", Ico = "fa-cog" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "组织架构", ControllerName = "SysDepartment", SystemId = "700200", Ico = "fa-sitemap" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "用户日志", ControllerName = "SysUserLog", SystemId = "700900", Ico = "fa-calendar-o" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "角色管理", ControllerName = "SysRole", SystemId = "700300", Ico = "fa-users" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Platform").Id, ControllerDisplayName = "用户管理", ControllerName = "SysUser", SystemId = "700400", Ico = "fa-user" }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Admin").Id, ControllerDisplayName = "企业管理", ControllerName = "Index", SystemId = "700", }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Admin").Id, ControllerDisplayName = "企业管理", ControllerName = "SysEnterprise", SystemId = "700200", }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Admin").Id, ControllerDisplayName = "角色管理", ControllerName = "SysRole", SystemId = "700300", }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Admin").Id, ControllerDisplayName = "用户管理", ControllerName = "SysUser", SystemId = "700400", }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Admin").Id, ControllerDisplayName = "系统设置", ControllerName = "Index", SystemId = "800", }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Admin").Id, ControllerDisplayName = "系统参数", ControllerName = "WebConfigAppSetting", SystemId = "800100", }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Admin").Id, ControllerDisplayName = "系统区域", ControllerName = "SysArea", SystemId = "800200", }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Admin").Id, ControllerDisplayName = "操作类型", ControllerName = "SysAction", SystemId = "800300", }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Admin").Id, ControllerDisplayName = "系统模块", ControllerName = "SysController", SystemId = "800400", }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Admin").Id, ControllerDisplayName = "帮助信息", ControllerName = "SysHelp", SystemId = "800900", }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Admin").Id, ControllerDisplayName = "系统信息", ControllerName = "Index", SystemId = "900", }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Admin").Id, ControllerDisplayName = "统计信息", ControllerName = "SysStatistic", SystemId = "900100", }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Admin").Id, ControllerDisplayName = "用户日志", ControllerName = "SysUserLog", SystemId = "900300", }, new SysController { SysAreaId = sysAreas.Single(a => a.AreaName == "Admin").Id, ControllerDisplayName = "系统日志", ControllerName = "SysLog", SystemId = "900400", } }; context.SysControllers.AddOrUpdate( a => new { a.SysAreaId, a.SystemId }, sysControllers); #endregion #region SysControllerSysAction SysControllerSysAction[] sysControllerSysActions = ( from sysAction in sysActions from sysController in sysControllers select new SysControllerSysAction { SysActionId = sysAction.Id, SysControllerId = sysController.Id }).ToArray(); context.SysControllerSysActions.AddOrUpdate(a => new { a.SysActionId, a.SysControllerId }, sysControllerSysActions); #endregion //添加管理员账号 #region Add Administrator User var sysUser = new SysUser { //EnterpriseId = sysEnterprise.Id, UserName = "******", DisplayName = "系统管理员", Email = "*****@*****.**", Password = HashPassword.GetHashPassword("123456"), OldPassword = HashPassword.GetHashPassword("123456"), }; context.SysUsers.Add(sysUser); #endregion //添加管理员权限栏位 #region SysRole var sysRole = new SysRole() { RoleName = "管理员" }; context.SysRoles.Add(sysRole); #endregion //对应管理员账号和管理员权限 #region SysRoleSysUser var sysRoleSysUser = new SysRoleSysUser { SysUserId = sysUser.Id, SysRoleId = sysRole.Id }; context.SysRoleSysUsers.Add(sysRoleSysUser); #endregion //添加详细权限给予管理员角色 #region SysRoleSysControllerSysAction var sysRoleSysControllerSysAction = new List <SysRoleSysControllerSysAction>(); foreach (var _sysControllerSysAction in sysControllerSysActions) { sysRoleSysControllerSysAction.Add(new SysRoleSysControllerSysAction() { SysControllerSysActionId = _sysControllerSysAction.Id, SysRoleId = sysRole.Id }); } foreach (var a in sysRoleSysControllerSysAction) { context.SysRoleSysControllerSysActions.Add(a); } #endregion }
public ActionResult Login(Login login) { try { if (ModelState.IsValid) { string email = login.Email; Users us = _UsersRepositeryObject.GetUserDetailUsingEmail(email);//email if (us == null || us.IsDeleted == true) { TempData["Message"] = "Your account deleted or does not exist:Please contact to admin"; return(RedirectToAction("Login")); } //hashing of password login.Password = _HashPasswordObject.GetHashPassword(login.Password); if (login.Email == us.Email && login.Password == us.Password) { role = _RoleRepositeryObject.GetRoleDetailUsingRoleId(us.RoleId); if (role.Type == "Admin")//need to change after project completion and all table truncate { Session["AdminId"] = us.Id; Session["UserId"] = us.Id; Session["UserName"] = us.Name; Session["UserEmail"] = us.Email; Session["RoleId"] = us.RoleId; return(RedirectToAction("AdminDashboard", "Home", new { area = "Admin" })); } else { Session["UserId"] = us.Id; Session["UserName"] = us.Name; Session["UserEmail"] = us.Email; Session["RoleId"] = us.RoleId; Mentor mentor = _MentorRepositeryObject.GetMentorDetailsUsingEmployeeId(us.Id); if (mentor != null) { Users user1 = _UsersRepositeryObject.GetUsersDetailUsingId(mentor.EmployeeMentorId); Session["MentorEmail"] = user1.Email; } return(RedirectToAction("EmployeeDashboard", "Home", new { area = "Employee" })); } } else { TempData["Message"] = "Invalid Credentials:Please Try Again"; return(RedirectToAction("Login")); } } } catch (Exception ex) { MethodBase site = MethodBase.GetCurrentMethod(); string url = Request.Url.ToString(); _ExceptionLogsRepositeryObject.InsertException(ex, url, site.Name); } return(View("Login")); }