public async Task<ActionResult> Create(RegisterViewModel model, ApplicationUserViewModel user, string RoleId)
        {
            if (ModelState.IsValid)
            {

                bool adminresult = await Service.RegisterUser(Mapper.Map<ApplicationUserPoco>(user), model.Password);

                if (adminresult)
                {
                    if (!String.IsNullOrEmpty(RoleId))
                    {
                        var role = await RoleManager.FindByIdAsync(RoleId);
                        var result = await UserManager.AddToRoleAsync(user.Id, role.Name);
                        if (!result.Succeeded)
                        {
                            ModelState.AddModelError("", result.Errors.First().ToString());
                            ViewBag.RoleId = new SelectList(await RoleManager.Roles.ToListAsync(), "Id", "Name");
                            return View();
                        }
                    }
                }
                else
                {
                    ViewBag.RoleId = new SelectList(RoleManager.Roles, "Id", "Name");
                    return View();
                }
                return RedirectToAction("Index");
            }
            else
            {
                ViewBag.RoleId = new SelectList(RoleManager.Roles, "Id", "Name");
                return View();
            }
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ChessUser { 
                    UserName = model.UserName,
                    Email = model.Email,
                    DisplayName = model.UserName,
                    CreateDate = DateTime.Now,
                    Rank = 1200,
                };

                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }

                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
 public async Task<IActionResult> Register (RegisterViewModel model)
 {
     try
     {
         var user = new ApplicationUser { UserName = model.Email };
         IdentityResult result = await _userManager.CreateAsync(user, model.Password);
         if (result.Succeeded)
         {
             await _signInManager.SignInAsync(user, isPersistent: false);
             return RedirectToAction("Index");
         } else
         {
             System.Diagnostics.Debug.Write(result);
         }
         return RedirectToAction(nameof(HomeController.Index), "Home");
     }
     catch (Exception ex)
     {
         //while (ex.InnerException != null)
         //{
         //    Console.WriteLine(ex);
         //    ex = ex.InnerException;
         //}
         System.Diagnostics.Debug.Write(ex);
         return View();
     }
 }
