Exemplo n.º 1
0
        public ActionResult BeginLogin(BeginLoginModel model)
        {
            if ((string.IsNullOrWhiteSpace(model.UserName) || string.IsNullOrWhiteSpace(model.Password)) ||
                (!_memeberShipService.IsUserRegistered(model.UserName.Trim()) &&
                 !_memeberShipService.IsValidUserNameAndPassword(model.UserName.Trim(), model.Password.Trim())))
            {
                // If we got this far, something failed, redisplay form
                ModelState.AddModelError("CustomError", "User has not been registered");
                return(View("Login", model));
            }

            try
            {
                ServerChallenge serverChallenge = _memeberShipService.GenerateServerChallenge(model.UserName.Trim());

                CompleteLoginModel loginModel = new CompleteLoginModel
                {
                    AppId     = serverChallenge.AppId,
                    KeyHandle = serverChallenge.KeyHandle,
                    Version   = serverChallenge.Version,
                    Challenge = serverChallenge.Challenge,
                    UserName  = model.UserName.Trim()
                };
                return(View("FinishLogin", loginModel));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            ModelState.AddModelError("CustomError", "User has not been registered");
            return(View("Login", model));
        }
Exemplo n.º 2
0
        public ActionResult BeginLogin(BeginLoginModel model)
        {
            if ((string.IsNullOrWhiteSpace(model.Password)) ||
                !_memeberShipService.IsUserRegistered(model.UserName.Trim()))
            {
                // If we got this far, something failed, redisplay form
                ModelState.AddModelError("CustomError", "User has not been registered.");
                return(View("Login", model));
            }

            if (!_memeberShipService.IsValidUserNameAndPassword(model.UserName.Trim(), model.Password.Trim()))
            {
                ModelState.AddModelError("CustomError", "User/Password is not invalid.");
                return(View("Login", model));
            }

            try
            {
                List <ServerChallenge> serverChallenge = _memeberShipService.GenerateServerChallenges(model.UserName.Trim());

                if (serverChallenge == null || serverChallenge.Count == 0)
                {
                    throw new Exception("No server challenges were generated.");
                }

                var challenges = JsonConvert.SerializeObject(serverChallenge);
                CompleteLoginModel loginModel = new CompleteLoginModel
                {
                    AppId      = serverChallenge.First().appId,
                    Version    = serverChallenge.First().version,
                    UserName   = model.UserName.Trim(),
                    Challenges = challenges
                };
                return(View("FinishLogin", loginModel));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);

                ModelState.AddModelError("CustomError", e.Message);
                return(View("Login", model));
            }
        }