Ejemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Params["code"] != null)
        {
            QOpenClient qzone = null;
            User currentUser = null;

            string verifier = Request.Params["code"];
            string state = Session["requeststate"].ToString();
            qzone = new QOpenClient(verifier, state);
            currentUser = qzone.GetCurrentUser();
            if (null != currentUser)
            {
                this.result.Text = "成功登陆";
                this.Nickname.Text = currentUser.Nickname;
                this.Figureurl.ImageUrl = currentUser.Figureurl;
            }
            Session["QzoneOauth"] = qzone;
        }
    }
Ejemplo n.º 2
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>");
             }
         }
     }
 }
Ejemplo n.º 3
0
        public ActionResult QQCallback()
        {
            if (Request.Params["code"] != null)
            {
                QOpenClient qzone = null;

                var verifier = Request.Params["code"];
                var state = Request.Params["state"];

                if (state == "fc")
                {
                    qzone = new QOpenClient(verifier, state);
                    var qqUser = qzone.GetCurrentUser();
                    var openId = qzone.OAuthToken.OpenId;

                    //var cmd = new UserQQLogin(openId, qqUser.Nickname, this.GetUserIPAddress());
                    //this.CommandBus.Send(cmd);

                    //var loginUser = IoC.Resolve<IUserQuery>().GetUserByOpenID(openId, OpenAuthType.QQ);

                    //if (loginUser.IsLocked) return Redirect("~/index");
                    //else
                    //{
                    //    //暂存用户信息
                    //    var verifyHash = KeepCurrentUserInfoInTmpAndReturnHash(loginUser);
                    //    //判断用户是否开了双重身份验证
                    //    var code = 1 | (loginUser.IsOpenLoginGA ? 2 : 0) | (loginUser.IsOpenLoginSMS ? 4 : 0);
                    //    if (code > 1)
                    //    {
                    //        return Json(new { Code = 2, ReturnUrl = string.Empty, Hash = verifyHash });
                    //    }
                    //    else
                    //    {
                    //        this.CurrentUserPassTwoFactoryVerify();
                    //        return Json(new { Code = 1, ReturnUrl = string.Empty });
                    //    }
                    //}
                }
            }
            return Redirect("~/index");
        }
