Exemple #1
0
        public Customer Authenticate(string login, string password)
        {
            if (string.IsNullOrWhiteSpace(login))
            {
                throw new ArgumentNullException(nameof(login));
            }

            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentNullException(nameof(password));
            }

            var user = GetByLogin(login);

            if (user is null)
            {
                return(null);
            }

            if (HMACSHA512Helper.IsAValidHash(password, user.PasswordSalt, user.PasswordHash))
            {
                return(user);
            }

            return(null);
        }
        public IActionResult Create(UserViewModel model)
        {
            if (ModelState.IsValid)
            {
                //TODO: Handle avatar image and save

                var(salt, hash) = HMACSHA512Helper.CreateHMACSHA12Hash(model.Password);

                var addresses = new List <Address>();

                if (model.Addresses.Any())
                {
                    foreach (var address in model.Addresses)
                    {
                        addresses.Add(new Address
                        {
                            Cep    = address.CEP,
                            City   = address.City,
                            Street = address.Street,
                            Number = address.Number,
                            Uf     = address.UF
                        });
                    }
                }

                var entity = new Customer
                {
                    BirthDate = model.BirthDate,
                    Email     = model.Email,
                    Address   = addresses,
                    //Avatar = avatarUrl,
                    AccessLevelId = UserAccessLevel == AccessLevelType.Admin ? 1 : 2,
                    FirstName     = model.FirstName,
                    LastName      = model.LastName,
                    Phone         = model.Phone,
                    PasswordSalt  = salt,
                    PasswordHash  = hash,
                    Cpf           = model.CPF,
                    LoginMethodId = (int)LoginMethods.Email
                };
            }

            return(View(model));
        }