예제 #1
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // Create a profile, password, and link the local login before signing in the user
                    User user = new User(model.UserName);
                    if (await Users.Create(user) &&
                        await Secrets.Create(new UserSecret(model.UserName, model.Password)) &&
                        await Logins.Add(new UserLogin(user.Id, IdentityConfig.LocalLoginProvider, model.UserName)))
                    {
                        await SignIn(user.Id, isPersistent: false);
                        return RedirectToAction("Index", "Home");
                    }
                    else
                    {
                        ModelState.AddModelError(String.Empty, "Failed to create login for: " + model.UserName);
                    }
                }
                catch (DbEntityValidationException e)
                {
                    ModelState.AddModelError("", e.EntityValidationErrors.First().ValidationErrors.First().ErrorMessage);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
예제 #2
0
        public ActionResult Index(RegisterViewModel model)
        {
            if (ModelState.IsValid)
                if ((int) Session["UserId"] > 0)
                {
                    var customer = new Customer
                        {
                            Id = (int) Session["UserId"],
                            Email = model.Email,
                            FirstName = model.FirstName,
                            LastName = model.LastName,
                            Password = model.Password,
                            Sex = string.IsNullOrEmpty(model.Sex) ? "" : model.Sex,
                            Phone = string.IsNullOrEmpty(model.Phone) ? "" : model.Phone,
                            Address = string.IsNullOrEmpty(model.Address) ? "" : model.Address
                        };

                    ViewBag.Message = _dataManager.Customers.UpdateCustomer(customer) == (int)Auxiliary.Result.OperationSuccess
                                    ? "Профиль сохранен!"
                                    : "Не удалось сохранить профиль!";
                }
                else
                    return RedirectToAction("LogIn", "Account");

            return View(model);
        }
예제 #3
0
 public ActionResult Register(RegisterViewModel model)
 {
     //Провіряємо чи користуач ввів все вірно
     if (ModelState.IsValid)
     {
         MembershipCreateStatus status = dataManager.MembershipProvider.CreateUser(model.UserName, model.Password,
                                                                                   model.Email, model.FirstName,
                                                                                   model.LastName, model.MiddleName);
         if (status == MembershipCreateStatus.Success)
             return View("Success");
         ModelState.AddModelError("", GetMembershipCreateStatusResultText(status));
     }
     return View(model);
 }
예제 #4
0
        public async Task <ActionResult> Register(Web.Models.RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                Data.Domain.User korisnik = new Data.Domain.User();
                korisnik.Email     = model.Email;
                korisnik.FirstName = model.Ime;
                korisnik.LastName  = model.Prezime;
                korisnik.Password  = model.Zaporka;
                UserServices korisnikServices = new UserServices();
                korisnikServices.SaveOrUpdate(korisnik);

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

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #5
0
        public ActionResult Index()
        {
            if (Session["UserId"] == null || (int) Session["UserId"] == -1)
                return RedirectToAction("LogIn", "Account");

            var customer = _dataManager.Customers.GetCustomerById((int)Session["UserId"]);
            if (customer == null)
                return RedirectToAction("Pity", "Error");

            var model = new RegisterViewModel
                {
                    UserName = customer.UserName,
                    Email = customer.Email,
                    ConfirmEmail = customer.Email,
                    FirstName = customer.FirstName,
                    LastName = customer.LastName,
                    Password = customer.Password,
                    ConfirmPassword = customer.Password,
                    Sex = string.IsNullOrEmpty(customer.Sex) ? "" : customer.Sex,
                    Phone = string.IsNullOrEmpty(customer.Phone) ? "" : customer.Phone,
                    Address = string.IsNullOrEmpty(customer.Address) ? "" : customer.Address
                };
            return View(model);
        }
예제 #6
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);
        }
예제 #7
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);
                    
                    // 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);
        }
 private async Task UpdateApplicationUser(RegisterViewModel model)
 {
     var user = await UserManager.FindByIdAsync(model.Id);
     user.MiddleName = model.MiddleName;
     user.Name = model.Name;
     user.Surname = model.Surname;
     user.PhoneNumber = model.PhoneNumber;
     await AdressManager.UpdateAsync(user, model.Adress);
     var result = await UserManager.UpdateAsync(user);
 }
 private async Task<RegisterViewModel> GetRegisterModel(ApplicationUser user)
 {
     await AdressManager.GetListAdressAsync();
     var adress = user.Adress ?? new Adress { Sity = "Київ" };
     var result = new RegisterViewModel
     {
         Id = user.Id,
         Adress = adress,
         Email = user.Email,
         UserName = user.UserName,
         PhoneNumber = user.PhoneNumber,
         MiddleName = user.MiddleName,
         Name = user.Name,
         Surname = user.Surname
     };
     return result;
 }
예제 #10
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Username, 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>");
                    _securityService.AddUser(user.UserName, user.Email, string.Empty, string.Empty);
                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
예제 #11
0
 public ActionResult Register(RegisterViewModel model)
 {
     if (ModelState.IsValid)
     {
         var status = _dataManager
             .Provider.CreateUser(
                 model.UserName,
                 model.Password,
                 model.Email,
                 model.FirstName,
                 model.LastName);
         if (status == MembershipCreateStatus.Success)
             return View("Success");
         ModelState.AddModelError("", GetMembershipCreateStatusResultText(status));
     }
     return View(model);
 }
예제 #12
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("RegisterStepTwo", "Account");
                }
                AddErrors(result);
            }

            // Появление этого сообщения означает наличие ошибки; повторное отображение формы
            return View(model);
        }
예제 #13
0
        public async Task<ActionResult> Register(RegisterViewModel model, string returnUrl)
        {
            var registerValidate = string.IsNullOrEmpty(model.UserName) && string.IsNullOrEmpty(model.Email) &&
                                   string.IsNullOrEmpty(model.PhoneNumber);
            if (ModelState.IsValid && !registerValidate)
            {
                var user = new ApplicationUser
                {
                    UserName = model.UserName ?? model.Email ?? "user" + model.PhoneNumber,
                    Email = model.Email,
                    PhoneNumber = model.PhoneNumber,
                    Name = model.Name,
                    MiddleName = model.MiddleName,
                    Surname = model.Surname
                };
                var result = model.Password == null?  await UserManager.CreateAsync(user):
                    await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await AdressManager.UpdateAsync(user, model.Adress);
                    if (!RoleManager.RoleExists("Користувач"))
                        await RoleManager.CreateAsync(new ApplicationRole("Користувач"));
                    await UserManager.AddToRoleAsync(user.Id, "Користувач");
                    if (!string.IsNullOrEmpty(returnUrl))
                    {
                        ViewBag.UserId = user.Id;
                        return RedirectToLocal(returnUrl + "&userId=" + user.Id);
                    }
                    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);
            }
            if(registerValidate) ModelState.AddModelError("", "Необхідно вказати логін, телефон або емайл");
            // Появление этого сообщения означает наличие ошибки; повторное отображение формы
            return View(model);
        }
예제 #14
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.UserName, Email = model.Email };

                if (db.Users.Count() == 0)
                {
                    user.Administrator = true;
                }

                IdentityResult result;

                if (ActiveDirectoryAuthentication.IsADAuthenticationEnabled())
                {
                    if (!ActiveDirectoryAuthentication.Authenticate(model.UserName, model.Password))
                    {
                        ModelState.AddModelError("", "username or password not valid");
                        return View(model);
                    }
                    else
                    {

                        result = await UserManager.CreateAsync(user, "bazooka");
                    }
                }
                else
                {
                    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);
        }