Ejemplo n.º 1
0
 private void ThrowIfLockout(AppUser user)
 {
     if (user.LockoutEnabled)
     {
         if (DateTime.UtcNow > user.LockoutEndDateUtc)
         {
             user.LockoutEnabled = false;
             user.AccessFailedCount = 0;
             _iUnitOfWork.SaveChanges();
         }
         else
         {
             throw BankClientException.ThrowUserLockout();
         }
     }
 }
Ejemplo n.º 2
0
 private void ThrowIfNotRegistered(AppUser user)
 {
     if (user == null)
     {
         throw BankClientException.ThrowUserNotRegistered();
     }
 }
Ejemplo n.º 3
0
 private void ThrowIfInvalidEmployeeCredentials(AppUser user, string password)
 {
     var appUser = AppUserManagerFactory.Instance.Factory().Find(user.UserName, password);
     if (appUser == null)
     {
         throw BankClientException.ThrowInvalidCredentials();
     }
 }
Ejemplo n.º 4
0
        private void ThrowIfInvalidCredentials(AppUser user, string password)
        {
            var appUser = AppUserManagerFactory.Instance.Factory().Find(user.UserName, password);
            if (appUser == null)
            {
                user.AccessFailedCount += 1;
                if (user.AccessFailedCount == 3)
                {
                    user.LockoutEnabled = true;
                    user.LockoutEndDateUtc = DateTime.UtcNow + TimeSpan.FromMinutes(15);
                    _iEmailSender.SendLockoutNotification(user.Email, user.UserName);
                }
                _iUnitOfWork.SaveChanges();

                throw BankClientException.ThrowInvalidCredentials();
            }
        }
Ejemplo n.º 5
0
 private void ThrowIfEmailNotConfirmed(AppUser user)
 {
     if (!user.EmailConfirmed)
     {
         throw BankClientException.ThrowEmailNotConfirmed();
     }
 }
Ejemplo n.º 6
0
        public async Task<IHttpActionResult> RegisterExternal(RegisterExternalBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            ExternalLoginData externalLogin = ExternalLoginData.FromIdentity(User.Identity as ClaimsIdentity);

            if (externalLogin == null)
            {
                return InternalServerError();
            }

            var user = new AppUser()
            {
                UserName = model.UserName
            };
            user.Logins.Add(new IdentityUserLogin
            {
                LoginProvider = externalLogin.LoginProvider,
                ProviderKey = externalLogin.ProviderKey
            });
            IdentityResult result = await UserManager.CreateAsync(user);
            IHttpActionResult errorResult = GetErrorResult(result);

            if (errorResult != null)
            {
                return errorResult;
            }

            return Ok();
        }
Ejemplo n.º 7
0
        public async Task<IHttpActionResult> Register(RegisterBindingModel request)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return BadRequest(ModelState);
                }

                var user = new AppUser()
                {
                    Email = request.Email,
                    UserName = request.UserName
                };

                var customer =
                    _iUnitOfWork.CustomerRepository.GetAll()
                        .FirstOrDefault(c => c.IdentificationNumber == request.IdentificationNumber);

                if (customer == null)
                {
                    throw BankClientException.ThrowIdentificationNumberNotFound();
                }

                if (request.Code != customer.SecretCode)
                {
                    throw BankClientException.ThrowSuperSecretCodeIsIncorrect();
                }

                //                else
                //                {
                //                    customer = Mapper.Map<Customer>(request);
                //                    _iUnitOfWork.CustomerRepository.Add(customer);
                //                    _iUnitOfWork.SaveChanges();
                //                }

                user.CustomerId = customer.Id;
                var result = await UserManager.CreateAsync(user, request.Password);
                if (result.Succeeded)
                {
                    UserManager.AddToRole(user.Id, AppRoles.User.ToString());
                    var baseUrl = String.Format("{0}://{1}", Request.RequestUri.Scheme, Request.RequestUri.Authority);
                    _iEmailSender.SendVerifyToEmail(user.Email, user.Id, baseUrl);
                }
                var errorResult = GetErrorResult(result);

                if (errorResult != null)
                {
                    return errorResult;
                }

                return Ok();
            }
            catch (BankClientException ex)
            {
                return BadRequest(ex.Message);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }