Example #1
0
        public ActionResult LogOnUsingOpenId(string site)
        {
            var locatedUser = ProvidersLocator.LocateService();
            if (locatedUser != null)
            {
                var id = locatedUser.Identifier;
                if (!String.IsNullOrEmpty(id))
                {
                    Session.User = new User();
                    Session.User.ProviderUserId = id;
                    Session.User.ProviderId = (int)locatedUser.Provider.Id;
                    var identifier = userModule.GetUserByProviderUserId(id);
                    if (identifier != null)
                    {
                        Session.User.Id = identifier.Id;
                        Session.User = userModule.GetUser(identifier.UserName);

                        ViewData["UserName"] = Session.User.UserName;
                        FormsService.SignIn(identifier.UserName, false);
                        Session.SessionEndTime = DateTime.Now;
                        return Redirect(Url.Home());
                    }
                    else
                    {
                        ViewData["ProviderId"] = id;
                        return Redirect(Url.Register(), true);
                    }
                }
            }

            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;
            }

            ViewData.Model = new AccountModel(new LogOnModel());
            return View("LogOn");
        }
Example #2
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();
        }