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 JsonResult GetChallenge()
        {
            ServerRegisterResponse serverRegisterResponse = _memeberShipService.GenerateServerChallenge(HttpContext.User.Identity.Name);
            CompleteRegisterModel  registerModel          = new CompleteRegisterModel
            {
                UserName  = HttpContext.User.Identity.Name,
                AppId     = serverRegisterResponse.AppId,
                Challenge = serverRegisterResponse.Challenge,
                Version   = serverRegisterResponse.Version
            };

            JsonResult result = new JsonResult
            {
                Data = registerModel
            };

            return(result);
        }
Exemplo n.º 3
0
        public JsonResult GetChallenge(string username)
        {
            ServerRegisterResponse serverRegisterResponse = _memeberShipService.GenerateServerChallenge(username);
            CompleteRegisterModel  registerModel          = new CompleteRegisterModel
            {
                UserName  = username,
                AppId     = serverRegisterResponse.AppId,
                Challenge = serverRegisterResponse.Challenge,
                Version   = serverRegisterResponse.Version
            };

            JsonResult result = new JsonResult
            {
                Data = registerModel
            };

            return(result);
        }
Exemplo n.º 4
0
        public ActionResult BeginRegister([FromBody] RegisterModel value)
        {
            if (_memeberShipService.IsUserRegistered(value.UserName))
            {
                ModelState.AddModelError("CustomError", "User is already registered.");
                return(View("Register", value));
            }

            if (!string.IsNullOrWhiteSpace(value.Password) &&
                !string.IsNullOrWhiteSpace(value.UserName) &&
                value.Password.Equals(value.ConfirmPassword))
            {
                try
                {
                    _memeberShipService.SaveNewUser(value.UserName, value.Password);
                    ServerRegisterResponse serverRegisterResponse = _memeberShipService.GenerateServerChallenge(value.UserName.Trim());
                    CompleteRegisterModel  registerModel          = new CompleteRegisterModel
                    {
                        UserName  = value.UserName,
                        AppId     = serverRegisterResponse.AppId,
                        Challenge = serverRegisterResponse.Challenge,
                        Version   = serverRegisterResponse.Version
                    };

                    return(View("FinishRegister", registerModel));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    ModelState.AddModelError("CustomError", e.Message);

                    return(View("Register", value));
                }
            }

            ModelState.AddModelError("CustomError", "invalid input");
            return(View("Register", value));
        }