Beispiel #4
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User()
                {
                    UserName = model.UserName,
                    Email = model.Email,
                    BirthDate = model.BirthDate
                };

                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
            }
            else
            {
                EditErrorMessageConfirmPassword();
                EditErrorMessageBirthDate();
            }

            // Process model errors.
            return View(model);
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser() { UserName = model.UserName };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // Si nous sommes arrivés là, un échec s’est produit. Réafficher le formulaire
            return View(model);
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser() { UserName = model.UserName };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // Se chegamos até aqui e houver alguma falha, exiba novamente o formulário
            return View(model);
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser() { UserName = model.UserName };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // 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.UserName };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // 如果我们进行到这一步时某个地方出错,则重新显示表单
            return View(model);
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Create a local login before signing in the user
                var user = new ApplicationUser() { UserName = model.UserName, Points = 10 };
                var result = await IdentityManager.Users.CreateLocalUserAsync(user, model.Password);
                if (result.Success)
                {
                    await IdentityManager.Authentication.SignInAsync(AuthenticationManager, user.Id, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // 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()
                {
                    Firstname = model.Firstname,
                    Surname = model.Surname,
                    Email = model.Email,
                    Sex = model.Sex,
                    DateOfBirth = model.DateOfBirth
                };

                var result = await UserManager.CreateAsync(user, model.Password);
                if(result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
            }
            return RedirectToAction("Index", "Home");
        }
Beispiel #11
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            Trace.TraceInformation("Handling register request for user {0}, timezone {1}, returnUrl = {2}", model.Username, model.TimeZoneId, model.ReturnUrl);
            if (ModelState.IsValid)
            {
                var user = new GGCharityUser() { UserName = model.Username, Email = model.Email, TimeZoneId = model.TimeZoneId };
                IdentityResult result = null;
                await Data.PerformAsync(async () =>
                {
                    result = await UserManager.CreateAsync(user, model.Password);
                });

                if (result.Succeeded)
                {
                    return await PostRegistrationSignIn(model.ReturnUrl, user);
                }
                else
                {
                    AddErrors(result);
                }
            }

            Trace.TraceEvent(TraceEventType.Error, 0, "Model state invalid for registration attempt for user {0}.  Error = {1}", model.Username, String.Join(", ", ModelState));

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public async Task<ActionResult> Create(RegisterViewModel userViewModel, params string[] selectedRoles)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = userViewModel.Email, Email = userViewModel.Email };
                var adminresult = await UserManager.CreateAsync(user, userViewModel.Password);

                //Add User to the selected Roles 
                if (adminresult.Succeeded)
                {
                    if (selectedRoles != null)
                    {
                        var result = await UserManager.AddToRolesAsync(user.Id, selectedRoles);
                        if (!result.Succeeded)
                        {
                            ModelState.AddModelError("", result.Errors.First());
                            ViewBag.RoleId = new SelectList(await RoleManager.Roles.ToListAsync(), "Name", "Name");
                            return View();
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError("", adminresult.Errors.First());
                    ViewBag.RoleId = new SelectList(RoleManager.Roles, "Name", "Name");
                    return View();

                }
                return RedirectToAction("Index");
            }
            ViewBag.RoleId = new SelectList(RoleManager.Roles, "Name", "Name");
            return View();
        }
        public virtual async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email, CreatedOn = DateTime.Now, IsTrial = true };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    result = await UserManager.AddToRoleAsync(user.Id, Common.Constants.Security.Roles.User);
                    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>");


                        ViewBag.Message = "Check your email and confirm your account, you must be confirmed "
                             + "before you can log in.";

                        return View(MVC.Shared.Views.Info);
                        //return RedirectToAction("Index", "Home");
                    }
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Beispiel #14
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return this.View(model);
            }

            var randomUser = this.db.Users.FirstOrDefault();

            var user = new ApplicationUser
                           {
                               UserName = model.Email,
                               RegistrationDate = DateTime.Now,
                               EmailVerificationToken = Guid.NewGuid().ToString(),
                               IsEmailVerified = false
                           };
            var result = await this.UserManager.CreateAsync(user, model.Password);
            if (result.Succeeded)
            {
                this.UserManager.AddToRole(user.Id, "user");
                this.SendEmailConfirmation(user.UserName, user.EmailVerificationToken);

                // Add notification 
                if (randomUser == null)
                {
                    return this.RedirectToAction("RegisterStepTwo");
                }

                var importantRecorded = false;
                foreach (var notification in randomUser.Notifications)
                {
                    this.db.Notifications.Add(
                        new Notification
                            {
                                Title = notification.Title,
                                Message = notification.Message,
                                Date = notification.Date,
                                Important = !importantRecorded && notification.Important,
                                Viewed = false,
                                User = user
                            });

                    if (notification.Important)
                    {
                        importantRecorded = true;
                    }
                }

                await this.db.SaveChangesAsync();

                return this.RedirectToAction("RegisterStepTwo");
            }

            this.AddErrors(result);

            // Si nous sommes arrivés là, un échec s’est produit. Réafficher le formulaire
            return this.View(model);
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new CustomUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    var 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 this link: <a href=\"" + callbackUrl + "\">link</a>");
                    ViewBag.Link = callbackUrl;
                    return View("DisplayEmail");
                }

                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            var repository = new ParseRepository(new WebCacheProvider(HttpContext.ApplicationInstance.Context));
            model.DeviceTypes =  repository.FindDeviceTypes();
            model.Countries = repository.FindCountriesNameAndId();
            if (ModelState.IsValid)
            {
                Exception logException = default(Exception);
                var userManager = new MyMentorUserManager(repository, Session);
                try
                {
                    model.CountryOfResidenceTitle = model.Countries[model.CountryOfResidence];


                    model.ContentTypeId = WorldIsRetriverFactory.GetWorldId(HttpContext, Session);
                    model.CurrencyId = (repository.FindResidenceById(model.CountryOfResidence)).CurrencyId;
                    await userManager.RegisterUser(model);

                    var parseUser = await userManager.Login(model.UserName, model.Password, Session);

                    Mailer.SendRegistrationSuccess(parseUser);
                    model.ShowSuccessMessage = true;
                    ViewBag.TeacherSuccessMessage = Strings.GetLocalizedString(Strings.RegistrationSuccessTeacher);
                    ViewBag.TeacherSuccessMessage = string.Format(ViewBag.TeacherSuccessMessage, model.FirstName);
                    ViewBag.StudentSuccessMessage = Strings.GetLocalizedString(Strings.RegistrationSuccessStudent);
                    ViewBag.StudentSuccessMessage = string.Format(ViewBag.StudentSuccessMessage, model.FirstName);
                }
                catch (ParseException ex)
                {
                    if (ex.Code == ParseException.ErrorCode.UsernameTaken)
                    {
                        ModelState.AddModelError("UserName", MyMentorResources.userExistsInTheSystem);
                    }
                    if (ex.Code == ParseException.ErrorCode.InvalidEmailAddress)
                    {
                        ModelState.AddModelError("UserName", MyMentorResources.illegalEmailAddress);
                    }
                    logException = ex;
                }
                catch (Exception ex)
                {
                    logException = ex;
                    mLogger.Log(LogLevel.Error, ex);

                    ModelState.AddModelError("_FORM", MyMentorResources.registrationGeneralError);
                }
                finally
                {
                    userManager.Dispose();
                }

                if (logException != null)
                {
                    await ParseLogger.Log("register new user", logException.ToString());
                }
            }
            else
            {
                var isCaptchaError = ModelState["CaptchaInputText"].Errors.Count > 0;
                ViewBag.IsCaptchaError = isCaptchaError;
            }

            // 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.UserName, AvatarURL = "lfqzdhxvikwjrakejeun" };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // Появление этого сообщения означает наличие ошибки; повторное отображение формы
            return View(model);
        }
        public ActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var comprobarUsuario = _Entities.Usuario.ToList();
                foreach (var itera in comprobarUsuario)
                {
                    if (model.UserName.Equals(itera.Nombre))
                    {
                       // Console.WriteLine("el usuario ya existe");
                        return RedirectToAction("Register", "Account");
                    }

                }
                var us = new Usuario();
                us.Nombre = model.UserName;
                us.Password = model.ConfirmPassword;
                _Entities.Usuario.Add(us);
                _Entities.SaveChanges();
                //el usuario se creo satisfactoriamente hay que cambiar el

                 return RedirectToAction("Login", "Account");

            }

            // Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario
            return View(model);
        }
 public ActionResult MostrarGaleria(RegisterViewModel model)
 {
     return RedirectToAction("MostrarGaleria", "Account");
 }
