Ejemplo n.º 1
0
        public void Execute(object parameter)
        {
            if (!Classes.Functions.CheckConnection())
            {
                messenger.Send(new NotConnectionMessage());
                return;
            }

            if (parameter is RegisterHelpClass userData)
            {
                var storedUser = dbUser.GetUserByModel(userData.User);

                if (storedUser != null)
                {
                    if (storedUser.Username == userData.User.Username)
                    {
                        messenger.Send(new UserExistMessage()
                        {
                            Message = "User with this username already exist"
                        });
                    }
                    else
                    {
                        messenger.Send(new UserExistMessage()
                        {
                            Message = "User with this email already exist"
                        });
                    }
                }
                else
                {
                    var userAdded = dbUser.AddUser(userData.User);

                    messenger.Send(new SignInApprovedMessage()
                    {
                        SignInType = SignInType.Register,
                        UserId     = userAdded.Id
                    });

                    messenger.Send(new LogInChangedMessage()
                    {
                        UserId      = userAdded.Id,
                        SignLogCode = SignLogCode.Registered
                    });
                }
            }
        }
Ejemplo n.º 2
0
        public void Execute(object parameter)
        {
            if (!Classes.Functions.CheckConnection())
            {
                messenger.Send(new NotConnectionMessage());
                return;
            }

            if (parameter is UserDetailModelDTO userData)
            {
                userData.Email = userData.Username;
                var user = dbUser.GetUserByModel(userData);

                if (user != null)
                {
                    if (dbLogIn.GetDeniedRow(user.Id) >= 3)
                    {
                        messenger.Send(new SignInDeniedMessage());
                        return;
                    }
                }
                else
                {
                    messenger.Send(new SignInDeniedMessage()
                    {
                        Message = "Wrong login or password"
                    });
                    return;
                }

                if (dbUser.Authenticate(userData))
                {
                    messenger.Send(new SignInApprovedMessage()
                    {
                        SignInType = SignInType.SignIn,
                        UserId     = user.Id
                    });

                    messenger.Send(new LogInChangedMessage()
                    {
                        UserId      = user.Id,
                        SignLogCode = SignLogCode.Succesful
                    });
                }
                else
                {
                    messenger.Send(new SignInDeniedMessage()
                    {
                        Message = "Wrong login or password"
                    });

                    if (user != null)
                    {
                        messenger.Send(new LogInChangedMessage()
                        {
                            UserId      = user.Id,
                            SignLogCode = SignLogCode.AccessDenied
                        });
                    }
                }
            }
        }