Ejemplo n.º 4
0
        public JsonResult SubmitNews( string json )
        {
            try {
                News news = JsonConvert.Import<News>(json);
                var cates = news.NewsCategories.ToList();
                news.NewsCategories.Clear();
                foreach (var cate in cates) {
                    var temp = newsService.GetCategory(cate.ID);
                    if (temp != null)
                        news.NewsCategories.Add(temp);
                }
                if (string.IsNullOrEmpty(news.WebFrom)) {
                    news.WebFrom = UserContext.Instance.User.NickName;
                    news.WebFromAddress = string.Format("/user/{0}/", UserContext.Instance.UserID);
                }
                //if (UserContext.Instance.User.((int)SysRoles.NewsEditor)) {
                news.State = (int)RecordState.Approved;
                //} else {
                //    news.CommentsCount = (int)RecordState.Pending;
                //}

                if (news.TopicID == 0) {
                    news.TopicID = null;
                }
                news.CreateTime = DateTime.Now;
                news.CreatorID = UserContext.Instance.UserID;
                news.AnymousComment = false;
                news.EnableComment = true;
                news.LastChanged = DateTime.Now;

                int newsid = newsService.CreateNews(news);
                bool result = newsid > 0;
                if (result) {

                    HomeContent content = new HomeContent();
                    content.Title = news.Title;
                    content.LinkUrl = string.Format("/news/detail/{0}", newsid);
                    content.ContentType = (int)HomeContentType.News;
                    content.ContentData = news.Summary;
                    content.InsertTime = DateTime.Now;
                    homecontentService.CreateHomeContent(content);
                    foreach (var auth in UserContext.Instance.User.OpenAuths) {
                        switch ((OpenAuthType)auth.OpenAuthType) {
                            case OpenAuthType.Sinaweibo: {
                                    try {
                                        UpdateStatusInfo updateStatusInfo = new UpdateStatusInfo();
                                        updateStatusInfo.Status = string.Format("【{0}】{1}@devtext http://www.devtext.com/news/detail/{2}",
                                            news.Title.Length > 30 ? news.Title.Substring(0, 30) : news.Title,
                                            news.Summary.Length > 90 ? news.Summary.Substring(0, 90) : news.Summary,
                                                                                newsid);
                                        AMicroblogAPI.AMicroblog.PostStatus(updateStatusInfo);
                                    } catch (Exception ex) {

                                    }
                                    break;
                                }
                            case OpenAuthType.QQ: {
                                    try {
                                        QConnectSDK.QOpenClient qzone =
                                            new QOpenClient(new OAuthToken() { AccessToken = auth.AccessTokenKey, OpenId = auth.OpenId });
                                        if (qzone != null) {
                                            qzone.AddFeeds(news.Title.Length > 30 ? news.Title.Substring(0, 30) : news.Title,
                                                           string.Format("http://www.devtext.com/news/detail/{0}", newsid));
                                        }
                                    } catch (Exception ex) {

                                    }
                                    break;
                                }
                        }
                    }
                }

                return Json(new { success = result, message = result ? "投递成功" : "投递失败" });
            } catch (Exception ex) {
                //log.Error(ex);
                return Json(new { success = false, message = "发生异常,投递失败,请稍候再试" });
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// QQ用户登录
        /// </summary>
        protected void QQLogin()
        {
            DataEntities ent = new DataEntities();

            if (Request.Params["code"] != null)
            {
                QOpenClient qzone = null;
                QConnectSDK.Models.User currentUser = null;
                var verifier = Request.Params["code"];
                string state = Session["requeststate"].ToString();
                qzone = new QOpenClient(verifier, state);
                //
                currentUser = qzone.GetCurrentUser();
                if (null != currentUser)
                {
                    string openid = qzone.OAuthToken.OpenId;

                    var SysUser = //UserView.Find(string.Format("UserName=N'{0}'", openid));
                        (from l in ent.User where l.UserName == openid select l).FirstOrDefault();
                    if (SysUser.ID <= 0)
                    {

                        SysUser.Cent = SystemSetting.RegCent;
                        SysUser.ChineseName = currentUser.Nickname;

                        SysUser.Enable = true;
                        SysUser.Group = 0;
                        SysUser.Image = currentUser.Figureurl;

                        SysUser.LastLoginIP = WS.GetIP();
                        SysUser.LastLoginTime = DateTime.UtcNow.AddHours(8);
                        SysUser.LoginCount = 1;
                        SysUser.PostCount = 0;
                        SysUser.RegIP = WS.GetIP();
                        SysUser.RegTime = DateTime.UtcNow.AddHours(8);
                        SysUser.StudentNo = "";
                        SysUser.TeachNo = "";
                        SysUser.Tel = "";
                        SysUser.Twitter = "";
                        SysUser.UserName = openid;
                        SysUser.UserPass = "";
                        SysUser.WebSite = "";
                        //SysUser.Weibo = "";

                        try
                        {
                            var i = qzone.GetWeiboUserInfo("", qzone.OAuthToken.OpenId);
                            SysUser.Address = i.Data.Location;
                            SysUser.Email = i.Data.Email;
                            SysUser.Intro = i.Data.Introduction;
                            SysUser.ZipCode = i.Data.City_code.ToS();
                        }
                        catch
                        {

                        }

                        //UserView.Insert(SysUser);
                        ent.AddToUser(SysUser);

                    }
                    else
                    {
                        SysUser.LoginCount++;
                        SysUser.LastLoginIP = WS.GetIP();
                        SysUser.LastLoginTime = DateTime.UtcNow.AddHours(8);

                    }
                    ent.SaveChanges();

                    //System.Web.HttpContext.Current.Session["sys_user"] = SysUser.ID;

                    System.Web.HttpCookie cookie = new System.Web.HttpCookie("User");
                    cookie.Expires = DateTime.Now.AddDays(7);
                    cookie.Values.Add("uid", SysUser.ID.ToString());
                    cookie.Values.Add("k", Voodoo.Security.Encrypt.Md5(string.Format("{0}{1}{2}",
                        SysUser.ID,
                        SysUser.UserName,
                        SysUser.UserPass,
                        BasePage.SystemSetting.SiteName
                        )));
                    Voodoo.Cookies.Cookies.SetCookie(cookie);

                    Response.Redirect("/");

                }

                Session["QzoneOauth"] = qzone;
            }
            ent.Dispose();
        }
Ejemplo n.º 6
0
        public JsonResult SubmitPost( string json )
        {
            try {
                Article article = JsonConvert.Import<Article>(json);
                if (string.IsNullOrEmpty(article.WebFrom)) {
                    article.WebFrom = UserContext.Instance.User.NickName;
                    article.WebFromAddress = "/user/" + UserContext.Instance.UserID + "/";
                }
                var cates = article.ArticleCategories.ToList();
                article.ArticleCategories.Clear();
                foreach (var cate in cates) {
                    var temp = articleService.GetArticleCategory(cate.ID);
                    if (temp != null)
                        article.ArticleCategories.Add(temp);
                }
                article.State = (int)RecordState.Approved;
                article.CreateTime = DateTime.Now;
                article.CreatorID = UserContext.Instance.UserID;
                article.AnymousComment = false;
                article.EnableComment = true;
                article.LastChanged = DateTime.Now;
                int aritlceid = articleService.CreateArticle(article);
                bool result = aritlceid > 0;
                if (result) {
                    HomeContent content = new HomeContent();
                    content.Title = article.Title;
                    content.LinkUrl = string.Format("/blogs/detail/{0}", aritlceid);
                    content.ContentType = (int)HomeContentType.Article;
                    content.ContentData = article.Summary;
                    content.InsertTime = DateTime.Now;
                    homecontentService.CreateHomeContent(content);
                    foreach (var auth in UserContext.Instance.User.OpenAuths) {
                        switch ((OpenAuthType)auth.OpenAuthType) {
                            case OpenAuthType.Sinaweibo: {
                                    try {
                                        UpdateStatusInfo updateStatusInfo = new UpdateStatusInfo();
                                        updateStatusInfo.Status = string.Format("【{0}】{1}@devtext http://www.devtext.com/blogs/detail/{2}",
                                                                                article.Title.Length > 30
                                                                                    ? article.Title.Substring(0, 30)
                                                                                    : article.Title,
                                                                                article.Summary.Length > 90
                                                                                    ? article.Summary.Substring(0, 90)
                                                                                    : article.Summary,
                                                                                aritlceid);
                                        AMicroblogAPI.AMicroblog.PostStatus(updateStatusInfo);
                                    } catch (Exception ex) {

                                    }
                                    break;
                                }
                            case OpenAuthType.QQ: {
                                    try {
                                        QConnectSDK.QOpenClient qzone =
                                            new QOpenClient(new OAuthToken() { AccessToken = auth.AccessTokenKey, OpenId = auth.OpenId });
                                        if (qzone != null) {
                                            qzone.AddFeeds(article.Title.Length > 30 ? article.Title.Substring(0, 30) : article.Title,
                                                           string.Format("http://www.devtext.com/blogs/detail/{0}", aritlceid));
                                        }
                                    } catch (Exception ex) {

                                    }
                                    break;
                                }
                        }
                    }
                }

                return Json(new { success = result, message = result ? "发布成功" : "发布失败" });
            } catch (Exception ex) {
                //log.Error(ex);
                return Json(new { success = false, message = "发生异常,请检查收再试" });
            }
        }
Ejemplo n.º 7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (Request.Params["code"] != null)
        //{
        //    QOpenClient qzone = null;
        //    User currentUser = null;

        //    var verifier = Request.Params["code"];
        //    string state = Session["requeststate"].ToString();
        //    qzone = new QOpenClient(verifier, state);
        //    currentUser = qzone.GetCurrentUser();
        //    if (null != currentUser)
        //    {
        //        this.result.Text = "成功登陆";
        //        this.Nickname.Text = currentUser.Nickname;
        //        this.Figureurl.ImageUrl = currentUser.Figureurl;
        //    }
        //    Session["QzoneOauth"] = qzone;
        //}
        //Response.Write(Request.Params["code"]+"1<br/>");
        //Response.Write(Request.Params["state"]+"2");
        //Response.End();
        if (Request.Params["code"] != null && Request.Params["state"] != null)
        {
            QOpenClient qzone = null;
            User currentUser = null;

            var verifier = Request.Params["code"];
            var state = Request.Params["state"];
            qzone = new QOpenClient(verifier, state);
            currentUser = qzone.GetCurrentUser();
            if (null != currentUser)
            {
                this.result.Text = "成功登陆";
                this.Nickname.Text = currentUser.Nickname;
                this.Figureurl.ImageUrl = currentUser.Figureurl;
                //Session["VId"] = "";
                //Session["LoginType"] = "QQ登陆中";
                Session["qzone"] = qzone;
                //Session["UserName"] = currentUser.Nickname;
                //Session["LoginOpenID"] = qzone.OAuthToken.OpenId;
            }
            else
            {
                Session["qzone"] = null;
            }

            //Response.Write(Session["fromurls"].ToString() + "1<br/>");
            //Response.Write(currentUser.Nickname + "2");
            //Response.End();
            //Session["QzoneOauth"] = qzone;
            if (Session["fromurls"] == null)
            {
                Response.Redirect("~/VoteProject/SFIVoteList.aspx");
            }
            else if (Session["fromurls"].ToString().Trim() == "")
            {
                Response.Redirect("~/VoteProject/SFIVoteList.aspx");
            }
            else
            {
                Response.Redirect(Session["fromurls"].ToString());
            }
        }
    }
Ejemplo n.º 8
0
        public ActionResult QQConnect()
        {
            if (Request.Params["code"] != null)
            {
                QOpenClient qzone = null;

                var verifier = Request.Params["code"];
                var state = Request.Params["state"];
                string requestState = Session["requeststate"].ToString();

                if (state == requestState)
                {
                    qzone = new QOpenClient(verifier, state);
                    var currentUser = qzone.GetCurrentUser();
                    if (this.Session["QzoneOauth"] == null)
                    {
                        this.Session["QzoneOauth"] = qzone;
                    }
                    var friendlyName = currentUser.Nickname;
                    var isPersistentCookie = true;

                    SetAuthCookie(qzone.OAuthToken.OpenId, friendlyName, isPersistentCookie);

                    return RedirectToAction("Index", "Home");
                }

            }
            return View();
        }