public async Task <IActionResult> CreateAdmin(ApplicationUserRegisterDto model)
        {
            var user = new ApplicationUser
            {
                Email     = model.Email,
                UserName  = model.Email,
                Nombres   = model.Nombres,
                Apellidos = model.Apellidos,
                IdCliente = null
            };
            await _userManager.CreateAsync(user, model.Password);

            var check = await _userManager.CheckPasswordAsync(user, model.Password);

            if (check)
            {
                //significa que se creo el usuario, y su contraseña es valida:
                await _userManager.AddToRoleAsync(user, RoleHelper.Admin);

                return(Ok());
            }
            else
            {
                return(BadRequest("No se pudo crear el usuario."));
            }
        }
Пример #2
0
        public async Task <IActionResult> Login(ApplicationUserRegisterDto model)
        {
            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user != null)
            {
                var check = await _signInManager.CheckPasswordSignInAsync(user, model.Password, false);

                if (check.Succeeded)
                {
                    return(Ok(
                               await GenerateToken(user)
                               ));
                }
            }
            return(BadRequest("Acceso no valido al sistema !!!"));
        }
        public async Task <IActionResult> Create(ApplicationUserRegisterDto model)
        {
            var user = new ApplicationUser
            {
                Email     = model.Email,
                UserName  = model.Email,
                FirstName = model.FirstName,
                LastName  = model.LastName
            };

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

            if (!result.Succeeded)
            {
                throw new Exception("No se pudo crea el usuario.");
            }

            return(Ok());
        }
Пример #4
0
        public async Task <IActionResult> Create(ApplicationUserRegisterDto model)
        {
            //Con esta funcion se puede crear usuarios, es aqui donde definimos si el usuario es user o admin
            var user = new ApplicationUser
            {
                Email     = model.Email,
                UserName  = model.Email,
                FirstName = model.FirstName,
                LastName  = model.LastName,
            };
            //El createAsync directamente encripta el password(solito)
            var result = await _userManager.CreateAsync(user, model.Password);

            //A base del email definimos si el usuario va a ser user o admin:
            string userRole;

            if (model.Email.EndsWith("foodyeah.com"))
            {
                userRole = RoleHelper.Admin;
                _customerService.Create(new CustomerCreateDto {
                    CustomerName = user.FirstName, CustomerLastName = user.LastName, Customer_CategoryId = 1, CustomerAge = 0, Email = user.Email
                });
            }
            else
            {
                userRole = RoleHelper.User;
                _customerService.Create(new CustomerCreateDto {
                    CustomerName = user.FirstName, CustomerLastName = user.LastName, Customer_CategoryId = 2, CustomerAge = 0, Email = user.Email
                });
                var target = _customerService.GetByEmail(user.Email);

                _locService.CreateLOC(new CreateLOCDto {
                    CustomerId = target.CustomerId, TotalLineOfCredit = 1000, Rate = 10, TypeRate = (TypeRate)1
                });
            }
            var DefaultRole = await _userManager.AddToRoleAsync(user, userRole);

            if (!result.Succeeded)
            {
                throw new Exception("No se pudo crear el usuario");
            }
            return(Ok());
        }
Пример #5
0
        public async Task <IActionResult> Create(ApplicationUserRegisterDto model)
        {
            var user = new ApplicationUser
            {
                Email    = model.Email,
                UserName = model.Email
            };

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

            await _userManager.AddToRoleAsync(user, RoleHelper.Ciudadano);

            if (!result.Succeeded)
            {
                throw new Exception("No se pudo crear el usuario.");
            }

            return(Ok());
        }
Пример #6
0
        public async Task <IActionResult> Create(ApplicationUserRegisterDto model)
        {
            var user = new ApplicationUser
            {
                Email     = model.Email,
                UserName  = model.Email,
                FirstName = model.FirstName,
                LastName  = model.LastName,
            };

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

            await _userManager.AddToRoleAsync(user, RoleHelper.Seller);

            if (!result.Succeeded)
            {
                return(BadRequest("No se pudo crear el usuario."));
            }
            return(Ok());
        }
        public async Task <IActionResult> CreateAdmin(ApplicationUserRegisterDto model)
        {
            var user = new ApplicationUser
            {
                Email     = model.Email,
                UserName  = model.Email,
                FirstName = model.FirstName,
                LastName  = model.LastName,
            };
            //El createAsync directamente encripta el password(solito)
            var result = await _userManager.CreateAsync(user, model.Password);

            var DefaultRole = await _userManager.AddToRoleAsync(user, "Admin");

            if (!result.Succeeded)
            {
                throw new Exception("No se pudo crear el usuario");
            }
            return(Ok());
        }
Пример #8
0
        public async Task <IActionResult> Create(ApplicationUserRegisterDto model)
        {
            var user = new ApplicationUser
            {
                Email     = model.Email,
                UserName  = model.Email,
                FirstName = model.FirstName,
                LastName  = model.LastName
            };

            // Al crear usuario agrega por defecto el rol de vendedor por defecto
            var result = await _userManager.CreateAsync(user, model.Password);

            await _userManager.AddToRoleAsync(user, RoleHelper.Seller);

            if (!result.Succeeded)
            {
                // Para visualizar el mensaje del lado del cliente
                return(BadRequest("No se pudo crear el usuario."));
            }

            return(Ok());
        }