Exemplo n.º 1
0
        public Guid RegistrationInit(ProfileRegistrationModel model)
        {
            if (model == null)
            {
                throw new CustomArgumentException("Registration data is empty!");
            }

            // input validation
            if (String.IsNullOrWhiteSpace(model.Email))
            {
                throw new CustomInputException("Email is empty!");
            }
            if (String.IsNullOrWhiteSpace(model.Password))
            {
                throw new CustomInputException("Password is empty!");
            }
            if (!model.IsPasswordMatch())
            {
                throw new CustomInputException("Password confirmation is not equal to Passowrd!");
            }

            // security policy
            var securityPolicy = this.GetSecurityPolicy();

            if (!securityPolicy.CheckStrength(model.Password))
            {
                throw new CustomInputException("Password does not match Security Policy!");
            }

            // change valid login
            model.Login = model.GetValidLogin();

            // check if user already exists with login
            var persons = this.Persons
                          .Include(t => t.User)
                          .Where(p => p.User.Login.ToLower() == model.Login.ToLower())
                          .ToList();

            if (persons.Any())
            {
                throw new CustomInputException($"Person with login {model.Login} is already exist!");
            }

            // create activity
            var now      = CommonService.Now;
            var pin      = CommonService.GeneratePin(10);
            var activity = Activity.Create(now.AddHours(DEFAULT_ACTIVITY_EXPIRATION_HOURS), DEFAULT_ACTIVITY_TYPE_REGISTRATION, model, pin);

            _dbContext.Set <Activity>().Add(activity);
            _dbContext.SaveChanges();

            // raise event to send email
            DomainDispatcher.RaiseEvent(new RegistrationInitDomainEvent()
            {
                Email     = model.Email,
                NameFirst = model.NameFirst,
                NameLast  = model.NameLast,
                Login     = model.Login,
                PIN       = pin
            });

            return(activity.ID);
        }
Exemplo n.º 2
0
 public Guid RegistrationInit([FromBody] ProfileRegistrationModel model)
 {
     return(_profileService.RegistrationInit(model));
 }