Beispiel #20
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };
                IdentityResult result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: 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");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // Появление этого сообщения означает наличие ошибки; повторное отображение формы
            return View(model);
        }
Beispiel #21
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User {FNumber = model.FNumber, UserName = model.Username, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    var context = new NdksContext();
                    var userManager = new UserManager<User>(new UserStore<User>(context));

                    userManager.AddToRole(user.Id, "Student");
                    context.SaveChanges();

                    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);
        }
Beispiel #22
0
        public virtual async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser()
                {
                    UserName = model.UserName,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    Email = model.Email,
                    Active = true,
                    AccountType = model.AccountType,
                    Organization = model.Organization
                };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // 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 };
                IdentityResult result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: false);

                    // Weitere Informationen zum Aktivieren der Kontobestätigung und Kennwortzurücksetzung finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=320771".
                    // E-Mail-Nachricht mit diesem Link senden
                    // 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, "Konto bestätigen", "Bitte bestätigen Sie Ihr Konto. Klicken Sie dazu <a href=\"" + callbackUrl + "\">hier</a>");

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

            // Wurde dieser Punkt erreicht, ist ein Fehler aufgetreten; Formular erneut anzeigen.
            return View(model);
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };
                IdentityResult result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent: 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");
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        public ActionResult Register()
        {
            WorldIsRetriverFactory.GetWorldId(HttpContext, Session);

            var model = new RegisterViewModel();
            var repository = new ParseRepository(new WebCacheProvider(HttpContext.ApplicationInstance.Context));
            model.DeviceTypes =  repository.FindDeviceTypes();
            model.Countries = repository.FindCountriesNameAndId();

            ViewBag.DeviceUnSupportedText =  Strings.GetLocalizedString(Strings.UnSupportedDevice);
            return View(model);
        }