Example #1
0
 public ActionResult Login(LoginModel model, string returnUrl)
 {
     if (base.ModelState.IsValid)
     {
         bool rememberMe = model.RememberMe;
         if (WebSecurity.Login(model.UserName, model.Password, rememberMe))
         {
             return(this.RedirectToLocal(returnUrl));
         }
         int userId = WebSecurity.GetUserId(model.UserName);
         if ((userId > 0) && !WebSecurity.IsConfirmed(model.UserName))
         {
             base.ModelState.AddModelError("", AccountStrings.AccountLogin_EmailNotConfirmed);
             string userConfirmationToken = MembershipHelper.GetUserConfirmationToken(userId);
             if (userConfirmationToken != null)
             {
                 base.ModelState.AddModelError("", AccountStrings.RegisterEmailNotConfirmedNote);
                 this.SendRegistrationConfirmMail(ConfirmMailOperation.confirm, model.UserName, userConfirmationToken);
             }
         }
         else
         {
             base.ModelState.AddModelError("", AccountStrings.AccountLogin_InvalidCredentails);
         }
     }
     ((dynamic)base.ViewBag).ReturnUrl = returnUrl;
     return(base.View(model));
 }
Example #2
0
        public ActionResult ExternalLoginCallback(string returnUrl)
        {
            AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(base.Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }));

            if (!result.IsSuccessful)
            {
                return(base.RedirectToAction("ExternalLoginFailure"));
            }
            bool   flag     = false;
            string userName = OAuthWebSecurity.GetUserName(result.Provider, result.ProviderUserId);

            if (userName != null)
            {
                flag = WebSecurity.IsConfirmed(userName);
                if (flag)
                {
                    bool createPersistentCookie = false;
                    if (OAuthWebSecurity.Login(result.Provider, result.ProviderUserId, createPersistentCookie))
                    {
                        return(this.RedirectToLocal(returnUrl));
                    }
                    if (base.User.Identity.IsAuthenticated)
                    {
                        OAuthWebSecurity.CreateOrUpdateAccount(result.Provider, result.ProviderUserId, base.User.Identity.Name);
                        return(this.RedirectToLocal(returnUrl));
                    }
                }
                else
                {
                    string userConfirmationToken = MembershipHelper.GetUserConfirmationToken(WebSecurity.GetUserId(userName));
                    if (userConfirmationToken != null)
                    {
                        this.SendRegistrationConfirmMail(ConfirmMailOperation.confirm, userName, userConfirmationToken);
                    }
                }
            }
            ((dynamic)base.ViewBag).NotConfirmedEmail = (userName != null) && !flag;
            string str3 = OAuthWebSecurity.SerializeProviderUserId(result.Provider, result.ProviderUserId);
            AuthenticationClientData oAuthClientData = OAuthWebSecurity.GetOAuthClientData(result.Provider);

            ((dynamic)base.ViewBag).ProviderDisplayName = oAuthClientData.DisplayName;
            ((dynamic)base.ViewBag).ReturnUrl           = returnUrl;
            RegisterExternalLoginModel model = new RegisterExternalLoginModel {
                UserName          = (result.UserName.Contains("@") && result.UserName.Contains(".")) ? result.UserName : "",
                ExternalLoginData = str3
            };

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