コード例 #1
0
        public ActionResult Register(UserViewModel user)
        {
            if (ModelState.IsValid && UserValidate(user))
            {
                var hash = new Helpers.Cript();
                user.Password = hash.GenerateSHA512String(user.Password);
                var userModel = Mapper.Map <UserViewModel, User>(user);
                _userAppService.Add(userModel);

                return(RedirectToAction("Index", "Home"));
            }

            return(View(user));
        }
コード例 #2
0
        public ActionResult Login(UserLogin user)
        {
            var hash = new Helpers.Cript();

            var authenticatedUser = _userAppService.Login(user.UserName, hash.GenerateSHA512String(user.Password));

            if (authenticatedUser != null)
            {
                var userAuth = PopuleUserLoginAuth(authenticatedUser);
                context.SetAuthenticationToken(authenticatedUser.Name.ToString(), false, userAuth);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Usuário ou senha inválido");
            }

            return(View(user));
        }