Пример #1
0
        /// <summary>
        /// 互联登陆结果.
        /// </summary>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult OAuthReturn(string type)
        {
            if (Request.QueryString["code"] != null)
            {
                string code = Request.QueryString["code"];
                bool accredit;
                switch (type)
                {
                    case "sina":
                        var sina = new Sina();
                        accredit = sina.Authorize(code);
                        if (accredit)
                        {
                            this.SaveUserInfo(sina.openID, sina.nickName);
                        }
                        else
                        {
                            return this.View("Index");
                        }
                        break;
                    case "qq":
                        var qq = new QQ();
                        accredit = qq.Authorize(code);
                        if (accredit)
                        {
                            this.SaveUserInfo(qq.openID, qq.nickName);
                        }
                        else
                        {
                            return this.View("Index");
                        }
                        break;
                    case "renren":
                        var rr = new RenRen();
                        accredit = rr.Authorize(code);
                        if (accredit)
                        {
                            // 保存登录信息
                            this.SaveUserInfo(rr.openID, rr.nickName);
                        }
                        else
                        {
                            return this.View("Index");
                        }
                        break;
                    case "163":
                        var wy = new Wangyi();
                        accredit = wy.Authorize(code);
                        if (accredit)
                        {
                            // 保存登录信息
                            this.SaveUserInfo(wy.openID, wy.nickName);
                        }
                        else
                        {
                            return this.View("Index");
                        }
                        break;
                    case "kaixin":
                        var kx = new KaiXin();
                        accredit = kx.Authorize(code);
                        if (accredit)
                        {
                            // 保存登录信息
                            this.SaveUserInfo(kx.openID, kx.nickName);
                        }
                        else
                        {
                            return this.View("Index");
                        }
                        break;
                    case "sohu":
                        var sh = new Sohu();
                        accredit = sh.Authorize(code);
                        if (accredit)
                        {
                            // 保存登录信息
                            this.SaveUserInfo(sh.openID, sh.nickName);
                        }
                        else
                        {
                            return this.View("Index");
                        }
                        break;
                    case "douban":
                        var douban = new DouBan();
                        accredit = douban.Authorize(code);
                        if (accredit)
                        {
                            // 保存登录信息
                            this.SaveUserInfo(douban.openID, douban.nickName);
                        }
                        else
                        {
                            return this.View("Index");
                        }
                        break;
                    case "taobao":
                        var taobao = new TaoBao();
                        accredit = taobao.Authorize(code);
                        if (accredit)
                        {
                            // 保存登录信息
                            this.SaveUserInfo(taobao.openID, taobao.nickName);
                        }
                        else
                        {
                            return this.View("Index");
                        }
                        break;
                }
            }

            return this.RedirectToAction("Index", "Home");
        }
