예제 #1
0
        public async Task <IActionResult> Login(LoginModelViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var authenticateResult = await _sessionProvider.Authenticate(model.Email, _hashGenerator.Generate(model.Password, true));

                if (authenticateResult.ResultMessage.MessageType != MessageType.Error)
                {
                    var userModel = new UserModel(model.Email, _hashGenerator.Generate(model.Password, true), authenticateResult.Model.SessionId);
                    _userManager.SetUser(userModel);
                    return(RedirectToLocal(returnUrl));
                }
                else
                {
                    ModelState.AddModelError(String.Empty, authenticateResult.ResultMessage.Message);
                }
            }

            return(View(model));
        }
예제 #2
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var passwordHash   = _hashGenerator.Generate(model.Password, true);
                var registerResult = await _userProvider.CreateUser(model.Email, model.Name, _hashGenerator.Generate(passwordHash, true));

                if (registerResult.ResultMessage.MessageType != MessageType.Error)
                {
                    var userModel = new UserModel(model.Email, passwordHash, registerResult.Model.SessionId);
                    _userManager.SetUser(userModel);
                    return(RedirectToLocal(returnUrl));
                }
                else
                {
                    ModelState.AddModelError(String.Empty, registerResult.ResultMessage.Message);
                }
            }

            return(View(model));
        }