public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var userProfile = new UserProfile { EmailAddress = model.Email, City = model.City, FirstName = model.FirstName, LastName = model.LastName, TelephoneNr = model.TelephoneNr }; // ONLY FOR TESTING PURPOSE!!! MADE BY LUKA var userToDelete = _userManager.Users.FirstOrDefault(); if (!(userToDelete is null)) { var entity = _context.UserProfiles.SingleOrDefault(u => u.EmailAddress == userToDelete.Email); if (!(entity is null)) { _context.UserProfiles.Remove(entity); _context.SaveChanges(); } await _userManager.DeleteAsync(userToDelete); } var profile = _context.UserProfiles.Add(userProfile); _context.SaveChanges(); var user = new ApplicationUser { UserName = model.Email, Email = model.Email, UserProfileId = profile.Entity.Id }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await _userManager.AddToRoleAsync(user, Constants.ROLE_USER); // For more information on how to enable account confirmaion and password reset please visit https://go.microsoft.com/fwlink/?LinkID=532713 // Send an email with this link var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Action(nameof(ConfirmEmail), "Account", new { userId = user.Id, code }, protocol: HttpContext.Request.Scheme); _emailSender.Send(new EmailMessage { Content = $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>", Subject = "Confirm your account", ToAddresses = new List <EmailAddress> { new EmailAddress { Address = model.Email } }, FromAddresses = new List <EmailAddress> { new EmailAddress { Address = AdminMail } } }); //await _signInManager.SignInAsync(user, isPersistent: false); _logger.LogInformation(3, "User created a new account with password."); return(RedirectToLocal(returnUrl)); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
private static void SeedEnumerations(ISAContext context) { for (var i = 0; i < 3; i++) { var dummyUser = new UserProfile { City = $"City{i}", EmailAddress = $"test{i}@test.mail", FirstName = $"FirstName{i}", LastName = $"LastName{i}", TelephoneNr = $"{i}{i}{i}{i}{i}{i}{i}" }; if (context.UserProfiles.All(u => u.EmailAddress != dummyUser.EmailAddress)) { context.UserProfiles.Add(dummyUser); } } context.SaveChanges(); var twoUsers = context.UserProfiles.Take(2); var firstUser = twoUsers.First(); var secondUser = twoUsers.Skip(1).Take(1).First(); if (context.FriendRequests.All(r => r.SenderId != firstUser.Id && r.ReceiverId != secondUser.Id)) { context.FriendRequests.Add(new FriendRequest { Sender = firstUser, Receiver = secondUser, Status = FriendshipStatus.Pending }); } var projection = new Projection { Description = "desc", Duration = new System.TimeSpan(2, 0, 0), Name = "Projection 1", Type = ProjectionTypeEnum.Movie }; var rep = new Repertoire { Projections = new List <Projection> { projection } }; var cinema = new Cinema { Address = "Address1", Name = "Cinema1", Type = DataAccess.Models.Enumerations.CinemaTypeEnum.Cinema, Repertoires = new List <Repertoire> { rep } }; var theater = new Theater() { Name = "Pozoriste Mladih" }; var funZone = new FunZone() { Cinema = cinema }; var funZoneTheater = new FunZone() { Theater = theater }; var starWarsProps = new ThematicProps() { FunZone = funZone, Description = "An almost brand new thematic prop for star wars! Used couple of times!", Image = @"~/images/sw1.jpg", Price = 1000, Name = "Star wars gear", Publisher = firstUser }; var starTreckProp = new ThematicProps() { FunZone = funZone, Description = "An almost brand new thematic prop for star treck! Used couple of times!", Image = @"~/images/st1.jpg", Price = 2000, Name = "Star treck terminal" }; var lotrProp = new ThematicProps() { FunZone = funZone, Description = "An almost brand new thematic prop for LOTR! Used couple of times!", Image = @"~/images/lordOfRings_ring.jpg", Price = 200000, Name = "LOTR ring on sales" }; context.ThematicProps.Add(starWarsProps); context.ThematicProps.Add(starTreckProp); context.ThematicProps.Add(lotrProp); context.Projections.Add(projection); context.Repertoires.Add(rep); context.Cinemas.Add(cinema); context.FunZone.Add(funZone); context.FunZone.Add(funZoneTheater); context.SaveChanges(); }
private void Save() { _context.SaveChanges(); }
public static void SeedUsers(UserManager <ApplicationUser> userManager, ISAContext context) { foreach (var role in Constants.SYSTEM_ROLES) { var username = $"{role.ToLower()}"; var email = $"{username}@test.mail"; var pw = $"{char.ToUpper(username[0])}{username.Substring(1)}2018!"; if (userManager.FindByNameAsync(email).Result == null) { ApplicationUser user = new ApplicationUser { UserName = email, Email = email, }; IdentityResult result = userManager.CreateAsync(user, pw).Result; if (result.Succeeded) { //add roles to user userManager.AddToRoleAsync(user, role).Wait(); //get activation code var code = userManager.GenerateEmailConfirmationTokenAsync(user).Result; //activate user userManager.ConfirmEmailAsync(user, code).Wait(); context.UserProfiles.Add(new UserProfile { City = $"{username} city", EmailAddress = email, FirstName = username, LastName = username, TelephoneNr = email }); } } } context.SaveChanges(); foreach (var role in Constants.SYSTEM_ROLES) { var username = $"{role.ToLower()}"; var email = $"{username}@test.mail"; var up = context.UserProfiles.FirstOrDefault(x => x.EmailAddress == email); if (!(up is null)) { var ur = userManager.FindByNameAsync(email).Result; if (ur != null) { ur.UserProfileId = up.Id; var r = userManager.UpdateAsync(ur).Result; } if (up.Id == 4) { context.FriendRequests.AddRange(new List <FriendRequest> { new FriendRequest { SenderId = 4, Status = FriendshipStatus.Accepted, ReceiverId = 1 }, new FriendRequest { SenderId = 4, Status = FriendshipStatus.Accepted, ReceiverId = 2, }, new FriendRequest { SenderId = 4, Status = FriendshipStatus.Accepted, ReceiverId = 3, }, }); context.SaveChanges(); } } } }