示例#1
0
        public void Create(IUnitOfWork uow, Fr8AccountDO submittedDockyardAccountData)
        {
            submittedDockyardAccountData.State = UserState.Active;
            submittedDockyardAccountData.Id    = Guid.NewGuid().ToString();
            if (string.IsNullOrEmpty(submittedDockyardAccountData.UserName))
            {
                submittedDockyardAccountData.UserName = submittedDockyardAccountData.EmailAddress != null
                    ? submittedDockyardAccountData.EmailAddress.Address
                    : null;
            }
            if (string.IsNullOrEmpty(submittedDockyardAccountData.UserName))
            {
                throw new ApplicationException("User must have username or email address");
            }
            submittedDockyardAccountData.EmailAddress =
                uow.EmailAddressRepository.GetOrCreateEmailAddress(submittedDockyardAccountData.EmailAddress.Address);
            submittedDockyardAccountData.Roles.ToList().ForEach(e =>
                                                                uow.AspNetUserRolesRepository.Add(new AspNetUserRolesDO
            {
                RoleId = e.RoleId,
                UserId = submittedDockyardAccountData.Id
            }));
            submittedDockyardAccountData.Roles.Clear();
            var userManager = new DockyardIdentityManager(uow);
            var result      = userManager.Create(submittedDockyardAccountData);

            if (!result.Succeeded)
            {
                throw new AggregateException(result.Errors.Select(s => new ApplicationException(s)));
            }
            uow.SaveChanges();
            EventManager.ExplicitCustomerCreated(submittedDockyardAccountData.Id);
        }
示例#2
0
        public async Task <IdentityResult> ResetPasswordAsync(string userId, string code, string password)
        {
            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                var userManager = new DockyardIdentityManager(uow);
                var result      = await userManager.ResetPasswordAsync(userId, code, password);

                uow.SaveChanges();
                return(result);
            }
        }
示例#3
0
        public async Task ForgotPasswordAsync(string userEmail)
        {
            using (var uow = ObjectFactory.GetInstance <IUnitOfWork>())
            {
                var userManager = new DockyardIdentityManager(uow);
                var user        = await userManager.FindByEmailAsync(userEmail);

                if (user == null /* || !(await userManager.IsEmailConfirmedAsync(user.Id))*/)
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return;
                }

                var code = await userManager.GeneratePasswordResetTokenAsync(user.Id);

                code = HttpUtility.HtmlEncode(code);

                var callbackUrl = string.Format("{0}Account/ResetPassword?UserId={1}&code={2}", Server.ServerUrl,
                                                user.Id, code);

                var emailDO = new EmailDO();
                IConfigRepository configRepository = ObjectFactory.GetInstance <IConfigRepository>();
                string            fromAddress      = configRepository.Get("EmailAddress_GeneralInfo");
                var emailAddressDO = uow.EmailAddressRepository.GetOrCreateEmailAddress(fromAddress);
                emailDO.From   = emailAddressDO;
                emailDO.FromID = emailAddressDO.Id;
                emailDO.AddEmailRecipient(EmailParticipantType.To,
                                          uow.EmailAddressRepository.GetOrCreateEmailAddress(userEmail));
                emailDO.Subject = "Password Recovery Request";
                string htmlText = string.Format("Please reset your password by clicking this <a href='{0}'>link:</a> <br> <b>Note: </b> Reset password link will be expired after 24 hours.", callbackUrl);
                emailDO.HTMLText = htmlText;

                uow.EnvelopeRepository.ConfigureTemplatedEmail(emailDO, configRepository.Get("ForgotPassword_template"),
                                                               new Dictionary <string, object>()
                {
                    { "-callback_url-", callbackUrl }
                });
                uow.SaveChanges();

                await ObjectFactory.GetInstance <IEmailPackager>().Send(new EnvelopeDO {
                    Email = emailDO
                });
            }
        }