Esempio n. 1
0
        public async Task<IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await _userManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                    //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    //await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
                    //    "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
                    await _signInManager.SignInAsync(user, isPersistent: false);
                    _logger.LogInformation(3, "User created a new account with password.");
                    return RedirectToAction(nameof(HomeController.Index), "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Esempio n. 2
0
        public async Task<IActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl = null)
        {
            if (User.IsSignedIn())
            {
                return RedirectToAction(nameof(ManageController.Index), "Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await _signInManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await _userManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);
                    if (result.Succeeded)
                    {
                        await _signInManager.SignInAsync(user, isPersistent: false);
                        _logger.LogInformation(6, "User created an account using {Name} provider.", info.LoginProvider);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewData["ReturnUrl"] = returnUrl;
            return View(model);
        }
Esempio n. 3
0
        public async Task<string> Create(string codigo, string nome, string departamento, string email, string telemovel,  string empresaId)
        {
            
            Funcionario funcionario = new Funcionario
            {
                codigo = codigo,
                nome = nome,
                telemovel = telemovel,
                email = email.Trim(),
                empresaId = empresaId,
                activo = true
            };
            

            var dep = _context.Departamentos.Where (d => d.descricao == departamento|| " " + d.descricao == departamento);

            if (dep.Count() > 0)
                funcionario.departamentoId = dep.First().Id;
            else
                funcionario.departamentoId = 17;

            try
            {

                var user = await _userManager.FindByNameAsync(funcionario.email);

                if (user == null)
                {
                    user = new ApplicationUser { UserName = funcionario.email, Email = funcionario.email, PhoneNumber=funcionario.telemovel };
                    await _userManager.CreateAsync(user, "Meridian123456!");
                    await _userManager.AddToRoleAsync(user, "Funcionario");
                    await _userManager.AddClaimAsync(user, new Claim("Funcionario", "Allowed"));

                    funcionario.utilizadorId = user.Id;

                    var callbackUrl = "http://ferias.mit.co.mz:5000/";

                    string mensaguem = " <h4>Caro Colaborador " + funcionario.nome + " </h4> <br/>" +
                        "<p>Foi criado com sucesso o seu utilizador para a marcação de ferias Online ainda em fase de Produção/Teste.</p>" +
                        "<p><b>Utilizador: </b> " + funcionario.email + "</p> <br/>" +
                        "<p><b>Password:   </b> Meridian123456!</p> <br/>" +
                        "<p><b>Aplicação:  </b> <a href=\"" + callbackUrl + "\">" + callbackUrl + "</a> </p> <br/>" +
                        "<br/> <p> <b> Faça Login e depois seleciona o menu RH e depois Ferias e em seguida o botão editar. </b></p>";

                    var host = HttpContext.Request.Host.Value;

                    await _emailSender.SendAsync("*****@*****.**", "Não Responder", funcionario.email,"", "Aplicação de Marcação de Ferias -Em Produção / Teste",
                       mensaguem,host);
                }
                else
                {
                    await _userManager.AddToRoleAsync(user, "Funcionario");
                    await _userManager.AddClaimAsync(user, new Claim("Funcionario", "Allowed"));

                    funcionario.utilizadorId = user.Id;
                }

                var temp = _context.Funcionarios.Where(d => d.codigo == codigo && d.empresaId == empresaId);
                if (temp.Count ()== 0)
                {
                    _context.Funcionarios.Add(funcionario);
                    _context.SaveChanges();

                    return "ok";
                }
                else
                {
                    return "null";
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(String.Format("Erro ao gravar funcionario {0} - {1}"), codigo, e.Message);

                return "null";


            }


        }