コード例 #1
0
 protected AbstractOAuth2ApiBinding(AccessGrant accessGrant)
 {
     this.accessToken = accessGrant.AccessToken;
     this.restTemplate = new Maticsoft.OAuth.Rest.Client.RestTemplate();
     ((WebClientHttpRequestFactory) this.restTemplate.RequestFactory).Expect100Continue = false;
     this.restTemplate.RequestInterceptors.Add(new OAuth2RequestInterceptor(accessGrant.AccessToken, this.GetOAuth2Version()));
     this.restTemplate.MessageConverters = this.GetMessageConverters();
     this.ConfigureRestTemplate(this.restTemplate);
 }
コード例 #2
0
 private ActionResult CallbackUserInfo(MediaType mediaType, AccessGrant accessGrant, string userIdOAuth, string nickNameOAuth, string emailOAuth)
 {
     if (base.CurrentUser != null)
     {
         Maticsoft.BLL.Members.UserBind bind = new Maticsoft.BLL.Members.UserBind();
         Maticsoft.Model.Members.UserBind bind2 = new Maticsoft.Model.Members.UserBind {
             MediaID = (int) mediaType,
             MediaNickName = nickNameOAuth,
             MediaUserID = userIdOAuth.ToString(),
             TokenAccess = accessGrant.AccessToken,
             UserId = (base.CurrentUser.UserType == "AA") ? -1 : base.CurrentUser.UserID,
             TokenAccess = accessGrant.AccessToken,
             TokenExpireTime = accessGrant.ExpireTime,
             Comment = true,
             iHome = true,
             GroupTopic = true
         };
         if (!bind.AddEx(bind2))
         {
             return this.Redirect("/");
         }
         if (base.currentUser.UserType == "AA")
         {
             return this.Redirect("/Admin/Accounts/UserBind.aspx");
         }
         return this.RedirectToUserBind();
     }
     string userName = string.Format("{0}_{1}", mediaType.ToString(), userIdOAuth);
     string password = userName + this.SinaSercet;
     Maticsoft.BLL.Members.Users users = new Maticsoft.BLL.Members.Users();
     User user = new User();
     if (user.HasUserByUserName(userName))
     {
         User user2 = new User(userName);
         FormsAuthentication.SetAuthCookie(userName, false);
         base.Session[Globals.SESSIONKEY_USER] = user2;
         base.Session["Style"] = user2.Style;
         new Maticsoft.BLL.Members.PointsDetail().AddPoints("Login", user2.UserID, "登录操作", "");
         if (base.Session["returnPage"] != null)
         {
             string url = base.Session["returnPage"].ToString();
             base.Session["returnPage"] = null;
             return this.Redirect(url);
         }
         return this.RedirectToHome();
     }
     User user3 = new User();
     string nickName = nickNameOAuth;
     while (user3.HasUserByNickName(nickName))
     {
         nickName = nickNameOAuth + "_" + Globals.GenRandomCodeFor6();
     }
     user.UserName = userName;
     user.Email = emailOAuth;
     user.Password = AccountsPrincipal.EncryptPassword(password);
     user.Activity = true;
     user.UserType = "UU";
     user.NickName = nickName;
     user.Style = 1;
     user.User_dateCreate = DateTime.Now;
     user.User_cLang = "zh-CN";
     int num = user.Create();
     if (num <= 0)
     {
         return this.Redirect("/");
     }
     UsersExp model = new UsersExp {
         UserID = num,
         Email = emailOAuth,
         Gravatar = string.Format("/{0}/User/Gravatar/{1}", Maticsoft.Components.MvcApplication.UploadFolder, num),
         BirthdayVisible = 0,
         BirthdayIndexVisible = false,
         ConstellationVisible = 0,
         ConstellationIndexVisible = false,
         NativePlaceVisible = 0,
         NativePlaceIndexVisible = false,
         RegionId = 0,
         AddressVisible = 0,
         AddressIndexVisible = false,
         BodilyFormVisible = 0,
         BodilyFormIndexVisible = false,
         BloodTypeVisible = 0,
         BloodTypeIndexVisible = false,
         MarriagedVisible = 0,
         MarriagedIndexVisible = false,
         PersonalStatusVisible = 0,
         PersonalStatusIndexVisible = false,
         LastAccessIP = "",
         LastAccessTime = new DateTime?(DateTime.Now),
         LastLoginTime = DateTime.Now,
         LastPostTime = new DateTime?(DateTime.Now)
     };
     if (!model.AddUsersExp(model))
     {
         users.Delete(num);
         new UsersExp().DeleteUsersExp(num);
         return this.Redirect("/");
     }
     User user4 = new User(userName);
     FormsAuthentication.SetAuthCookie(userName, false);
     base.Session[Globals.SESSIONKEY_USER] = user4;
     base.Session["Style"] = user4.Style;
     if (Maticsoft.BLL.SysManage.ConfigSystem.GetValueByCache("SNS_Register_IsBind") == "1")
     {
         Maticsoft.BLL.Members.UserBind bind3 = new Maticsoft.BLL.Members.UserBind();
         Maticsoft.Model.Members.UserBind bind4 = new Maticsoft.Model.Members.UserBind {
             MediaID = (int) mediaType,
             MediaNickName = nickNameOAuth,
             MediaUserID = userIdOAuth,
             TokenAccess = accessGrant.AccessToken,
             TokenExpireTime = accessGrant.ExpireTime,
             UserId = num,
             TokenAccess = accessGrant.AccessToken,
             TokenExpireTime = accessGrant.ExpireTime,
             Comment = true,
             iHome = true,
             GroupTopic = true
         };
         if (!bind3.AddEx(bind4))
         {
             return this.Redirect("/");
         }
     }
     string valueByCache = Maticsoft.BLL.SysManage.ConfigSystem.GetValueByCache("DefaultGravatar");
     valueByCache = string.IsNullOrEmpty(valueByCache) ? "/Upload/User/Gravatar/Default.jpg" : valueByCache;
     string str7 = Maticsoft.BLL.SysManage.ConfigSystem.GetValueByCache("TargetGravatarFile");
     str7 = string.IsNullOrEmpty(str7) ? "/Upload/User/Gravatar/" : str7;
     string str8 = base.ControllerContext.HttpContext.Server.MapPath("/");
     if (File.Exists(str8 + valueByCache))
     {
         File.Copy(str8 + valueByCache, string.Concat(new object[] { str8, str7, user4.UserID, ".jpg" }), true);
     }
     new Maticsoft.BLL.Members.PointsDetail().AddPoints("Register", num, "注册成功", "");
     Maticsoft.Model.SNS.UserAlbums albums = new Maticsoft.Model.SNS.UserAlbums();
     Maticsoft.BLL.SNS.UserAlbums albums2 = new Maticsoft.BLL.SNS.UserAlbums();
     Maticsoft.BLL.SNS.UserShip ship = new Maticsoft.BLL.SNS.UserShip();
     albums.AlbumName = "默认专辑";
     albums.CreatedDate = DateTime.Now;
     albums.CreatedNickName = user4.NickName;
     albums.CreatedUserID = user4.UserID;
     albums2.AddEx(albums, 1);
     ship.GiveUserFellow(user4.UserID);
     return this.RedirectToHome();
 }
