public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { //var user = new ApplicationUser { UserName = model.FirstName+"9"+model.LastName, Email = model.Email,FirstName = model.FirstName, LastName = model.LastName}; var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl); await _categories.AddObject(CategoryObjectFactory.Create(Guid.NewGuid().ToString(), user.Id, "Uncategorized")); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation("User created a new account with password."); return(RedirectToLocal(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
//[ValidateAntiForgeryToken] public async Task <IActionResult> CreateCategory([Bind(properties)] CategoryViewModel c) { if (!ModelState.IsValid) { return(View(c)); } c.ID = Guid.NewGuid().ToString(); var user = await GetCurrentUser(); c.UserID = user.Id; var o = CategoryObjectFactory.Create(c.ID, c.UserID, c.CategoryName, c.ValidFrom, c.ValidTo); await categories.AddObject(o); return(RedirectToAction("Index")); }