Beispiel #1
0
 public ActionResult AccountBindingSuccess()
 {
     var viewModel = new BindingModel();
     viewModel.Session = Session;
     return View(viewModel);
 }
Beispiel #2
0
        public ActionResult AccountBinding()
        {
            ViewData["ProviderId"] = Session.User.ProviderId;
            if (ViewData.Model == null)
            {
                ViewData.Model = null;
            }

            var locatedUser = ProvidersLocator.LocateService();
            if (locatedUser != null)
            {
                var user = Session.User as User;
                var id = locatedUser.Identifier;

                userBind = userModule.GetUserByProviderUserId(id);
                if (userBind != null)
                    ViewData.Model = userBind;
                else
                    ViewData.Model = 1;

                var providerName = locatedUser.Provider.Name;
                ViewData["ProviderUserId"] = id;

                var providerType = providerModule.GetProvider(providerName).Id;
                ViewData["ProviderId"] = providerType;
                var model = new BindingModel(new ChangeBindingModel(user, userBind));
                model.AccountBinding.ProviderId = providerType;
                model.AccountBinding.ProviderUserId = id;
                model.Session = Session;
                return View(model);
            }
            var viewModel = new BindingModel(new ChangeBindingModel());
            viewModel.Session = Session;
            return View(viewModel);
        }
Beispiel #3
0
        public ActionResult AccountBinding(BindingModel model, string site)
        {
            switch (site)
            {
                case "twitter":
                    var client = new TwitterClient(ProvidersLocator.TwitterTokenManager);
                    client.StartAuthentication(Request.Url);
                    break;
                case "google":
                    TransferToOpenIdProvider(OpenIdProviderEndPoints.Google.EndPoint);
                    break;
                case "vkontakte":
                    TransferToOpenIdProvider(OpenIdProviderEndPoints.VKontakte.EndPoint);
                    break;
                case "linkedin":
                    var authorization = new WebOAuthAuthorization(ProvidersLocator.LinkedinTokenManager, null);
                    var callback = Request.Url;
                    authorization.BeginAuthorize(callback);
                    break;
                case "myspace":
                    TransferToOpenIdProvider(OpenIdProviderEndPoints.MySpace.EndPoint);
                    break;
                default:
                    int curProviderId;
                    string curProviderUserId;

                    userBind = userModule.GetUserByProviderUserId(model.AccountBinding.ProviderUserId);
                    if (userBind != null)
                        userModule.CleanProvider(model.AccountBinding.ProviderUserId);
                    curProviderId = model.AccountBinding.ProviderId;
                    curProviderUserId = model.AccountBinding.ProviderUserId;

                    if (userModule.AddProvider(curProviderId, curProviderUserId, Session.User.Id))
                    {
                        HttpCookie providerCookie = new HttpCookie("SkynerCookie");

                        Session.User.ProviderId = curProviderId;
                        Session.User.ProviderUserId = curProviderUserId;

                        providerCookie.Value = providerModule.GetProvider(Session.User.ProviderId).Name;
                        Response.Cookies.Add(providerCookie);

                        ViewData["UserName"] = Session.User.UserName;
                        ViewData.Model = null;
                        return RedirectToAction("AccountBindingSuccess", "Account");
                    }
                    break;
            }
            model.Session = Session;
            return View();
        }