コード例 #3
0
 public ActionResult TencentCallback(string code, string state, string openid, string openkey)
 {
     AccessGrant result;
     JsonValue value2;
     if (string.IsNullOrWhiteSpace(code) || !this.CheckSessionState(state))
     {
         return this.Redirect("/");
     }
     IOAuth2ServiceProvider<Maticsoft.OAuth.Tencent.Weibo.IWeibo> provider = new Maticsoft.OAuth.Tencent.Weibo.WeiboServiceProvider(this.TencentAppId, this.TencentSercet);
     try
     {
         result = provider.OAuthOperations.ExchangeForAccessAsync(code, this.RedirectTencentUrl, null).Result;
     }
     catch (AggregateException exception)
     {
         if (base.Session["OAuth2CallbackTry"] == null)
         {
             base.Session["OAuth2CallbackTry"] = 3;
         }
         int num = Globals.SafeInt(base.Session["OAuth2CallbackTry"].ToString(), -1);
         HttpResponseException innerException = exception.InnerExceptions[0].InnerException as HttpResponseException;
         if (innerException != null)
         {
             LogHelp.AddErrorLog(innerException.GetResponseBodyAsString(), innerException.StackTrace, "OAuth2 TencentCallback HttpResponseException Try:" + num);
         }
         if (num > 0)
         {
             base.Session["OAuth2CallbackTry"] = --num;
             return base.RedirectToAction("Tencent", "Social", new { area = Maticsoft.Components.MvcApplication.GetCurrentAreaRoute(base.ControllerContext).ToString() });
         }
         base.Session.Remove("OAuth2CallbackTry");
         return this.Redirect("/");
     }
     base.Session.Remove("OAuth2CallbackTry");
     result = new AccessGrant(result, new string[] { openid, openkey, Globals.ClientIP });
     Maticsoft.OAuth.Tencent.Weibo.IWeibo api = provider.GetApi(result);
     try
     {
         value2 = api.GetUserProfileAsync().Result;
     }
     catch (Exception exception3)
     {
         LogHelp.AddErrorLog(exception3.Message, exception3.StackTrace, "OAuth2 TencentCallback GetUserProfileAsync Exception");
         return this.Redirect("/");
     }
     if (value2 == null)
     {
         string loginfo = "GetUserProfileAsync: userInfoJson IS NULL";
         LogHelp.AddErrorLog(loginfo, loginfo, "OAuth2 TencentCallback");
         return this.Redirect("/");
     }
     string userIdOAuth = result.ExtraData[0] + "|" + result.ExtraData[1];
     string nickNameOAuth = value2.GetValue("data").GetValue<string>("name");
     return this.CallbackUserInfo(MediaType.Tencent, result, userIdOAuth, nickNameOAuth, null);
 }
コード例 #4
0
ファイル: AccessGrant.cs プロジェクト: huaminglee/myyyyshop
 public AccessGrant(AccessGrant accessGrant, string[] extraData) : this(accessGrant.AccessToken, accessGrant.Scope, accessGrant.RefreshToken, extraData, accessGrant.ExpireTime)
 {
 }
コード例 #5
0
 public QConnectOpenIdTemplate(AccessGrant accessGrant) : base(accessGrant, null)
 {
     base._accessGrant = accessGrant;
 }
コード例 #6
0
ファイル: WeiboTemplate.cs プロジェクト: huaminglee/myyyyshop
 public WeiboTemplate(AccessGrant accessGrant, string clientId) : base(accessGrant)
 {
     this._clientId = clientId;
     this._accessGrant = accessGrant;
 }