public async Task <string> SubmitLoginAsync(LoginInputDTO input) { input.password = input.password.ToMD5String(); var theUser = await GetIQueryable() .Where(x => x.UserName == input.userName && x.Password == input.password) .FirstOrDefaultAsync(); if (theUser.IsNullOrEmpty()) { throw new BusException("账号或密码不正确!"); } List <UserProjectDTO> projusers = await _mini_project_userBusiness.GetUserProjectListAsync(theUser.UserName); if (projusers?.Count > 0) { var defaultProject = projusers.FirstOrDefault(x => x.Id == theUser.Last_Interview_Project)?.Id; if (theUser.Last_Interview_Project != defaultProject) { theUser.Last_Interview_Project = defaultProject; await UpdateAsync(theUser); } } //生成token,有效期一天 JWTPayload jWTPayload = new JWTPayload { UserId = theUser.Id, Expire = DateTime.Now.AddDays(1) }; string token = JWTHelper.GetToken(jWTPayload.ToJson(), JWTHelper.JWTSecret); return(token); }
public AjaxResult SubmitLogin(string userName, string password) { if (userName.IsNullOrEmpty() || password.IsNullOrEmpty()) { return(Error("账号或密码不能为空!")); } password = password.ToMD5String(); var theUser = GetIQueryable().Where(x => x.UserName == userName && x.Password == password).FirstOrDefault(); if (theUser != null) { //生成token,有效期一天 JWTPayload jWTPayload = new JWTPayload { UserId = theUser.Id, Expire = DateTime.Now.AddDays(1) }; string token = JWTHelper.GetToken(jWTPayload.ToJson(), JWTHelper.JWTSecret); return(Success(token)); } else { return(Error("账号或密码不正确!")); } }
public async Task <string> SubmitLoginAsync(LoginInputDTO input) { input.password = input.password.ToMD5String(); var theUser = await GetIQueryable() .Where(x => x.UserName == input.userName && x.Password == input.password) .FirstOrDefaultAsync(); if (theUser.IsNullOrEmpty()) { throw new BusException("账号或密码不正确!"); } //生成token,有效期一天 JWTPayload jWTPayload = new JWTPayload { UserId = theUser.Id, Expire = DateTime.Now.AddDays(1) }; string token = JWTHelper.GetToken(jWTPayload.ToJson(), JWTHelper.JWTSecret); return(token); }
public async Task <string> Login(string code) { string token = WeChatOperation.GetToken(EnumWeChatAppType.Food); if (token == null) { throw new BusException("获取授权token失败!"); } string userId = WeChatOperation.GetUserId(code, token); if (userId == null) { throw new BusException("获取授权userId失败"); } //缓存token,不重复获取 //查询用户信息 var userInfo = GetIQueryable().Where(a => a.WeCharUserId == userId)?.FirstOrDefault(); if (userInfo == null || string.IsNullOrEmpty(userInfo.Department)) { WeChatUserInfo weChatUserInfo = WeChatOperation.GetUserInfo(token, userId); WeChatDepartmentList weChatDepartmentList = null; string departmentPath = string.Empty; string departmentId = string.Empty; string department = string.Empty; if (weChatUserInfo == null) { throw new BusException("获取用户信息失败,登录失败!"); } if (!string.IsNullOrEmpty(weChatUserInfo.main_department)) { //底层部门 weChatDepartmentList = WeChatOperation.GetDepartment(token, weChatUserInfo.main_department); if (weChatDepartmentList != null) { departmentId = weChatDepartmentList?.department?.FirstOrDefault()?.parentid; departmentPath = weChatDepartmentList?.department?.FirstOrDefault()?.name; department = weChatDepartmentList?.department?.FirstOrDefault()?.name; } //倒数第二 weChatDepartmentList = WeChatOperation.GetDepartment(token, departmentId); if (weChatDepartmentList != null) { departmentPath = weChatDepartmentList?.department?.Where(a => a.id == departmentId)?.FirstOrDefault()?.name + "/" + departmentPath; departmentId = weChatDepartmentList?.department?.Where(a => a.id == departmentId) ?.FirstOrDefault() ?.parentid; } //倒数第三 weChatDepartmentList = WeChatOperation.GetDepartment(token, departmentId); if (weChatDepartmentList != null) { departmentPath = weChatDepartmentList?.department?.Where(a => a.id == departmentId)?.FirstOrDefault()?.name + "/" + departmentPath; } } if (userInfo == null) { F_UserInfo fUserInfo = new F_UserInfo() { Id = IdHelper.GetId(), IsAdmin = false, ShopInfoId = "", UserName = weChatUserInfo.name, UserImgUrl = weChatUserInfo.avatar, WeCharUserId = weChatUserInfo.userid, Department = department, FullDepartment = departmentPath, CreateTime = DateTime.Now, CreatorId = "system", CreatorName = weChatUserInfo.name, }; await InsertAsync(fUserInfo); } else if (string.IsNullOrEmpty(userInfo.Department) || string.IsNullOrEmpty(userInfo.FullDepartment)) { //更新部门//组合倒数第二级部门 userInfo.Department = department; userInfo.FullDepartment = departmentPath; userInfo.UpdateTime = DateTime.Now; userInfo.UpdateName = userInfo.UserName; userInfo.UpdateId = userInfo.UpdateId; await Service.UpdateAnyAsync(userInfo, new List <string>() { "Department", "UpdateTime", "UpdateName", "UpdateId" }); } } //生成token,有效期一个月 JWTPayload jWTPayload = new JWTPayload { UserId = userId, Expire = DateTime.Now.AddDays(30), AppId = (int)EnumWeChatAppType.Food }; string tk = JWTHelper.GetToken(jWTPayload.ToJson(), JWTHelper.JWTClient); return(tk); }