public virtual async Task RemoveLoginAsync(TUser user, UserLoginInfo login) { user.CheckNotNull("user"); login.CheckNotNull("login"); await UserLoginRepository.DeleteAsync( m => m.User.Id.Equals(user.Id) && m.LoginProvider == login.LoginProvider && m.ProviderKey == login.ProviderKey); }
/// <summary> /// 绑定小程序至账号 /// </summary> /// <param name="encrpytedUserId"></param> /// <returns></returns> public virtual async Task BindLogin(string encryptedUserId, string openId) { if (!int.TryParse(SimpleStringCipher.Instance.Decrypt(encryptedUserId, AppConsts.DefaultPassPhrase), out var userid)) { throw new UserFriendlyException("未找到对应用户"); } var user = await UserRepository.GetAll().IgnoreQueryFilters().Where(o => o.Id == userid).SingleAsync(); await UserLoginRepository.DeleteAsync(o => o.UserId == userid && o.LoginProvider == MiniProgramAuthProviderApi.Name); var userlogin = new UserLogin() { UserId = userid, LoginProvider = MiniProgramAuthProviderApi.Name, TenantId = user.TenantId, ProviderKey = openId }; await UserLoginRepository.InsertAsync(userlogin); }
/// <summary> /// 删除实体信息信息 /// </summary> /// <param name="ids">要删除的实体信息编号</param> /// <returns>业务操作结果</returns> public Task <OperationResult> DeleteUserLogins(params Guid[] ids) { return(UserLoginRepository.DeleteAsync(ids, entity => { int userId = CurrentUser.Identity.GetUserId <int>(); if (entity.UserId != userId) { throw new OsharpException("要解除的第三方登录绑定不属于当前用户"); } var user = UserManager.Users.Where(m => m.Id == userId).Select(m => new { m.PasswordHash, m.NormalizeEmail }).First(); if ((string.IsNullOrEmpty(user.PasswordHash) || string.IsNullOrEmpty(user.NormalizeEmail)) && UserLoginRepository.QueryAsNoTracking(m => m.UserId == entity.UserId).Count() == 1) { throw new OsharpException("当前用户未设置登录密码,并且要解除的第三方登录是唯一登录方式,无法解除"); } return Task.FromResult(0); })); }