Beispiel #1
0
        public ActionResult ExternalLoginCallback(string returnUrl)
        {
            Authentication.Results.AuthResult result = Authentication.OAuthSecurity.VerifyAuthentication(Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }));

            if (result.IsSuccessful)
            {
                if (Authentication.OAuthSecurity.Login(result.Provider, result.ProviderUserId, createPersistentCookie: false))
                {
                    if (result.ExtraData.ContainsKey("email"))
                    {
                        string key = string.Format("TempUserEmailAddress");

                        Session.Add(key, Library.Helpers.EncryptUtil.Encrypt(result.ExtraData["email"]));

                        return(RedirectToAction("UpdatePicture", "Account", new { returnUrl = returnUrl }));
                    }

                    return(RedirectToLocal(returnUrl));
                }

                if (!User.Identity.IsAuthenticated)
                {
                    // User is new, ask for their desired membership name
                    string loginData = Authentication.OAuthSecurity.SerializeProviderUserId(result.Provider, result.ProviderUserId);

                    Authentication.Models.Account.RegisterExternalLogin model = new Authentication.Models.Account.RegisterExternalLogin
                    {
                        UserName            = "",
                        ExternalLoginData   = loginData,
                        ProviderDisplayName = Authentication.OAuthSecurity.GetOAuthClientDataDisplayName(result.Provider),
                        ReturnUrl           = returnUrl,
                        UserEmail           = result.ExtraData["email"]
                    };

                    return(View("ExternalLoginConfirmation", model));
                }
            }

            return(RedirectToAction("ExternalLoginFailure"));
        }
Beispiel #2
0
        public ActionResult ExternalLoginConfirmation(Authentication.Models.Account.RegisterExternalLogin model)
        {
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !Authentication.OAuthSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                Entities.User user = new Entities.User
                {
                    DisplayName = model.UserName,
                    PictureUrl  = String.Format("/Account/Image?hash={0}", HttpUtility.UrlEncode(Library.Helpers.EncryptUtil.Encrypt(CalculateMD5Hash(model.UserEmail))))
                };

                // Insert name into the profile table
                _insertUser.Execute(user);

                // Check if user already exists
                if (user.UserId > 0)
                {
                    Authentication.OAuthSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                    Authentication.OAuthSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                    return(RedirectToLocal(model.ReturnUrl));
                }
                else
                {
                    ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                }
            }

            return(View(model));
        }
        public ActionResult ExternalLoginCallback(string returnUrl)
        {
            Authentication.Results.AuthResult result = Authentication.OAuthSecurity.VerifyAuthentication(Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }));
			
			if (result.IsSuccessful)
			{
                if (Authentication.OAuthSecurity.Login(result.Provider, result.ProviderUserId, createPersistentCookie: false))
				{
                    if(result.ExtraData.ContainsKey("email"))
                    {
                        string key = string.Format("TempUserEmailAddress");

                        Session.Add(key, Library.Helpers.EncryptUtil.Encrypt(result.ExtraData["email"]));

                        return RedirectToAction("UpdatePicture", "Account", new { returnUrl = returnUrl });
                    }

					return RedirectToLocal(returnUrl);
				}

				if (!User.Identity.IsAuthenticated)
				{
					// User is new, ask for their desired membership name
                    string loginData = Authentication.OAuthSecurity.SerializeProviderUserId(result.Provider, result.ProviderUserId);

					Authentication.Models.Account.RegisterExternalLogin model = new Authentication.Models.Account.RegisterExternalLogin
					{
						UserName = "",
						ExternalLoginData = loginData,
                        ProviderDisplayName = Authentication.OAuthSecurity.GetOAuthClientDataDisplayName(result.Provider),
						ReturnUrl = returnUrl,
                        UserEmail = result.ExtraData["email"]
					};

					return View("ExternalLoginConfirmation", model);
				}
			}

            return RedirectToAction("ExternalLoginFailure");
        }