예제 #1
0
        public Guid PasswordRecoveryInit(ProfilePasswordRecoveryModel model)
        {
            // validate model
            if (model == null || String.IsNullOrWhiteSpace(model.Login))
            {
                throw new CustomInputException("Password Recovery model is empty!");
            }
            if (String.IsNullOrWhiteSpace(model.Password))
            {
                throw new CustomInputException("Password is empty!");
            }
            if (!model.IsPasswordMatch())
            {
                throw new CustomInputException("Password Confirmation does not match!");
            }

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

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

            // get person
            var person = this.Persons
                         .Include(t => t.User)
                         .FirstOrDefault(p => p.User.Login.ToLower() == model.Login.ToLower());

            if (person == null || person.User == null)
            {
                throw new CustomInputException($"User with login '{model.Login}' not found!");
            }

            model.PersonID = person.ID;

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

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

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

            return(activity.ID);
        }
예제 #2
0
 public Guid PasswordRecoveryInit([FromBody] ProfilePasswordRecoveryModel model)
 {
     return(_profileService.PasswordRecoveryInit(model));
 }