public ActionResult Register(RegisterViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                string clientId                  = CreateGuid.NewId();
                string clientEmail               = model.UserEmail;
                string verificationCode          = SecurityStamp.EncryptSecurityStamp("Create-Account", clientId);
                var    encryptEmail              = _iEncryptData.Encrypt(model.UserEmail);
                string encryptedEmail            = encryptEmail.Item1;
                string encryptedEmailkey         = encryptEmail.Item2;
                string hashPassword              = _iPasswordService.HashPassword(model.UserPassword);
                var    encryptedVerificationCode = _iEncryptData.Encrypt(verificationCode);


                model.ClientId          = clientId;
                model.VerificationToken = encryptedVerificationCode.ToString();
                model.UserEmail         = encryptedEmail;
                model.Encryptionkey     = encryptedEmailkey;
                model.UserPassword      = hashPassword;

                _iCreateUserAccount.InsertNewMember(model);

                var callbackUrl = CallbackUrl(encryptedVerificationCode.ToString());

                SendEmail(callbackUrl, clientEmail);

                TempData["Message"] = MvcHtmlString.Create("<p class=\"alert alert-danger\">Please check your email to confirm your address.</p>");

                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception e)
            {
                TempData["Message"] = MvcHtmlString.Create("<p class=\"alert alert-danger\">" + e.Message + "</p>");

                return(RedirectToAction("Index", "Home"));
            }
        }
Beispiel #2
0
        public async Task <LoginViewModel> LoginAsync(LoginViewModel userLogin)
        {
            ValidarDadosLogin(userLogin);
            var passwordEncripty = _encryptData.Encrypt(userLogin.Password);
            var login            = await _usuarioRepository.Login(userLogin.Username, passwordEncripty);

            if (login == null)
            {
                throw new Exception("Usuário ou senha incorreto.");
            }

            var usuarioAuthentication = _mapper.Map <UsuarioAuthentication>(login);
            var token = _token.GenerateToken(usuarioAuthentication);

            login.Token = token;
            return(_mapper.Map <LoginViewModel>(login));
        }
Beispiel #3
0
        public async Task <bool> AtualizarSenha(AtualizaSenhaViewModel atualizaSenha)
        {
            if (string.IsNullOrEmpty(atualizaSenha.Token) || !_tokenService.ValidateSimpleToken(atualizaSenha.Token))
            {
                _notificationService.AddNotification("Token Inválido", "O token informado é inválido, acesse o link enviado por e-mail e tente novamente.");
                return(false);
            }

            var usuario = await _usuarioRepository.ObterUsuarioPorUsername(atualizaSenha.Username);

            string password = _encryptData.Encrypt(atualizaSenha.Senha);

            usuario.AtivarUsuario();
            usuario.AtualizarSenha(password);
            await _usuarioRepository.AtualizarAsync(usuario, usuario.Id);

            return(true);
        }