Exemple #1
0
        public async Task <ActionResult> Aprovar(int id)
        {
            var corredor = db.Corredors.Include(x => x.Corridas).Where(x => x.Id == id).FirstOrDefault();
            var user     = db.Users.Where(dado => dado.UserName == corredor.Email).FirstOrDefault();

            if (user == null)
            {
                var    passwordHash = new PasswordHasher();
                string password     = TratamentoString.CalcularMD5Hash(corredor.Email).Substring(1, 8);

                user = new ApplicationUser {
                    UserName = corredor.Email, Email = corredor.Email, TipoUsuario = TipoConta.Corredor
                };
                var result = await UserManager.CreateAsync(user, password);

                if (!result.Succeeded)
                {
                    ModelState.AddModelError("", result.Errors.ToString());
                    if (!ModelState.IsValid)
                    {
                        return(RedirectToAction("index"));
                    }
                }

                NotificaPorEmail.NotificarNovoCorredor(user.Email, "Seu cadastro na Corrida foi aprovado Seu Usuario é " + user.Email + " Sua Senha é " + password);
            }

            corredor.Aprovado        = true;
            corredor.UserId          = user.Id;
            db.Entry(corredor).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("index"));
        }
Exemple #2
0
        public async Task <ActionResult> Create(Corrida corrida)
        {
            var user = db.Users.Where(dado => dado.UserName == corrida.EmailADM).FirstOrDefault();

            if (ModelState.IsValid)
            {
                string password = "******";

                if (user == null)
                {
                    var passwordHash = new PasswordHasher();
                    password = TratamentoString.CalcularMD5Hash(corrida.EmailADM).Substring(1, 8);
                    user     = new ApplicationUser {
                        UserName = corrida.EmailADM, Email = corrida.EmailADM, TipoUsuario = TipoConta.Administrador
                    };
                    var result = await UserManager.CreateAsync(user, password);

                    if (!result.Succeeded)
                    {
                        ModelState.AddModelError("", result.Errors.ToString());
                        if (!ModelState.IsValid)
                        {
                            return(View(corrida));
                        }
                    }
                }

                var link = "http://www.corridadepeso.com.br/corrida/link/" + TratamentoString.CalcularMD5Hash(corrida.Titulo);
                corrida.UserId = user.Id;
                corrida.Link   = TratamentoString.CalcularMD5Hash(corrida.Titulo);
                db.Corridas.Add(corrida);
                db.SaveChanges();
                NotificaPorEmail.NotificarNovoCadastro(user.Email, password, user.Email, link);
                return(RedirectToAction("CorridasPublicas"));
            }

            return(View(corrida));
        }
Exemple #3
0
        public async Task <ActionResult> ForgotPassword(ForgotPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(model.Email);

                if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
                {
                    string password = TratamentoString.CalcularMD5Hash(model.Email).Substring(1, 8);
                    // Don't reveal that the user does not exist or is not confirmed
                    return(View("ForgotPasswordConfirmation"));
                }

                // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                // Send an email with this link
                // string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
                // var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                // await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");
                // return RedirectToAction("ForgotPasswordConfirmation", "Account");
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }