public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName = model.Email,
                    Email    = model.Email,
                    City     = model.City
                };
                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);

                    _logger.Log(LogLevel.Warning, confirmationLink);

                    if (_signInManager.IsSignedIn(User) && User.IsInRole("Admin"))
                    {
                        return(RedirectToAction("ListUsers", "Administration"));
                    }
                    //await _signInManager.SignInAsync(user, isPersistent:false);
                    //return RedirectToAction("Index", "Home");
                    ViewBag.ErrorTitle   = "Registration successful";
                    ViewBag.ErrorMessage = "Before you can Login, please confirm your " +
                                           "email, by clicking on the confirmation link we have emailed you";
                    return(View("Error"));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }
            return(View(model));
        }
Пример #2
0
        public void Exception(Exception ex)
        {
            var extra = _loggerSettings.ExceptionDetailed ? ToDictionary(ex.Data) : null;
            var state = PrepareStateObject(BuildProperties(extra), null);

            _logger.Log(LogLevel.Error, _eventId, state, ex, ExceptionMessageGetter);
        }
 public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
 {
     instance.Log <TState>(logLevel: logLevel, eventId: eventId, state: state, exception: exception, formatter: formatter);
 }