// GET: Registration public ActionResult Index() { var baseModel = new CustomerRegistrationModel(); SetUpNavItems(baseModel); return(View(baseModel)); }
public async Task <Object> CustomerRegistration(CustomerRegistrationModel model) { var usr = await _userManager.FindByEmailAsync(model.Email); if (usr != null) { return(BadRequest(new { message = "User Already Exists" })); } var Role = "Customer"; var applicationUser = new ApplicationUserModel() { UserName = model.Email, Email = model.Email }; ProfileModel profile = new ProfileModel() { Email = model.Email, Name = "Name", PhoneNumber = "+880100000000000" }; try { var result = await _userManager.CreateAsync(applicationUser, model.Password); await _userManager.AddToRoleAsync(applicationUser, Role); _context.Profile.Add(profile); await _context.SaveChangesAsync(); if (result.Succeeded) { var code = await _userManager.GenerateEmailConfirmationTokenAsync(applicationUser); var callbackUrl = Url.Action(("ConfirmEmail"), "User", new { userId = applicationUser.Id, code = code }, Request.Scheme); EmailSender emailSender = new EmailSender(); emailSender.sendVerificationEmail(model.Email, callbackUrl); } return(Ok(result)); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> Register(int Id = -1) { CustomerRegistrationModel customerRegistrationModel = new CustomerRegistrationModel(); // When we want to diplay a new empty form (new customer) if (Id == -1) { customerRegistrationModel.IsOld = false; } else { string response = await client.GetStringAsync(webApiUri + "/" + Id); Customer customer = JsonConvert.DeserializeObject <Customer>(response); customerRegistrationModel.Customer = customer; customerRegistrationModel.IsOld = true; } return(View(customerRegistrationModel)); }
public async Task <IActionResult> Register(CustomerRegistrationModel customerRegistrationModel) { // add new customer to database Boolean success; Guid newGuid = Guid.NewGuid(); if (customerRegistrationModel.IsOld) { success = await shopRepository.AddOldCustomerAsync(new OldCustomer() { FirstName = customerRegistrationModel.Customer.FirstName, MiddleName = customerRegistrationModel.Customer.MiddleName, LastName = customerRegistrationModel.Customer.LastName, OldDbId = customerRegistrationModel.Customer.Id, PhoneNumber = customerRegistrationModel.Customer.PhoneNumber, Address = customerRegistrationModel.Customer.Address, City = customerRegistrationModel.Customer.City, PostalCode = customerRegistrationModel.Customer.PostalCode, ExposeId = newGuid }); } else { customerRegistrationModel.Customer.ExposeId = newGuid; success = await shopRepository.AddCustomerAsync(customerRegistrationModel.Customer); } if (success) { return(RedirectToAction(nameof(Index), "Order", new { Id = newGuid })); } else { return(View(customerRegistrationModel)); } }
public ActionResult RenderSignUpForm(CustomerRegistrationModel model, string theme) { return(View(PathHelper.GetThemePartialViewPath(theme, "SignInSignUp"))); }
public async Task <ActionResult> Register(CustomerRegistrationModel model) { var cryptionHelper = new FrostAura.Dynamics.Core.Helpers.FaCryptographyHelper(); if (ModelState.IsValid) { var existingUser = WeedHackersContext.Users.FirstOrDefault(u => u.Email == model.RegistringUser.Email); if (existingUser != null) { ModelState.AddModelError("Email", "Email already registered"); FlashMessage.Danger("{0} is already registered. Please use a different valid email address to register", model.RegistringUser.Email); } var User = new User { Name = model.RegistringUser.Name, Surname = model.RegistringUser.Surname, Email = model.RegistringUser.Email, Password = cryptionHelper.HashString(model.RegistringUser.Password), PhoneNumber = model.RegistringUser.PhoneNumber, Deleted = false, Timestamp = DateTime.Now, SuperAdmin = false }; WeedHackersContext.Users.Add(User); var Customer = new WeedHackers_Data.Entities.Customer { Id = User.Id, Address = model.RegistringCustomer.Address, CustomerTypeId = model.RegistringCustomer.CustomerTypeId, EmailVerified = false }; WeedHackersContext.Customers.Add(Customer); await WeedHackersContext.SaveChangesAsync(); var userContext = await WeedHackersContext .Users .Include(u => u.Customer.CustomerType) .Include(u => u.Customer) .SingleOrDefaultAsync(u => u.Id == model.RegistringUser.Id); // Create the session var session = new SessionModel { Identifier = Guid.NewGuid(), // Session unique identifier (This gets sent to the client) User = userContext, // The mandatory user object a session belongs to ExpiryTime = DateTime.Now.AddMinutes(20) // Session valid for 20 minutes }; // Store the session on the server (As opposed to the database) MvcApplication.Sessions[session.Identifier.ToString()] = session; // Pass the session to the client via cookies (like before) var sessionCookie = new HttpCookie("WeedHackersSession") { Value = session.Identifier.ToString(), Expires = session.ExpiryTime, HttpOnly = true }; Response.Cookies.Add(sessionCookie); //var userContext = (User)ViewBag.UserContext; FlashMessage.Confirmation("Registration Successful!", "Welcome to WeedHackers {0}", model.RegistringUser.Name); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Please fill in all fields and try again"); FlashMessage.Danger("Error", "Please fill in all fields and try again"); return(View("Index", model)); } }