Example #1
0
        public void UpdateOpenAuth( OpenAuth auth )
        {
            try {
                openauthRepository.Update(auth);
                Save();
            } catch (Exception ex) {

            }
        }
Example #2
0
 public int CreateOpenAuth( OpenAuth auth )
 {
     try {
         openauthRepository.Add(auth);
         Save();
         return auth.ID;
     } catch (Exception ex) {
         //log.Error(ex.Message, ex);
         return -1;
     }
 }
Example #3
0
 public void SinaCallback( )
 {
     var verifer = Request.QueryString["oauth_verifier"];
     if (verifer != null) {
         var reqToken = HttpContext.Session["RequestToken"] as OAuthRequestToken;
         var accessToken = AMicroblogAPI.AMicroblog.GetAccessToken(reqToken, verifer);
         HttpContext.Session["AccessToken"] = accessToken;
         AMicroblogAPI.Environment.AccessToken = accessToken;
         OpenAuth auth = openAuthService.GetOpenAuthEntityByOpenID(accessToken.UserID);
         if (auth != null) {
             if (auth.AccessTokenKey != accessToken.Token || auth.AccessTokenSecret != accessToken.Secret) {
                 auth.AccessTokenKey = accessToken.Token;
                 auth.AccessTokenSecret = accessToken.Secret;
                 openAuthService.UpdateOpenAuth(auth);
             }
             AccountState state = UserContext.Instance.OpenAuthLogin(accessToken.UserID, Utils.GetRealIP());
             switch (state) {
                 case AccountState.Normal: {
                         Response.Write("<script>opener.location.href=\"/\";window.close();</script>");
                         break;
                     }
                 //case AccountState.PendingActived: {
                 //        Model.Entities.User user = userService.GetUser(auth.UserID);
                 //        if (string.IsNullOrEmpty(user.Email)) {
                 //            Response.Write("<script>alert(\"尚未设置邮箱!\");opener.location.href=\"/site/updateemail\";window.close();</script>");
                 //        } else {
                 //            Response.Write("<script>alert(\"账户尚未激活!\");opener.location.href=\"/site/activeuser\";window.close();</script>");
                 //        }
                 //        break;
                 //    }
                 default: {
                         Response.Write("<script>opener.location.href =\"/site/login\";window.close();</script>");
                         break;
                     }
             }
         } else {
             AMicroblogAPI.DataContract.UserInfo userInfo = AMicroblogAPI.AMicroblog.GetUserInfo(Convert.ToInt64(accessToken.UserID));
             Codingwell.DevText.Model.Entities.User user = new Codingwell.DevText.Model.Entities.User();
             user.NickName = userInfo.ScreenName;
             user.Figureurl50 = userInfo.ProfileImageUrl;
             user.LastLoginTime = DateTime.Now;
             user.CreateTime = DateTime.Now;
             user.OpenAuthType = (int)OpenAuthType.Sinaweibo;
             user.AccountState = (int)AccountState.Normal;
             user.ActiveCode = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Guid.NewGuid().ToString(), "md5");
             int userid = userService.CreateUser(user);
             HttpContext.Session["UserId"] = userid;
             auth = new OpenAuth();
             auth.OpenId = accessToken.UserID;
             auth.AccessTokenKey = accessToken.Token;
             auth.AccessTokenSecret = accessToken.Secret;
             auth.UserID = userid;
             auth.InsertTime = DateTime.Now;
             openAuthService.CreateOpenAuth(auth);
             UserContext.Instance.OpenAuthLogin(accessToken.UserID, Utils.GetRealIP());
             Response.Write("<script>opener.location.href=opener.location.href;window.close();</script>");
         }
     }
 }
Example #4
0
 public void QzoneCallback( )
 {
     if (Request.Params["code"] != null) {
         var verifier = Request.Params["code"];
         QOpenClient qzone = null;
         QConnectSDK.Models.User currentUser = null;
         string state = Session["requeststate"].ToString();
         qzone = new QOpenClient(verifier, state);
         currentUser = qzone.GetCurrentUser();
         Session["QzoneOauth"] = qzone;
         if (null != currentUser) {
             OpenAuth openauth = openAuthService.GetOpenAuthEntityByOpenID(qzone.OAuthToken.OpenId);
             if (openauth != null) {
                 if (openauth.AccessTokenKey != qzone.OAuthToken.AccessToken || openauth.AccessTokenSecret != qzone.OAuthToken.AccessToken) {
                     openauth.AccessTokenKey = qzone.OAuthToken.AccessToken;
                     openauth.AccessTokenSecret = qzone.OAuthToken.AccessToken;
                     openAuthService.UpdateOpenAuth(openauth);
                 }
                 AccountState accountstate = UserContext.Instance.OpenAuthLogin(qzone.OAuthToken.OpenId, Utils.GetRealIP());
                 switch (accountstate) {
                     case AccountState.Normal: {
                             Response.Write("<script>opener.location.href=opener.location.href;window.close();</script>");
                             break;
                         }
                     //case AccountState.PendingActived: {
                     //        Model.Entities.User userentity = userService.GetUser(openauth.UserID);
                     //        if (string.IsNullOrEmpty(userentity.Email)) {
                     //            Response.Write("<script>alert(\"尚未设置邮箱!\");opener.location.href=\"/site/updateemail\";window.close();</script>");
                     //        } else {
                     //            Response.Write("<script>alert(\"账户尚未激活!\");opener.location.href=\"/site/activeuser\";window.close();</script>");
                     //        }
                     //        break;
                     //    }
                     default: {
                             Response.Write("<script>opener.location.href =\"/site/login\";window.close();</script>");
                             break;
                         }
                 }
             } else {
                 Model.Entities.User userEntity = new Model.Entities.User();
                 userEntity.NickName = currentUser.Nickname;
                 userEntity.Figureurl = currentUser.Figureurl;
                 userEntity.Figureurl50 = currentUser.Figureurl;
                 userEntity.Figureurl100 = currentUser.Figureurl;
                 userEntity.CreateTime = DateTime.Now;
                 userEntity.LastLoginTime = DateTime.Now;
                 userEntity.OpenAuthType = (int)OpenAuthType.QQ;
                 userEntity.AccountState = (int)AccountState.Normal;
                 userEntity.ActiveCode = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Guid.NewGuid().ToString(), "md5");
                 int userid = userService.CreateUser(userEntity);
                 HttpContext.Session["UserId"] = userid;
                 openauth = new OpenAuth();
                 openauth.UserID = userid;
                 openauth.OpenId = qzone.OAuthToken.OpenId;
                 openauth.AccessTokenKey = qzone.OAuthToken.AccessToken;
                 openauth.AccessTokenSecret = qzone.OAuthToken.AccessToken;
                 openauth.InsertTime = DateTime.Now;
                 openAuthService.CreateOpenAuth(openauth);
                 UserContext.Instance.OpenAuthLogin(qzone.OAuthToken.OpenId, Utils.GetRealIP());
                 Response.Write("<script>opener.location.href=opener.location.href;window.close();</script>");
             }
         }
     }
 }