示例#1
0
        public AuthenticationService(UserAccountsManager userAccountsManager, IUserInterfaceService userInterfaceService)
        {
            this.userAccountsManager = userAccountsManager;
            uiService = userInterfaceService;

            uiService.BreakLine();
            uiService.OutputInfo("<Authentication>", InfoCategory.SubTitle);
            uiService.BreakLine();
        }
示例#2
0
        public void Authenticate()
        {
            var status_messages = new Dictionary <AuthStatus, string>();

            status_messages.Add(AuthStatus.AccountValidated, "Account validated successfully.");
            status_messages.Add(AuthStatus.UserNotFound, "Username not found.");
            status_messages.Add(AuthStatus.IncorrectPasswd, "Incorrect password.");

            AuthStatus status;

            var userAccount = userAccountsManager.Find(uiService.GetUIField("Username").Value);

            if (userAccount == null)
            {
                status = AuthStatus.UserNotFound;
            }
            else
            if (userAccount.Passwd != uiService.GetUIField("Password").Value)
            {
                status = AuthStatus.IncorrectPasswd;
            }
            else
            {
                status = AuthStatus.AccountValidated;
            }

            if (status == AuthStatus.AccountValidated)
            {
                this.result = ServiceExecutionResult.Success;
            }
            else
            {
                remainingAttempts--;
                if (remainingAttempts == 0)
                {
                    this.result = ServiceExecutionResult.Failure;
                }
            }

            uiService.BreakLine();
            uiService.OutputInfo(status_messages[status], InfoCategory.FixedResponse);

            if (this.result != ServiceExecutionResult.Undefined)
            {
                this.status = ServiceExecutionStatus.Completed;
            }
        }
        public async void Run()
        {
            this.uiService = svcPvd.GetService<IUserInterfaceService>();
            this.uiService.OutputInfo("--* IoC Example App *--", InfoCategory.Title);

            var authService = svcPvd.GetService<IAuthenticationService>();

            var t = await authService.SignInTask();

            var msg = "";

            if (t == ServiceExecutionResult.Failure)
                msg = "It's not possible to proceed.";
            else
                msg = "You're in.";

            uiService.OutputInfo(msg, InfoCategory.Response);
            if (uiService.RequestAppStop != null) Stop(uiService.RequestAppStop);
        }