Exemplo n.º 1
0
        public IActionResult Register(string returnUrl)
        {
            var vm = new RegisterInputModel {
                ReturnUrl = returnUrl
            };

            return(View(vm));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Register(RegisterInputModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user = new ApplicationUser
                {
                    UserName    = model.Email,
                    Email       = model.Email,
                    Address     = model.Address,
                    Name        = model.Name,
                    PhoneNumber = model.PhoneNumber,
                    Role        = SD.ROLE_CUSTOMER,
                    CreatedAt   = DateTime.Now,
                };

                var createUserResult = await _userManager.CreateAsync(user, model.Password);

                if (createUserResult.Succeeded)
                {
                    await _userManager.AddToRoleAsync(user, user.Role);

                    user.CreatedBy = user.Id;
                    await _userManager.UpdateAsync(user);

                    return(await Login(new LoginInputModel
                    {
                        Username = model.Email,
                        Password = model.Password,
                        RememberLogin = false,
                        ReturnUrl = model.ReturnUrl
                    }, "login"));
                }

                ModelState.AddModelError(string.Empty, createUserResult.Errors.First().Description);
            }
            return(View(model));
        }