示例#1
0
        private void AddUserDetails(string userName, string password, string selectedDomain)
        {
            string cardID               = Session["SelfRegistterCardID"] as string;
            string userID               = userName;
            string domainName           = selectedDomain;
            string userPassword         = password;
            bool   isValidFascilityCode = false;
            bool   isValidCard          = false;
            string cardValidationInfo   = "";
            string deviceIpAddress      = Request.Params["REMOTE_ADDR"].ToString();
            string transformationCard   = Card.ProvideCardTransformation(null, Session["CardReaderType"] as string, cardID, ref isValidFascilityCode, ref isValidCard, ref cardValidationInfo);
            string deviceCulture        = HttpContext.Current.Request.UserLanguages[0];
            bool   isSupportedlangauge  = DataManagerDevice.ProviderDevice.ApplicationSettings.IsSupportedLanguage(deviceCulture);

            if (!isSupportedlangauge)
            {
                deviceCulture = "en-US";
            }
            if (Session["UILanguage"] != null)
            {
                deviceCulture = Session["UILanguage"] as string;
            }
            if (!string.IsNullOrEmpty(transformationCard))
            {
                string pin = "";
                if (DataManagerDevice.Controller.Card.IsCardExists(cardID))
                {
                    Response.Redirect("MessageForm.aspx?FROM=SelfRegistration.aspx&MESS=CARDID_ALREADY_USED");
                    //LabelCommunicatorNote.Text = Localization.GetServerMessage(Constants.APPLICATION_TYPE_OSA_CLASSIC, deviceCulture, "CARDID_ALREADY_USED");
                }
                else
                {
                    if (isValidFascilityCode == true && string.IsNullOrEmpty(cardValidationInfo) == true)
                    {
                        if (string.Compare(cardID, transformationCard, true) == 0) //cardID.IndexOf(transformationCard) > -1
                        {
                            int    defaultDepartment    = DataManagerDevice.ProviderDevice.Users.ProvideDefaultDepartment(userSource);
                            string userAuthenticationOn = "Username/Password";
                            try
                            {
                                if (userSource == Constants.USER_SOURCE_DB)
                                {
                                    domainName = "Local";
                                }
                                if (string.IsNullOrEmpty(domainName))
                                {
                                    domainName = "Local";
                                }

                                string emailid = string.Empty;
                                if (userSource == Constants.USER_SOURCE_AD)
                                {
                                    emailid = Ldap.GetUserEmail(domainName, userID, userPassword, userID.Replace("'", "''"));
                                }

                                // Check If the User exist in the AccountingPlus Database
                                string  isInserted            = "";
                                bool    isUpdated             = false;
                                DataSet dsExistingUserDetails = DataManagerDevice.ProviderDevice.Users.ProvideUserDetails(userID, userSource);
                                if (dsExistingUserDetails != null)
                                {
                                    if (dsExistingUserDetails.Tables[0].Rows.Count > 0)
                                    {
                                        string existingPassword = dsExistingUserDetails.Tables[0].Rows[0]["USR_PASSWORD"].ToString();
                                        // Update existing user
                                        isInserted = DataManagerDevice.Controller.Users.UpdateUser(userID, userPassword, cardID, userAuthenticationOn, pin, userSource, defaultDepartment, domainName, ref isUpdated);
                                    }
                                    else
                                    {
                                        // Insert new user
                                        isInserted = DataManagerDevice.Controller.Users.InsertUser(userID, userPassword, cardID, userAuthenticationOn, pin, userSource, defaultDepartment, domainName, emailid, ref isUpdated);
                                    }
                                }
                                else
                                {
                                    // Insert new user
                                    isInserted = DataManagerDevice.Controller.Users.InsertUser(userID, userPassword, cardID, userAuthenticationOn, pin, userSource, defaultDepartment, domainName, emailid, ref isUpdated);
                                }

                                if (string.IsNullOrEmpty(isInserted))
                                {
                                    //string assignUser = DataManagerDevice.Controller.Users.AssignUserToCostCenter(userID, "1", userSource);

                                    password            = "";
                                    Session["UserID"]   = userID;
                                    Session["Username"] = userID;
                                    DataSet dsUsers = DataManagerDevice.ProviderDevice.Users.ProvideUserDetails(userID, userSource);
                                    if (dsUsers != null && dsUsers.Tables[0].Rows.Count > 0)
                                    {
                                        Session["UserSystemID"] = dsUsers.Tables[0].Rows[0]["USR_ACCOUNT_ID"].ToString();

                                        string setAccessRight = DataManagerDevice.Controller.Users.SetAccessRightForSelfRegistration(dsUsers.Tables[0].Rows[0]["USR_ACCOUNT_ID"].ToString(), userSource, deviceIpAddress);
                                    }
                                    else
                                    {
                                        Session["UserSystemID"] = userID;
                                    }

                                    string auditorSuccessMessage = string.Format("User {0}, Successfully self registered on device {1}", userID, deviceIpAddress);
                                    if (isUpdated)
                                    {
                                        auditorSuccessMessage = string.Format("User {0},  Successfully updated card on device {1}", userID, deviceIpAddress);
                                    }
                                    LogManager.RecordMessage(deviceIpAddress, userID, LogManager.MessageType.Success, auditorSuccessMessage);
                                    RedirectPage();
                                }
                                else
                                {
                                    Response.Redirect("MessageForm.aspx?FROM=SelfRegistration.aspx&MESS=FAILED_TO_REGISTER");
                                    // LabelCommunicatorNote.Text = Localization.GetServerMessage(Constants.APPLICATION_TYPE_OSA_CLASSIC, deviceCulture, "FAILED_TO_REGISTER");
                                }
                            }
                            catch (Exception ex)
                            {
                                if (ex.Message == "Restart the MFP")
                                {
                                    //Response.Redirect("MessageForm.aspx?FROM=SelfRegistration.aspx&MESS=REGISTRATION_DEVICE_NOT_RESPONDING");
                                    // LabelCommunicatorNote.Text = Localization.GetServerMessage(Constants.APPLICATION_TYPE_OSA_CLASSIC, deviceCulture, "REGISTRATION_DEVICE_NOT_RESPONDING");
                                }
                                else
                                {
                                    //Response.Redirect("MessageForm.aspx?FROM=SelfRegistration.aspx&MESS=FAILED_TO_REGISTER");
                                    //LabelCommunicatorNote.Text = Localization.GetServerMessage(Constants.APPLICATION_TYPE_OSA_CLASSIC, deviceCulture, "FAILED_TO_REGISTER");
                                }
                            }
                        }
                        else
                        {
                            InvalidCard();
                        }
                    }
                    else
                    {
                        InvalidCard();
                    }
                }
            }
            else
            {
                InvalidCard();
            }
        }
        /// <summary>
        /// Adds the user details.
        /// </summary>
        /// <remarks>
        /// Sequence Diagram:<br/>
        ///     <img src="SequenceDiagrams/SD_PrintReleaseDevice.Browser.SelfRegistration.AddUserDetails.jpg"/>
        /// </remarks>
        private void AddUserDetails()
        {
            string cardID               = cardId;
            string userID               = TextBoxUserName.Text.Trim();
            string domainName           = TextBoxDomain.Text;
            string userPassword         = password;
            bool   isValidFascilityCode = false;
            bool   isValidCard          = false;
            string cardValidationInfo   = "";
            string deviceIpAddress      = Request.Params["REMOTE_ADDR"].ToString();
            string transformationCard   = Card.ProvideCardTransformation(null, Session["CardReaderType"] as string, cardID, ref isValidFascilityCode, ref isValidCard, ref cardValidationInfo);

            if (!string.IsNullOrEmpty(transformationCard))
            {
                if (string.IsNullOrEmpty(userPassword))
                {
                    userPassword = TextBoxPassword.Text.Trim();
                }

                string pin = TextBoxPin.Text.Trim();
                if (DataManagerDevice.Controller.Card.IsCardExists(cardID))
                {
                    TableCommunicator.Visible             = true;
                    TableSelfRegistrationControls.Visible = false;
                    TableFutureLogOnControls.Visible      = false;
                    redirectToLogOn            = true;
                    LabelCommunicatorNote.Text = Localization.GetServerMessage(Constants.APPLICATION_TYPE_OSA_CLASSIC, deviceCulture, "CARDID_ALREADY_USED");
                }
                else
                {
                    if (isValidFascilityCode == true && string.IsNullOrEmpty(cardValidationInfo) == true)
                    {
                        if (string.Compare(cardID, transformationCard, true) == 0) //cardID.IndexOf(transformationCard) > -1
                        {
                            int    defaultDepartment    = DataManagerDevice.ProviderDevice.Users.ProvideDefaultDepartment(userSource);
                            string userAuthenticationOn = string.Empty;

                            if (RadioButtonUseWindowsPassword.Checked)
                            {
                                userAuthenticationOn = Constants.AUTHENTICATE_FOR_PASSWORD;
                            }
                            else if (RadioButtonUsePin.Checked)
                            {
                                userAuthenticationOn = Constants.AUTHENTICATE_FOR_PIN;
                            }

                            try
                            {
                                if (userSource == Constants.USER_SOURCE_DB)
                                {
                                    domainName = "Local";
                                }
                                if (string.IsNullOrEmpty(domainName))
                                {
                                    domainName = "Local";
                                }

                                string emailid = string.Empty;
                                if (userSource == Constants.USER_SOURCE_AD)
                                {
                                    emailid = Ldap.GetUserEmail(domainName, userID, userPassword, userID.Replace("'", "''"));
                                }

                                // Check If the User exist in the AccountingPlus Database
                                string  isInserted            = "";
                                bool    isUpdated             = false;
                                DataSet dsExistingUserDetails = DataManagerDevice.ProviderDevice.Users.ProvideUserDetails(userID, userSource);
                                if (dsExistingUserDetails != null)
                                {
                                    if (dsExistingUserDetails.Tables[0].Rows.Count > 0)
                                    {
                                        string userName         = dsExistingUserDetails.Tables[0].Rows[0]["USR_ID"].ToString();
                                        string existingPassword = dsExistingUserDetails.Tables[0].Rows[0]["USR_PASSWORD"].ToString();
                                        // Update existing user
                                        isInserted = DataManagerDevice.Controller.Users.UpdateUser(userID, userPassword, cardID, userAuthenticationOn, pin, userSource, defaultDepartment, domainName, ref isUpdated);
                                    }
                                    else
                                    {
                                        // Insert new user
                                        isInserted = DataManagerDevice.Controller.Users.InsertUser(userID, userPassword, cardID, userAuthenticationOn, pin, userSource, defaultDepartment, domainName, emailid, ref isUpdated);
                                    }
                                }
                                else
                                {
                                    // Insert new user
                                    isInserted = DataManagerDevice.Controller.Users.InsertUser(userID, userPassword, cardID, userAuthenticationOn, pin, userSource, defaultDepartment, domainName, emailid, ref isUpdated);
                                }
                                if (string.IsNullOrEmpty(isInserted))
                                {
                                    //string assignUser = DataManagerDevice.Controller.Users.AssignUserToCostCenter(userID, "1", userSource);

                                    password            = "";
                                    Session["UserID"]   = userID;
                                    Session["Username"] = userID;
                                    DataSet dsUsers = DataManagerDevice.ProviderDevice.Users.ProvideUserDetails(userID, userSource);
                                    if (dsUsers != null && dsUsers.Tables[0].Rows.Count > 0)
                                    {
                                        Session["UserSystemID"] = dsUsers.Tables[0].Rows[0]["USR_ACCOUNT_ID"].ToString();
                                        string setAccessRight = DataManagerDevice.Controller.Users.SetAccessRightForSelfRegistration(dsUsers.Tables[0].Rows[0]["USR_ACCOUNT_ID"].ToString(), userSource, deviceIpAddress);
                                    }
                                    else
                                    {
                                        Session["UserSystemID"] = userID;
                                    }
                                    string auditorSuccessMessage = string.Format("User {0}, Successfully self registered on device {1}", userID, deviceIpAddress);
                                    if (isUpdated)
                                    {
                                        auditorSuccessMessage = string.Format("User {0},  Successfully updated card on device {1}", userID, deviceIpAddress);
                                    }
                                    LogManager.RecordMessage(deviceIpAddress, userID, LogManager.MessageType.Success, auditorSuccessMessage);
                                    RedirectToJobListPage();
                                }
                                else
                                {
                                    TableCommunicator.Visible             = true;
                                    TableSelfRegistrationControls.Visible = false;
                                    TableFutureLogOnControls.Visible      = false;
                                    LabelCommunicatorNote.Text            = Localization.GetServerMessage(Constants.APPLICATION_TYPE_OSA_CLASSIC, deviceCulture, "FAILED_TO_REGISTER");
                                }
                            }
                            catch (Exception ex)
                            {
                                TableCommunicator.Visible             = true;
                                TableSelfRegistrationControls.Visible = false;
                                TableFutureLogOnControls.Visible      = false;
                                if (ex.Message == "Restart the MFP")
                                {
                                    LabelCommunicatorNote.Text = Localization.GetServerMessage(Constants.APPLICATION_TYPE_OSA_CLASSIC, deviceCulture, "REGISTRATION_DEVICE_NOT_RESPONDING");
                                }
                                else
                                {
                                    LabelCommunicatorNote.Text = Localization.GetServerMessage(Constants.APPLICATION_TYPE_OSA_CLASSIC, deviceCulture, "FAILED_TO_REGISTER");
                                }
                            }
                        }
                        else
                        {
                            InvalidCard();
                        }
                    }
                    else
                    {
                        InvalidCard();
                    }
                }
            }
            else
            {
                InvalidCard();
            }
        }