Пример #1
0
        private void GetCardInfoSucceeded(string cardUID)
        {
            LogManager.Debug("GetCardInfoSucceeded: " + cardUID);
            //MessageBox.Show(cardUID);
            // get local user info
            DAL_User dAL_User = new DAL_User();
            var      user     = dAL_User.GetUserBySmartCardId(cardUID);

            //LogManager.Debug("GetCardInfoSucceeded: user: "******"You have been blocked.", "Supervisee " + user.Name + " has been blocked.");
                        return;
                    }
                    if (user.Status.Equals(EnumUserStatuses.New, StringComparison.InvariantCultureIgnoreCase))
                    {
                        SmartCard_OnSmartCardFailed("You haven't enrolled yet.", "Supervisee " + user.Name + " hasn't enrolled yet.");
                        return;
                    }
                    if (user.Role.Equals(EnumUserRoles.USA, StringComparison.InvariantCultureIgnoreCase) || user.Role.Equals(EnumUserRoles.Supervisee, StringComparison.InvariantCultureIgnoreCase))
                    {
                        var smartCard = new DAL_IssueCard().GetIssueCardBySmartCardId(cardUID);
                        if (smartCard == null)
                        {
                            SmartCard_OnSmartCardFailed("Your smart card does not exist.", "The smart card " + cardUID + " does not exist.");
                            return;
                        }
                        else if (smartCard.Status.Equals(EnumIssuedCards.Inactive, StringComparison.InvariantCultureIgnoreCase))
                        {
                            SmartCard_OnSmartCardFailed("Your smart card does not work.", "The smart card " + cardUID + " does not work.");
                            return;
                        }
                        else if ((smartCard.Status.Equals(EnumIssuedCards.Active, StringComparison.InvariantCultureIgnoreCase) && smartCard.Expired_Date < DateTime.Today) || (user.Expired_Date.HasValue && user.Expired_Date.Value < DateTime.Today))
                        {
                            SmartCard_OnSmartCardFailed("Your smart card has already expired.", "The smart card " + cardUID + " has already expired.");
                            return;
                        }
                    }
                    Session session = Session.Instance;
                    session.IsSmartCardAuthenticated    = true;
                    session[CommonConstants.USER_LOGIN] = user;
                    this.LayerWeb.RunScript("$('.status-text').css('color','#000').text('Your smart card is authenticated.');");
                    // Stop SCardMonitor
                    SmartCardReaderUtil.Instance.StopSmartCardMonitor();
                    // raise succeeded event
                    SmartCard_OnSmartCardSucceeded();
                    //MessageBox.Show("SmartCard_OnSmartCardSucceeded");
                }
                else
                {
                    SmartCard_OnSmartCardFailed("You do not have permission to access this page", "The user " + user.Name + " tries to access a page for which he/she is not authorized.");
                }
            }
            else
            {
                // raise failed event
                if (string.IsNullOrEmpty(cardUID))
                {
                    SmartCard_OnSmartCardFailed("Unable to retrieve smart card information.", "The smart card " + cardUID + " cannot be read.");
                }
                else
                {
                    SmartCard_OnSmartCardFailed("Your smart card does not exist.", "The smart card " + cardUID + " does not exist.");
                }
                //SmartCard_OnSmartCardSucceeded();
            }
        }
