Example #1
0
        /// <summary>
        /// This is used to verify if the user that has logged in
        /// is the same that before, if not this will Reject every query in the Queue
        /// and clear all subscriptions, otherwise this will replay the Queue if it is waiting.
        /// </summary>
        internal override void OnUserLoggedIn(object sender, UserLoggedInEvent e)
        {
            if (previousKUID != e.Kuid)
            {
                if (AutoRecover &&
                    QueryReplayer.WaitLoginToReplay)
                {
                    QueryReplayer.RejectAllQueries(new UnauthorizeException("Request submitted by another user"));
                    QueryReplayer.Lock = false;
                    QueryReplayer.WaitLoginToReplay = false;
                }

                SubscriptionRecoverer.Clear();
            }
            else
            {
                if (AutoRecover &&
                    QueryReplayer.WaitLoginToReplay)
                {
                    QueryReplayer.ReplayQueries();
                    QueryReplayer.Lock = false;
                    QueryReplayer.WaitLoginToReplay = false;
                }

                SubscriptionRecoverer.RenewSubscriptions();
            }
            previousKUID = e.Kuid;
        }
 /// <summary>
 /// Fire user logged in event.
 /// </summary>
 /// <param name="userContext">Information about the user that has logged in.</param>
 private void FireUserLoggedInEvent(IUserContext userContext)
 {
     if (UserLoggedInEvent.IsNotNull())
     {
         UserLoggedInEvent(userContext);
     }
 }
Example #3
0
        public async Task Handle(UserLoggedInEvent notification, CancellationToken cancellationToken)
        {
            var log = _mapper.Map <UserLoginLog>(notification);
            await _loginLogRepository.AddAsync(log);

            await _loginLogRepository.SaveChangesAsync();
        }
Example #4
0
        public async Task <ApplicationResult <LoginResponseModel> > Handle(LoginCommand request, CancellationToken cancellationToken)
        {
            var user = await _userService.GetUserAsync(request.Email);

            if (user == null)
            {
                return(ApplicationResult <LoginResponseModel> .Fail(PowerChatError.Create(UserErrorCodes.UserNotFound,
                                                                                          $"User with email '{request.Email}' was not found.")));
            }

            var result = await _authService.LoginAsync(request.Email, request.Password);

            if (result.Succeeded)
            {
                var userLoggedInEvent = new UserLoggedInEvent {
                    UserId = user.Id
                };
                await _mediator.Publish(userLoggedInEvent, cancellationToken);

                var loginResponse = new LoginResponseModel
                {
                    UserId  = user.Id,
                    Token   = result.Value.Token,
                    Expires = result.Value.Expires
                };

                return(ApplicationResult <LoginResponseModel> .Ok(loginResponse));
            }

            return(ApplicationResult <LoginResponseModel> .Fail(result.Error));
        }
Example #5
0
        public void Handle(UserLoggedInEvent ev)
        {
            var usage = _usageRepository.GetByIdentityId(ev.EntityId);

            if (usage != null)
            {
                usage.UpdateLastLogin(ev.TimeStamp);
                _usageRepository.Save();
            }
        }
Example #6
0
        public async Task Handle(UserLoggedInEvent @event)
        {
            LedgerIdentityUser user = await _userManager.FindByIdAsync(@event.UserId.ToString());

            bool confirmedEmail = await _userManager.IsEmailConfirmedAsync(user);

            string confirmationToken = await _userManager.GenerateEmailConfirmationTokenAsync(user);

            if (!confirmedEmail)
            {
                EmailTemplate template = new EmailTemplate(@event.Email)
                                         .SetTemplate(EmailTemplateTypes.UserLoggedIn)
                                         .AddSubstitution("-code-", confirmationToken);

                await _emailDispatcher.SendEmailAsync(template);
            }
        }
Example #7
0
        public Guid Login(UserIdentifier userIdentifier, string username, string password)
        {
            VerifySystemIsInitialized();
            _verifier.VerifyMe(MethodBase.GetCurrentMethod(), userIdentifier, username, password);
            var result = _userDomain.Login(username, password);

            if (!result.Equals(Guid.Empty))
            {
                var newEvent = new UserLoggedInEvent(result);
                //newEvent.SetTargets(DomainData.ShopsCollection.Values, DomainData.RegisteredUsersCollection.Values);
                //newEvent.SetMessage(DomainData.ShopsCollection.Values, DomainData.RegisteredUsersCollection.Values);
                newEvent.SetMessages(_unitOfWork);
                UpdateCenter.RaiseEvent(newEvent);
                _logger.LogInformation($"{username} logged in successfuly.");
            }
            return(result);
        }
Example #8
0
        private static async Task OnTicketReceived(TicketReceivedContext context)
        {
            var principal = context.Principal;

            if (principal != null)
            {
                var mediator = context.HttpContext.RequestServices.GetRequiredService <IMediator>();

                var @event = new UserLoggedInEvent
                {
                    FullName = principal.Identity.Name,
                    Email    = principal.Claims
                               .FirstOrDefault(x => x.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress")?.Value
                };

                await mediator.Publish(@event);
            }
        }
        /// <summary>
        /// Login user.
        /// </summary>
        /// <param name="userName">User name.</param>
        /// <param name="password">Password.</param>
        /// <param name="applicationIdentifier">
        /// Identifier of the application that the user uses.
        /// </param>
        /// <param name="isActivationRequired">
        /// Flag that indicates that the user account must
        /// be activated before login can succeed.
        /// </param>
        /// <param name="errorMessage">Possible error message if login failed.</param>
        /// <returns>True if user was logged in.</returns>
        public static Boolean Login(String userName,
                                    String password,
                                    String applicationIdentifier,
                                    Boolean isActivationRequired,
                                    out String errorMessage)
        {
            Boolean isUserLoggedIn = false;

            // Check arguments.
            userName.CheckNotEmpty("userName");
            password.CheckNotEmpty("password");

            // Make sure the user is not already logged in.
            Logout();

            // Loggin.
            try
            {
                errorMessage   = null;
                isUserLoggedIn = WebServiceClient.Login(userName, password, applicationIdentifier, isActivationRequired);
            }
            catch (WebException)
            {
                // No contact with web service.
                errorMessage = "Validering av ditt konto misslyckades!\nIngen kontakt mot servern gick att erhålla.";
            }
            catch (Exception exception)
            {
                errorMessage = "Validering av ditt konto misslyckades!\nServern returnerade ett fel.\n" + exception.Message;
            }
            if (isUserLoggedIn)
            {
                // Get user information.
                _user = GetUser(WebServiceClient.GetUser());

                // Fire user logged in event.
                if (UserLoggedInEvent.IsNotNull())
                {
                    UserLoggedInEvent();
                }
            }

            return(isUserLoggedIn);
        }
Example #10
0
 internal abstract void OnUserLoggedIn(object sender, UserLoggedInEvent e);
Example #11
0
 /// <summary>
 /// User logged in event, creates instance of user
 /// </summary>
 /// <param name="user"></param>
 private void UserLoggedIn(User user)
 {
     WeSketchClientData.Instance.User = user;
     UserLoggedInEvent.Invoke();
 }
 private static void ARA_Events_UserLoggedInEventHandler(object sender, UserLoggedInEvent e)
 {
     AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;
 }