public CustomerViewModel RegisterSupporter(RegisterSupporterViewModel registerSupporterViewModel)
        {
            var customer = _customerService.GetCustomerByEmail(registerSupporterViewModel.Email);

            if (customer == null)
            {
                var salt = CustomerAuthenticationExtensions.GenerateSalt();

                customer = new Customer
                {
                    Name         = registerSupporterViewModel.Name,
                    Email        = registerSupporterViewModel.Email,
                    PhoneNumber  = registerSupporterViewModel.PhoneNumber,
                    Salt         = salt,
                    Password     = CustomerAuthenticationExtensions.HashPassword(registerSupporterViewModel.Password, salt),
                    Active       = true,
                    AmbassadorId = registerSupporterViewModel.AmbassadorId,
                    CreatedOn    = DateTime.UtcNow
                };

                _customerService.InsertCustomer(customer);
            }

            return(new CustomerViewModel
            {
                Id = customer.Id,
                CustomerGuid = customer.CustomerGuid,
                Name = customer.Name,
                Email = customer.Email,
                PhoneNumber = customer.PhoneNumber,
                AmbassadorId = customer.AmbassadorId,
                Token = _jsonWebTokenService.GenerateJSONWebToken(customer)
            });
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> RegisterSupporter(RegisterSupporterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, UserRole = "Supporter"
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    await this.UserManager.AddToRoleAsync(user.Id, user.UserRole);

                    return(RedirectToAction("Create", "Supporters"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult RegisterSupporter()
        {
            RegisterSupporterViewModel viewModel = new RegisterSupporterViewModel()
            {
                UserRole = "Supporter",
            };

            return(View());
        }
Ejemplo n.º 4
0
 public CustomerViewModel RegisterSupporter([FromBody] RegisterSupporterViewModel registerSupporterViewModel)
 {
     return(_networkMarketingFactory.RegisterSupporter(registerSupporterViewModel));
 }