コード例 #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)
                {
                    var token = await UserManager.GenerateEmailConfirmationTokenAsync(user);

                    var confirmationLink = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, token = token }, Request.Scheme);

                    MailRequest mail = new MailRequest
                    {
                        Subject = "Confirm your account",
                        Body    = "Please confirm your account by clicking this link: <a href =\"" + confirmationLink + "\">link</a>",
                        ToEmail = model.Email
                    };
                    await _emailSender.SendEmailAsync(mail);

                    kupacService.InsertKupac(model.convertToKupac(user));

                    if (SignInManager.IsSignedIn(User) && User.IsInRole("Administrator"))
                    {
                        return(RedirectToAction("ListUsers", "Administration", new { area = "Admin" }));
                    }

                    return(View("SuccessfulRegistration"));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }
            model.Gradovi = gradoviService.GetGradovi().Select(a =>
                                                               new SelectListItem
            {
                Value = a.Id.ToString(),
                Text  = a.Ime
            }).ToList();
            return(View(model));
        }
コード例 #2
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, PhoneNumber = model.FullPhone
                };
                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);

                    MailRequest mail = new MailRequest
                    {
                        Subject = "Confirm your account",
                        Body    = "Please confirm your account by clicking this link: <a href =\"" + callbackUrl + "\">link</a>",
                        ToEmail = model.Email
                    };
                    await _emailSender.SendEmailAsync(mail);

                    //await _signInManager.SignInAsync(user, isPersistent: false);

                    //dodao sam insertkupac servis i ubacio konverter u viewmodel radi vece preglednosti koda
                    _kupacService.InsertKupac(model.convertToKupac(user));

                    _logger.LogInformation(3, "User created a new account with password.");
                    return(View("ThankYou"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            model.Gradovi = _gradoviService.GetGradovi().Select(a =>
                                                                new SelectListItem
            {
                Value = a.Id.ToString(),
                Text  = a.Naziv
            }).ToList();
            return(View(model));
        }