Пример #2
0
        private async void CreateUserAsync()
        {
            //if (string.IsNullOrEmpty(_currentUser.SmartCardId) || _currentUser.Fingerprint == null)
            //{
            //    MessageBox.Show("You have to scan your smart card and fingerprint");
            //    return;
            //}
            //
            // Prepare user information
            //

            _currentUser.Name = txtName.Text;
            _currentUser.NRIC = txtNRIC.Text;
            _currentUser.Role = String.IsNullOrEmpty(cboRoles.Text) ? EnumUserRoles.Supervisee : cboRoles.Text;

            ApplicationUser user = new ApplicationUser();

            user.UserName = _currentUser.NRIC;
            user.Name     = _currentUser.Name;
            user.Email    = txtPrimaryEmail.Text;
            user.RightThumbFingerprint = _currentUser.RightThumbFingerprint;
            user.LeftThumbFingerprint  = _currentUser.LeftThumbFingerprint;
            user.IsFirstAttempt        = _currentUser.IsFirstAttempt;
            user.NRIC        = _currentUser.NRIC;
            user.PhoneNumber = txtPrimaryPhone.Text;
            user.SmartCardId = _currentUser.SmartCardId;
            user.Status      = EnumUserStatuses.Enrolled;

            UserManager <ApplicationUser> userManager = ApplicationIdentityManager.GetUserManager();

            Trinity.DAL.DAL_User dalUser = new Trinity.DAL.DAL_User();
            IdentityResult       result  = await userManager.CreateAsync(user, txtPassword.Text.Trim());

            if (result.Succeeded)
            {
                RoleManager <IdentityRole> roleManager = ApplicationIdentityManager.GetRoleManager();
                userManager.AddToRole(user.Id, _currentUser.Role);
                // Save to the Centralized DB also
                //dalUser.CreateUser(_currentUser, false);

                Trinity.DAL.DAL_UserProfile dalUserProfile = new Trinity.DAL.DAL_UserProfile();
                Trinity.BE.UserProfile      userProfile    = new Trinity.BE.UserProfile();
                userProfile.UserId        = _currentUser.UserId;
                userProfile.Primary_Phone = txtPrimaryPhone.Text;
                userProfile.Primary_Email = txtPrimaryEmail.Text;
                userProfile.Nationality   = txtNationality.Text;
                userProfile.DOB           = dpDOB.Value;



                var updateUProfileResult = CallCentralized.Post <bool>("User", "UpdateUserProfile", userProfile);

                //dalUserProfile.UpdateUserProfile(userProfile, _currentUser.UserId, true);

                //// Save to the Centralized DB also
                //dalUserProfile.UpdateUserProfile(userProfile, _currentUser.UserId, false);

                Trinity.BE.IssueCard issuedCard = new Trinity.BE.IssueCard()
                {
                    CreatedDate   = DateTime.Now,
                    Date_Of_Issue = DateTime.Now,
                    Expired_Date  = DateTime.Now.AddYears(2),
                    Name          = _currentUser.Name,
                    NRIC          = _currentUser.NRIC,
                    Serial_Number = "123434",
                    SmartCardId   = _currentUser.SmartCardId,
                    Status        = "Active",
                    UserId        = user.Id
                };
                DAL_IssueCard dalIssuedCard = new DAL_IssueCard();
                dalIssuedCard.Insert(issuedCard);

                btnSave.Enabled = false;
                MessageBox.Show("Create user successfully!", "Create user", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Form frmMain = (Form)this.MainForm;
                frmMain.Show();
                this.Close();
            }
            else
            {
                MessageBox.Show("Could not create user.", "Create user", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #3
0
        private void GetCardInfoSucceeded(string cardUID)
        {
            DAL_User dAL_User = new DAL_User();

            Trinity.BE.User user = dAL_User.GetUserBySmartCardId(cardUID);

            if (user != null)
            {
                // Only enrolled supervisees are allowed to login
                if (user.Role.Equals(EnumUserRoles.Supervisee, StringComparison.InvariantCultureIgnoreCase) || user.Role.Equals(EnumUserRoles.DutyOfficer, StringComparison.InvariantCultureIgnoreCase))
                {
                    if (user.Status.Equals(EnumUserStatuses.New, StringComparison.InvariantCultureIgnoreCase))
                    {
                        SmartCard_OnSmartCardFailed("You haven't enrolled yet.", "Supervisee " + user.Name + " hasn't enrolled yet.");
                        return;
                    }
                    if (user.Role.Equals(EnumUserRoles.Supervisee, StringComparison.InvariantCultureIgnoreCase))
                    {
                        var smartCard = new DAL_IssueCard().GetIssueCardBySmartCardId(cardUID);
                        if (smartCard == null)
                        {
                            SmartCard_OnSmartCardFailed("Your smart card does not exist.", "The smart card " + cardUID + " does not exist.");
                            return;
                        }
                        else if (smartCard.Status.Equals(EnumIssuedCards.Inactive, StringComparison.InvariantCultureIgnoreCase))
                        {
                            SmartCard_OnSmartCardFailed("Your smart card does not work.", "The smart card " + cardUID + " does not work.");
                            return;
                        }
                        else if ((smartCard.Status.Equals(EnumIssuedCards.Active, StringComparison.InvariantCultureIgnoreCase) && smartCard.Expired_Date < DateTime.Today) || (user.Expired_Date.HasValue && user.Expired_Date.Value < DateTime.Today))
                        {
                            SmartCard_OnSmartCardFailed("Your smart card has already expired.", "The smart card " + cardUID + " has already expired.");
                            return;
                        }
                    }
                    Session session = Session.Instance;
                    session.IsSmartCardAuthenticated    = true;
                    session[CommonConstants.USER_LOGIN] = user;
                    this.LayerWeb.RunScript("$('.status-text').css('color','#000').text('Your smart card is authenticated.');");
                    // Stop SCardMonitor
                    SmartCardReaderUtil sCardMonitor = SmartCardReaderUtil.Instance;
                    sCardMonitor.StopSmartCardMonitor();
                    // raise succeeded event

                    new DAL_ActionLog().Insert(ActionName.TabSmartCard, user.UserId, string.Empty, EnumStation.ARK);
                    SmartCard_OnSmartCardSucceeded();
                }
                else
                {
                    SmartCard_OnSmartCardFailed("You do not have permission to login to this system.", "The user " + user.Name + " tries to access ARK for which he/she is not authorized.");
                }
            }
            else
            {
                // raise failed event

                if (string.IsNullOrEmpty(cardUID))
                {
                    SmartCard_OnSmartCardFailed("Unable to retrieve smart card information.", "The smart card " + cardUID + " cannot be read.");
                }
                else
                {
                    SmartCard_OnSmartCardFailed("Your smart card does not exist.", "The smart card " + cardUID + " does not exist.");
                }
            }
        }