Пример #2
0
 /// <summary>
 /// 注册登录成功后保存登录数据.
 /// </summary>
 /// <param name="session">
 /// The session.
 /// </param>
 /// <param name="user">
 /// The user.
 /// </param>
 //private void LoginRegisterSeucced(UserSession session, User user)
 //{
 //    session.UserID = user.ID;
 //    session.Name = user.Name;
 //    session.LoginName = user.LoginName;
 //    session.ShowName = user.NickName ?? (user.Name ?? (user.LoginName ?? (user.Email ?? user.Mobile)));
 //    session.LastVisitTime = DateTime.Now;
 //    session.LoginTime = DateTime.Now;
 //    // 更新用户的会话Session
 //    MongoDBHelper.RemoveModel<UserSession>(u => u.UserID == user.ID);
 //    MongoDBHelper.UpdateModel(session, u => u.VisitorKey == session.VisitorKey);
 //    // 更新购物车
 //    var anonyCart = MongoDBHelper.GetModel<UserCartModel>(u => u.VisitorKey == session.VisitorKey);
 //    CartController.WriteUserCartOperationLog(
 //        new UserCartOperationLog()
 //            {
 //                OperateTime = DateTime.Now,
 //                SessionKey = this.Session.SessionID,
 //                VisitorKey = this.UserSession.VisitorKey,
 //                OperationType = "Get",
 //                Message =
 //                    "登录获取当前匿名购物车(" + this.UserSession.VisitorKey
 //                    + "):Selector:c => u => u.VisitorKey == session.VisitorKey",
 //                UserCart =
 //                    anonyCart
 //                    ?? new UserCartModel()
 //                           {
 //                               BuyList = new List<CartProduct>(),
 //                               ProductItems = new List<CartProduct>()
 //                           },
 //                UserID = this.UserSession.UserID
 //            });
 //    var userCart = MongoDBHelper.GetModel<UserCartModel>(u => u.UserId == user.ID);
 //    CartController.WriteUserCartOperationLog(
 //        new UserCartOperationLog()
 //            {
 //                OperateTime = DateTime.Now,
 //                SessionKey = this.Session.SessionID,
 //                VisitorKey = this.UserSession.VisitorKey,
 //                OperationType = "Get",
 //                Message =
 //                    "登录获取当前User购物车(" + this.UserSession.VisitorKey
 //                    + "):Selector:c => u => u.VisitorKey == session.VisitorKey",
 //                UserCart =
 //                    userCart
 //                    ?? new UserCartModel()
 //                           {
 //                               BuyList = new List<CartProduct>(),
 //                               ProductItems = new List<CartProduct>()
 //                           },
 //                UserID = this.UserSession.UserID
 //            });
 //    var cart = userCart != null && userCart.ProductItems.Count > 0 ? userCart : anonyCart;
 //    if (cart != null)
 //    {
 //        // 此用户已经有购物车数据
 //        if (cart.UserId > 0)
 //        {
 //            if (anonyCart != null && anonyCart.ProductItems.Count > 0)
 //            {
 //                // 购物车商品合并
 //                foreach (var productItem in anonyCart.ProductItems)
 //                {
 //                    var product = cart.ProductItems.FirstOrDefault(p => p.ProductID == productItem.ProductID);
 //                    if (product != null)
 //                    {
 //                        // 若原先购物车中已有此商品,则将新数据替代老数据
 //                        product.GoujiuPrice = productItem.GoujiuPrice;
 //                        product.Quantity = productItem.Quantity;
 //                        product.Discount = productItem.Discount;
 //                    }
 //                    else
 //                    {
 //                        cart.ProductItems.Add(productItem);
 //                    }
 //                }
 //            }
 //            cart.VisitorKey = session.VisitorKey; // 更新购物车的访问标示
 //        }
 //        else
 //        {
 //            cart.UserId = user.ID;
 //        }
 //        CartController.WriteUserCartOperationLog(
 //            new UserCartOperationLog()
 //                {
 //                    OperateTime = DateTime.Now,
 //                    SessionKey = this.Session.SessionID,
 //                    VisitorKey = this.UserSession.VisitorKey,
 //                    OperationType = "Edit",
 //                    Message = "登录开始更新当前User购物车(" + this.UserSession.VisitorKey + ")",
 //                    UserCart = cart,
 //                    UserID = this.UserSession.UserID
 //                });
 //        MongoDBHelper.UpdateModel<UserCartModel>(cart, uc => uc.VisitorKey == session.VisitorKey);
 //        CartController.WriteUserCartOperationLog(
 //            new UserCartOperationLog()
 //                {
 //                    OperateTime = DateTime.Now,
 //                    SessionKey = this.Session.SessionID,
 //                    VisitorKey = this.UserSession.VisitorKey,
 //                    OperationType = "Get",
 //                    Message =
 //                        "登录更新完毕当前User购物车(" + this.UserSession.VisitorKey
 //                        + "):Selector:u => u.UserId == user.ID || u.VisitorKey == session.VisitorKey",
 //                    UserCart =
 //                        MongoDBHelper.GetModel<UserCartModel>(
 //                            u => u.UserId == user.ID || u.VisitorKey == session.VisitorKey)
 //                        ?? new UserCartModel()
 //                               {
 //                                   BuyList = new List<CartProduct>(),
 //                                   ProductItems = new List<CartProduct>()
 //                               },
 //                    UserID = this.UserSession.UserID
 //                });
 //    }
 //    this.userService.ModifyUserLastLoginTime(user.ID); // 更新会员的最后登录时间
 //    HttpRuntime.Cache[session.VisitorKey] = session;
 //}
 /// <summary>
 /// 互联登录.
 /// </summary>
 /// <returns>
 /// The <see cref="ActionResult"/>.
 /// </returns>
 public ActionResult OAuthLogin(string type)
 {
     var url = string.Empty;
     switch (type)
     {
         case "sina":
             var sina = new Sina();
             url = sina.OAuthUrl;
             break;
         case "qq":
             var qq = new QQ();
             url = qq.OAuthUrl;
             break;
         case "renren":
             var rr = new RenRen();
             url = rr.OAuthUrl;
             break;
         case "163":
             var wangyi = new Wangyi();
             url = wangyi.OAuthUrl;
             break;
         case "kaixin":
             var kaixin = new KaiXin();
             url = kaixin.OAuthUrl;
             break;
         case "sohu":
             var sohu = new Sohu();
             url = sohu.OAuthUrl;
             break;
         case "douban":
             var douban = new DouBan();
             url = douban.OAuthUrl;
             break;
     }
     return this.Redirect(url);
 }