Esempio n. 1
0
        public async Task <AccessTokenResponse> Register(RegisteredUser userRegister)
        {
            RegisteredUserValidation validation = new RegisteredUserValidation(this.repository);

            validation.ValidateAndThrow(userRegister);

            var user = userRegister.ToEntity <User>();

            try
            {
                byte[] hash, salt;
                PasswordManipulation.CreatePasswordHash(userRegister.Password, out hash, out salt);
                user.PasswordHash = hash;
                user.PasswordSalt = salt;

                var roles = userRegister.Role.Trim().Split(",");
                foreach (var role in roles)
                {
                    user.UserRole.Add(new UserRole()
                    {
                        RoleId = (int)Enum.Parse(typeof(RolesEnum), role, true)
                    });
                }

                await this.repository.AddAsync(user);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(CreateToken(user));
        }
Esempio n. 2
0
        public Customer CreateCustomer(UserRegisterdViewModel userRegisterd)
        {
            Customer customer = userRegisterd.ToEntity <Customer>();

            byte[] passwordSalt, passwordHash;

            PasswordManipulation.CreatePasswordHash(userRegisterd.Password, out passwordHash, out passwordSalt);

            customer.PasswordHash = passwordHash;
            customer.PasswordSalt = passwordSalt;

            customer.Id = Guid.NewGuid().ToString();

            this.Add(customer);

            return(customer);
        }