public async Task<ActionResult> 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)
                {
                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    
                    // 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.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

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

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemple #2
0
        public async Task<ActionResult> 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)
                {
                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    
                    // アカウント確認とパスワード リセットを有効にする方法の詳細については、http://go.microsoft.com/fwlink/?LinkID=320771 を参照してください
                    // このリンクを含む電子メールを送信します
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "アカウントの確認", "このリンクをクリックすることによってアカウントを確認してください <a href=\"" + callbackUrl + "\">こちら</a>");

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

            // ここで問題が発生した場合はフォームを再表示します
            return View(model);
        }
        public async Task<ActionResult> 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)
                {
                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    
                    // Para obtener más información sobre cómo habilitar la confirmación de cuenta y el restablecimiento de contraseña, visite http://go.microsoft.com/fwlink/?LinkID=320771
                    // Enviar correo electrónico con este vínculo
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirmar cuenta", "Para confirmar la cuenta, haga clic <a href=\"" + callbackUrl + "\">aquí</a>");

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

            // Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario
            return View(model);
        }
        public async Task<ActionResult> 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)
                {
                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    
                    // 如需如何啟用帳戶確認和密碼重設的詳細資訊,請造訪 http://go.microsoft.com/fwlink/?LinkID=320771
                    // 傳送包含此連結的電子郵件
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "確認您的帳戶", "請按一下此連結確認您的帳戶 <a href=\"" + callbackUrl + "\">這裏</a>");

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

            // 如果執行到這裡,發生某項失敗,則重新顯示表單
            return View(model);
        }
        public async Task<ActionResult> RegisterPromotor(RegisterViewModel model)
        {
            CuentaUsuario cue = null;
            cue = db.CuentaUsuario.Find(model.Email);
            if (cue != null)
            {
                TempData["MessageErrorPromotor"] = "Ya existe una cuenta con ese correo";
                return RedirectToAction("Index", "Empleado");
            }
            List<CuentaUsuario> lcu = db.CuentaUsuario.Where(c => c.tipoDoc == model.tipoDoc && c.codDoc == model.codDoc).ToList();
            if (lcu == null || lcu.Count > 0)
            {
                TempData["MessageErrorPromotor"] = "Ya existe un cuenta registrada con ese DNI";
                return RedirectToAction("Index", "Empleado");
            }
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var currentUser = UserManager.FindByName(user.UserName);
                    UserManager.AddToRole(user.Id, "Promotor");
                    CuentaUsuario cuentausuario = new CuentaUsuario();

                    cuentausuario.correo = model.Email;
                    cuentausuario.apellido = model.apellido;
                    cuentausuario.codDoc = model.codDoc;
                    cuentausuario.codPerfil = 3;
                    //cuentausuario.contrasena = user.PasswordHash;
                    cuentausuario.direccion = model.direccion;
                    cuentausuario.estado = true;
                    cuentausuario.fechaNac = model.fechaNac;
                    cuentausuario.nombre = model.nombre;
                    cuentausuario.puntos = 0;
                    cuentausuario.sexo = model.sexo;
                    cuentausuario.telefono = model.telefono;
                    cuentausuario.telMovil = model.telMovil;
                    cuentausuario.tipoDoc = model.tipoDoc;
                    cuentausuario.usuario = model.Email;
                    db.CuentaUsuario.Add(cuentausuario);
                    db.SaveChanges();
                    // 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.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    return RedirectToAction("Index", "Empleado");
                    //return View("~/Views/Home/Index.cshtml");
                }
                AddErrors(result);
            }
            // If we got this far, something failed, redisplay form
            return RedirectToAction("Index", "Empleado");
        }
        public async Task<ActionResult> RegisterClient(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                int errorr = 0;
                if (model.tipoDoc == 1)
                {
                    if (model.codDoc.Length != 8)
                    {
                        ModelState.AddModelError("codDoc", "El DNI debe tener 8 dígitos");
                        errorr = 1;
                    }
                    List<CuentaUsuario> lcu = db.CuentaUsuario.Where(c => c.tipoDoc == model.tipoDoc && c.codDoc == model.codDoc).ToList();
                    if (lcu.Count > 0)
                    {
                        ModelState.AddModelError("codDoc", "DNI ya utilizado");
                        errorr = 1;
                    }
                    if (model.fechaNac > DateTime.Today || model.fechaNac < Convert.ToDateTime("01/01/1900"))
                    {
                        ModelState.AddModelError("fechaNac", "La fecha con rango inválido");
                        errorr = 1;
                    }
                }
                else
                {
                    if (model.codDoc.Length != 12)
                    {
                        ModelState.AddModelError("codDoc", "El Pasaporte debe tener 12 dígitos");
                        errorr = 1;
                    }
                    List<CuentaUsuario> lcu = db.CuentaUsuario.Where(c => c.tipoDoc == model.tipoDoc && c.codDoc == model.codDoc).ToList();
                    if (lcu.Count > 0)
                    {
                        ModelState.AddModelError("codDoc", "Pasaporte ya utilizado");
                        errorr = 1;
                    }
                    if (model.fechaNac > DateTime.Today || model.fechaNac < Convert.ToDateTime("01/01/1900"))
                    {
                        ModelState.AddModelError("fechaNac", "La fecha con rango inválido");
                        errorr = 1;
                    }
                }

                if (errorr != 1)
                {
                    var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                    var result = await UserManager.CreateAsync(user, model.Password);
                    if (result.Succeeded)
                    {
                        var currentUser = UserManager.FindByName(user.UserName);
                        UserManager.AddToRole(user.Id, "Cliente");
                        CuentaUsuario cuentausuario = new CuentaUsuario();

                        cuentausuario.correo = model.Email;
                        cuentausuario.apellido = model.apellido;
                        cuentausuario.codDoc = model.codDoc;
                        cuentausuario.codPerfil = 1;
                        cuentausuario.contrasena = model.Password;
                        cuentausuario.direccion = model.direccion;
                        cuentausuario.estado = true;
                        cuentausuario.fechaNac = model.fechaNac;
                        cuentausuario.nombre = model.nombre;
                        cuentausuario.puntos = 0;
                        cuentausuario.sexo = model.sexo;
                        cuentausuario.telefono = model.telefono;
                        cuentausuario.telMovil = model.telMovil;
                        cuentausuario.tipoDoc = model.tipoDoc;
                        cuentausuario.usuario = model.Email;

                        db.CuentaUsuario.Add(cuentausuario);
                        db.SaveChanges();
                        Session["UsuarioLogueado"] = cuentausuario;
                        EmailController.EnviarCorreoRegistro(model.Email);
                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                        // 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.GenerateEmailConfirmationTokenAsync(user.Id);
                        // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                        TempData["tipo"] = "alert alert-success";
                        TempData["message"] = "Registro Exitoso!";
                        return RedirectToAction("Index", "Home");
                        //return View("~/Views/Home/Index.cshtml");
                    }

                    foreach (var error in result.Errors)
                    {
                        if (!error.Contains("nombre"))
                            ModelState.AddModelError("", error);
                    }
                }
                else
                    return View(model);

            }
            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public async Task<ActionResult> 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)
                {
                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    
                    // Дополнительные сведения о том, как включить подтверждение учетной записи и сброс пароля, см. по адресу: http://go.microsoft.com/fwlink/?LinkID=320771
                    // Отправка сообщения электронной почты с этой ссылкой
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Подтверждение учетной записи", "Подтвердите вашу учетную запись, щелкнув <a href=\"" + callbackUrl + "\">здесь</a>");

                    return RedirectToAction("Index", "Genre");
                }
                AddErrors(result);
            }

            // Появление этого сообщения означает наличие ошибки; повторное отображение формы
            return View(model);
        }
Exemple #8
0
        public async Task<IActionResult> Register(RegisterViewModel model)
        {
            EnsureDatabaseCreated(_applicationDbContext);
            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: Context.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);
                    return RedirectToAction(nameof(HomeController.Index), "Home");
                }
                AddErrors(result);
            }

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