Beispiel #1
0
 public ClaimsIdentity GetIdentity(IUnitOfWork uow, UserDO userDO)
 {
     var um = new KwasantUserManager(uow);
     var identity = um.CreateIdentity(userDO, DefaultAuthenticationTypes.ApplicationCookie);
     foreach (var roleId in userDO.Roles.Select(r => r.RoleId))
     {
         var role = uow.AspNetRolesRepository.GetByKey(roleId);
         identity.AddClaim(new Claim(ClaimTypes.Role, role.Name));
     }
     return identity;
 }
Beispiel #2
0
 public async Task<IdentityResult> ResetPasswordAsync(string userId, string code, string password)
 {
     using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
     {
         var userManager = new KwasantUserManager(uow);
         var result = await userManager.ResetPasswordAsync(userId, code, password);
         uow.SaveChanges();
         return result;
     }
 }
Beispiel #3
0
        public async Task ForgotPasswordAsync(string userEmail)
        {
            using (var uow = ObjectFactory.GetInstance<IUnitOfWork>())
            {
                var userManager = new KwasantUserManager(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);
                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";

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