Exemple #1
0
        public void ManualLogin(string username, string password)
        {
            EventCenter eventCenter = EventCenter.Default;

            UserManager <ApplicationUser> userManager = ApplicationIdentityManager.GetUserManager();
            ApplicationUser appUser = userManager.Find(username, password);

            if (appUser != null)
            {
                // Authenticated successfully
                // Check if the current user is an Duty Officer or not
                if (userManager.IsInRole(appUser.Id, EnumUserRoles.DutyOfficer))
                {
                    // Authorized successfully
                    Trinity.BE.User user = new Trinity.BE.User()
                    {
                        RightThumbFingerprint = appUser.RightThumbFingerprint,
                        LeftThumbFingerprint  = appUser.LeftThumbFingerprint,
                        IsFirstAttempt        = appUser.IsFirstAttempt,
                        Name        = appUser.Name,
                        NRIC        = appUser.NRIC,
                        Role        = EnumUserRoles.DutyOfficer,
                        SmartCardId = appUser.SmartCardId,
                        Status      = appUser.Status,
                        UserId      = appUser.Id
                    };
                    Session session = Session.Instance;
                    session.IsUserNamePasswordAuthenticated = true;
                    session.Role = EnumUserRoles.DutyOfficer;
                    session[CommonConstants.USER_LOGIN] = user;

                    eventCenter.RaiseEvent(new Trinity.Common.EventInfo()
                    {
                        Code = 0, Name = EventNames.LOGIN_SUCCEEDED
                    });
                }
                else
                {
                    eventCenter.RaiseEvent(new Trinity.Common.EventInfo()
                    {
                        Code = -2, Name = EventNames.LOGIN_FAILED, Message = "You do not have permission to access this page."
                    });
                }
            }
            else
            {
                eventCenter.RaiseEvent(new Trinity.Common.EventInfo()
                {
                    Code = -1, Name = EventNames.LOGIN_FAILED, Message = "Your username or password is incorrect."
                });
            }
        }
Exemple #2
0
        public void ProcessManualLogin(string username, string password)
        {
            try
            {
                BarcodeScannerUtil.Instance.Disconnect();

                EventCenter eventCenter = EventCenter.Default;

                //UserManager<ApplicationUser> userManager = ApplicationIdentityManager.GetUserManager();
                //ApplicationUser appUser = userManager.Find(username, password);
                var             dalUser = new DAL_User();
                ApplicationUser appUser = dalUser.Login(username, password);
                if (appUser != null)
                {
                    // Authenticated successfully
                    // Check if the current user is an Duty Officer or not
                    if (dalUser.IsInRole(appUser.Id, EnumUserRoles.DutyOfficer))
                    {
                        // Authorized successfully
                        Trinity.BE.User user = new Trinity.BE.User()
                        {
                            RightThumbFingerprint = appUser.RightThumbFingerprint,
                            LeftThumbFingerprint  = appUser.LeftThumbFingerprint,
                            IsFirstAttempt        = appUser.IsFirstAttempt,
                            Name        = appUser.Name,
                            NRIC        = appUser.NRIC,
                            Role        = EnumUserRoles.DutyOfficer,
                            SmartCardId = appUser.SmartCardId,
                            Status      = appUser.Status,
                            UserId      = appUser.Id
                        };
                        Session session = Session.Instance;
                        session.IsUserNamePasswordAuthenticated = true;
                        session.Role = EnumUserRoles.DutyOfficer;
                        session[CommonConstants.USER_LOGIN] = user;

                        eventCenter.RaiseEvent(new Trinity.Common.EventInfo()
                        {
                            Code = 0, Name = EventNames.LOGIN_SUCCEEDED
                        });

                        // Set application status is busy
                        ApplicationStatusManager.Instance.IsBusy = true;
                    }
                    else
                    {
                        eventCenter.RaiseEvent(new Trinity.Common.EventInfo()
                        {
                            Code = -2, Name = EventNames.LOGIN_FAILED, Message = "You do not have permission to access this page."
                        });
                    }
                }
                else
                {
                    // Enable scanner
                    if (BarcodeScannerUtil.Instance.GetDeviceStatus().Contains(EnumDeviceStatus.Connected))
                    {
                        System.Threading.Tasks.Task.Factory.StartNew(() => BarcodeScannerUtil.Instance.StartScanning(BarcodeScannerCallback));
                    }

                    eventCenter.RaiseEvent(new Trinity.Common.EventInfo()
                    {
                        Code = -1, Name = EventNames.LOGIN_FAILED, Message = "Your username or password is incorrect."
                    });
                }
            }
            finally
            {
                BarcodeScannerUtil.Instance.Disconnect();
            }
        }