LoginUser() public method

public LoginUser ( string userName, string password, string ipAddress ) : string
userName string
password string
ipAddress string
return string
コード例 #1
0
 public virtual ActionResult Login(string language, string emailAddress, string password, bool rememberMe = false)
 {
     var ctx = new DatabaseDataContext();
     var token = "";
     var message = "";
     try
     {
         ctx.LoginUser(emailAddress, password, HostIPAddress);
     }
     catch (Exception e)
     {
         switch (e.ErrorCode())
         {
             case 60020:
                 message = Resources.Home.Login.LoginError_60020;
                 break;
             case 60022:
                 message = Resources.Home.Login.LoginError_60022;
                 break;
         }
     }
     return View();
 }
コード例 #2
0
        public virtual ActionResult ExternalLoginCallback(string returnUrl)
        {
            var ctx = new DatabaseDataContext();
            var bypass = ctx.GetSetting("ByPassPrefix");
            AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }));
            if (!result.IsSuccessful)
            {
                return RedirectToAction("ExternalLoginFailure");
            }
            var email = result.ExtraData["username"].ToLower();
            long id = -1;
            try
            {
                id = ctx.GetUserIDByEmail(email);
            }
            catch
            {

            }

            if (id == -1)
            {
                // new user should not get a confirmation mail
                try
                {
                    id = ctx.RegisterNewUser(
                        email,
                        Convert.ToBase64String(new SHA1CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(new Guid().ToString()))),
                        false,
                        returnUrl
                    );
                }
                catch
                {
                }
            }

            string token = "";
            if (id != -1)
            {
                try
                {
                    token = ctx.LoginUser(bypass + "_" + email, "notneeded", MvcApplication.HostIPAddress(HttpContext));
                }
                catch (Exception exception)
                {
                    switch (exception.ErrorCode())
                    {
                        case 60021:
                            ctx.ConfirmEmailAddress(Convert.ToBase64String(new SHA1CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(email))));
                            break;
                    }
                }
                // second try
                if (string.IsNullOrWhiteSpace(token))
                {
                    try
                    {
                        token = ctx.LoginUser(bypass + "_" + email, "notneeded", MvcApplication.HostIPAddress(HttpContext));
                    }
                    catch
                    {
                    }
                }
            }

            if (!string.IsNullOrWhiteSpace(token))
            {
                var tokenCookie = new HttpCookie("GameToken", token);
                tokenCookie.Expires = DateTime.Now.AddYears(1);
                Response.Cookies.Add(tokenCookie);
                if (!string.IsNullOrWhiteSpace(returnUrl))
                {
                    if (returnUrl.Contains("{guid}"))
                    {
                        if (returnUrl.Contains("?"))
                            returnUrl = returnUrl.Replace("{guid}", "&guid=" + token);
                        else
                            returnUrl = returnUrl.Replace("{guid}", "?guid=" + token);
                    }
                }
                else
                {
                    returnUrl = Url.Action(MVC.Home.Index());
                }
                ViewBag.ReturnUrl = returnUrl;
                return View(MVC.Home.Views.Shared.ExternalLoginCallback);
            }

            return RedirectToAction("ExternalLoginFailure");
        }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: Jacco/Perpetuality
        public virtual ActionResult Login(string language, string emailAddress, string password, bool rememberMe = false)
        {
            var ctx = new DatabaseDataContext();
            var token = "";
            var message = "";
            try
            {
                token = ctx.LoginUser(emailAddress, password, HostIPAddress);

                if (!string.IsNullOrWhiteSpace(token))
                {
                    var tokenCookie = new HttpCookie("GameToken", token);
                    tokenCookie.Expires = DateTime.Now.AddYears(1);
                    Response.Cookies.Add(tokenCookie);
                }
            }
            catch (Exception e)
            {
                switch (e.ErrorCode())
                {
                    case 60020:
                        message = Resources.Home.Login.LoginError_60020;
                        break;
                    case 60022:
                        message = Resources.Home.Login.LoginError_60022;
                        break;
                }
            }
            return RedirectToAction(Index());
        }