/// <summary>取消绑定</summary> /// <param name="id"></param> /// <returns></returns> public virtual ActionResult UnBind(String id) { var user = Provider.Current; if (user == null) { throw new Exception("未登录!"); } var binds = UserConnect.FindAllByUserID(user.ID); var uc = binds.FirstOrDefault(e => e.Provider.EqualIgnoreCase(id)); if (uc != null) { uc.Enable = false; uc.Update(); } #if __CORE__ var url = Request.Headers["Referer"].FirstOrDefault() + ""; #else var url = Request.UrlReferrer + ""; #endif if (url.IsNullOrEmpty()) { url = "/"; } return(Redirect(url)); }
/// <summary>取消绑定</summary> /// <param name="id"></param> /// <returns></returns> public virtual ActionResult UnBind(String id) { var user = Provider.Current; if (user == null) { throw new Exception("未登录!"); } var binds = UserConnect.FindAllByUserID(user.ID); foreach (var uc in binds) { if (uc.Provider.EqualIgnoreCase(id)) { uc.Enable = false; uc.Update(); } } if (IsJsonRequest) { return(Ok()); } var url = Provider.GetReturnUrl(Request, true); if (url.IsNullOrEmpty()) { url = "/"; } return(Redirect(url)); }
public ActionResult Binds() { var user = ManageProvider.User as XCode.Membership.User; if (user == null) { return(RedirectToAction("Login")); } user = XCode.Membership.User.FindByKeyForEdit(user.ID); if (user == null) { throw new Exception("无效用户编号!"); } // 第三方绑定 var ucs = UserConnect.FindAllByUserID(user.ID); var ms = OAuthConfig.GetValids(); var model = new BindsModel { Name = user.Name, Connects = ucs, OAuthItems = ms, }; if (IsJsonRequest) { return(Ok(data: model)); } return(View(model)); }
public ActionResult Binds() { var user = ManageProvider.User as XCode.Membership.User; if (user == null) { return(RedirectToAction("Login")); } user = XCode.Membership.User.FindByKeyForEdit(user.ID); if (user == null) { throw new Exception("无效用户编号!"); } // 第三方绑定 var ucs = UserConnect.FindAllByUserID(user.ID); var ms = OAuthConfig.Current.Items.Where(e => !e.AppID.IsNullOrEmpty()).ToList(); var model = new BindsModel { Name = user.Name, Connects = ucs, OAuthItems = ms, }; return(View(model)); }
/// <summary>抓取远程头像</summary> /// <param name="user"></param> /// <param name="url"></param> /// <returns></returns> public virtual Boolean FetchAvatar(IManageUser user, String url = null) { if (url.IsNullOrEmpty()) { url = user.GetValue("Avatar") as String; } //if (av.IsNullOrEmpty()) throw new Exception("用户头像不存在 " + user); // 尝试从用户链接获取头像地址 if (url.IsNullOrEmpty() || !url.StartsWithIgnoreCase("http")) { var list = UserConnect.FindAllByUserID(user.ID); url = list.OrderByDescending(e => e.UpdateTime) .Where(e => !e.Avatar.IsNullOrEmpty() && e.Avatar.StartsWithIgnoreCase("http")) .FirstOrDefault()?.Avatar; } if (url.IsNullOrEmpty()) { return(false); } if (!url.StartsWithIgnoreCase("http")) { return(false); } // 不要扩展名 var set = Setting.Current; var dest = set.AvatarPath.CombinePath(user.ID + ".png").GetBasePath(); //// 头像是否已存在 //if (File.Exists(dest)) return false; LogProvider.Provider?.WriteLog(user.GetType(), "抓取头像", $"{url} => {dest}", user.ID, user + ""); dest.EnsureDirectory(true); try { //var wc = new WebClientX(); //Task.Factory.StartNew(() => wc.DownloadFileAsync(url, av)).Wait(5000); var client = new HttpClient(); var rs = client.GetAsync(url).Result; var buf = rs.Content.ReadAsByteArrayAsync().Result; File.WriteAllBytes(dest, buf); // 更新头像 user.SetValue("Avatar", "/Sso/Avatar/" + user.ID); (user as IEntity)?.Update(); return(true); } catch (Exception ex) { XTrace.WriteException(ex); } return(false); }
public virtual Task DeleteAccountAsync(IUser user) { XTrace.WriteLine($"删除用户信息:{(user as TUser)}"); if (user == null || user.ID < 1) { throw ApiException.Common(_requestLocalizer["The user was not found"]); } (user as TUser)?.Delete(); var ucs = UserConnect.FindAllByUserID(user.ID); ucs.Delete(); return(Task.CompletedTask); }
public ActionResult Info(Int32?id) { if (id == null || id.Value <= 0) { throw new Exception("无效用户编号!"); } var user = ManageProvider.User; if (user == null) { return(RedirectToAction("Login")); } if (id.Value != user.ID) { throw new Exception("禁止修改非当前登录用户资料"); } user = UserX.FindByKeyForEdit(id.Value); if (user == null) { throw new Exception("无效用户编号!"); } //user.Password = null; user["Password"] = null; // 用于显示的列 if (ViewBag.Fields == null) { ViewBag.Fields = GetFields(true); } ViewBag.Factory = UserX.Meta.Factory; // 第三方绑定 var ucs = UserConnect.FindAllByUserID(user.ID); ViewBag.Binds = ucs; return(IsJsonRequest ? Json(0, "ok", user) : View(user)); }