Exemple #1
0
        // source: // source: http://jasonwatmore.com/post/2018/06/26/aspnet-core-21-simple-api-for-authentication-registration-and-user-management
        public Developer Add(Developer user, string password)
        {
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new Exception("Password is required");
            }

            // find if user exists
            var existingUsers = _repository.FindByConditionAync(x => x.UserName == user.UserName);

            if (existingUsers.Result.Count() != 0)
            {
                throw new Exception("Username \"" + user.UserName + "\" is already taken");
            }

            byte[] passwordHash, passwordSalt;

            // create password secret
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            var developer = _mapper.Map <DeveloperDTO>(user);

            developer.PasswordHash = passwordHash;
            developer.PasswordSalt = passwordSalt;

            var result = _factory.Create(developer);

            return(result);
        }
Exemple #2
0
        public int HandleCreate(DeveloperForm form)
        {
            var developer = developerFactory.Create(form.Name);

            entityRepository.InsertOnSave(developer);
            entityRepository.SaveChanges();

            return(developer.Id);
        }