Exemplo n.º 1
0
        public MD_GAI_1617 GetUserName(string connectionString, string sessionTicket, string groupID, string MasterRole, out TransactionalInformation transaction)
        {
            var method = MethodInfo.GetCurrentMethod();
            var ipInfo = Util.GetIPInfo(HttpContext.Current.Request);

            transaction = new TransactionalInformation();
            transaction.IsAuthenicated = true;
            MD_GAI_1617 data = new MD_GAI_1617();
            var         userSecurityTicket = VerifySessionToken(sessionTicket);

            try
            {
                data = cls_Get_Account_Information.Invoke(connectionString, userSecurityTicket).Result;

                if (data.group_id != groupID)
                {
                    if (data.AccountType == 0)
                    {
                        cls_Save_Permisions_to_User.Invoke(connectionString, new P_MD_SPtMU_1433 {
                            GroupName = groupID, Role = MasterRole, AccountID = userSecurityTicket.AccountID
                        }, userSecurityTicket);

                        //Company settings for new Tenant
                        P_MD_SCS_1700 parameter = new P_MD_SCS_1700();
                        parameter.AccountID              = userSecurityTicket.AccountID;
                        parameter.Email                  = WebConfigurationManager.AppSettings["mailFrom"];
                        parameter.OrderInterval          = 120;
                        parameter.ImmediateOrderInterval = 120;
                        cls_Save_Company_Settings.Invoke(connectionString, parameter, userSecurityTicket);

                        data.group_id = groupID;
                        data.role     = MasterRole;
                    }
                    else
                    {
                        transaction.ReturnMessage = new List <string>();
                        string errorMessage = "Zugriff nicht gestattet.";
                        transaction.ReturnStatus   = false;
                        transaction.IsAuthenicated = false;
                        transaction.ReturnMessage.Add(errorMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogInfo(new LogEntry(ipInfo.address, ipInfo.agent, connectionString, method, userSecurityTicket, ex));

                transaction.ReturnMessage = new List <string>();
                string errorMessage = ex.Message != "The creator of this fault did not specify a Reason." ? ex.Message : "Irgendwas ist schiefgegangen";
                transaction.ReturnStatus = false;
                transaction.ReturnMessage.Add(errorMessage);
                transaction.IsAuthenicated = true;
                transaction.IsException    = true;
                transaction.logoutUrl      = GlobalProperties.LOGIN_PAGE;
            }

            return(data);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Save new settings for MM user/tenant
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="connectionString"></param>
        /// <param name="sessionTicket"></param>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public string SaveAppSettings(AppSettings settings, string connectionString, string sessionTicket, out TransactionalInformation transaction)
        {
            var method = MethodInfo.GetCurrentMethod();
            var ipInfo = Util.GetIPInfo(HttpContext.Current.Request);

            bool password_verified = false;

            transaction = new TransactionalInformation();
            var userSecurityTicket = VerifySessionToken(sessionTicket);

            try
            {
                //check credentials
                try
                {
                    IAccountServiceProvider accountService;
                    var _providerFactory = ProviderFactory.Instance;
                    accountService = _providerFactory.CreateAccountServiceProvider();
                    ChangePasswordRequest request = new ChangePasswordRequest();
                    request.NewPassword = settings.Password;
                    request.OldPassword = settings.Password;
                    request.TenantID    = userSecurityTicket.TenantID;

                    var account = accountService.GetAllAccountsForTenant(userSecurityTicket.TenantID).Where(acc => acc.ID == settings.AdminUser).FirstOrDefault();

                    if (account != null)
                    {
                        request.Email     = account.Email;
                        password_verified = accountService.ChangePassword(request).ChangedAccounts.FirstOrDefault() != null;
                    }
                }
                catch (Exception ex)
                {
                    if (ex is SDKServiceException)
                    {
                        transaction.ReturnMessage = new List <string>();
                        ServiceErrror errorMessage = (ServiceErrror) new JavaScriptSerializer().Deserialize(ex.Message, typeof(ServiceErrror));

                        if (errorMessage.Code == 70211)
                        {
                            transaction.ReturnStatus = true;
                            password_verified        = true;
                        }
                        else
                        {
                            transaction.ReturnStatus = false;
                            transaction.ReturnMessage.Add(errorMessage.DeveloperMessage);
                            transaction.IsAuthenicated = true;
                            transaction.IsException    = true;
                            password_verified          = false;
                        }
                    }
                    else
                    {
                        Logger.LogInfo(new LogEntry(ipInfo.address, ipInfo.agent, connectionString, method, userSecurityTicket, ex));
                        throw new Exception("Something went wrong", ex);
                    }
                }

                if (password_verified)
                {
                    //save settings
                    P_MD_SCS_1700 parameter = new P_MD_SCS_1700();
                    parameter.AccountID              = settings.AdminUser;
                    parameter.Email                  = settings.Email;
                    parameter.OrderInterval          = settings.OrderInterval;
                    parameter.ImmediateOrderInterval = settings.ImmediateOrderInterval;

                    AppSettings previous_state = null;

                    Thread detailsThread = new Thread(() => GetCompanySettingsPreviousDetails(out previous_state, connectionString, userSecurityTicket));
                    detailsThread.Start();

                    cls_Save_Company_Settings.Invoke(connectionString, parameter, userSecurityTicket);

                    Logger.LogInfo(new LogEntry(ipInfo.address, ipInfo.agent, connectionString, method, userSecurityTicket, settings, previous_state));
                }
                else
                {
                    return("password invalid");
                }
            }
            catch (Exception ex)
            {
                Logger.LogInfo(new LogEntry(ipInfo.address, ipInfo.agent, connectionString, method, userSecurityTicket, ex));

                transaction.ReturnMessage = new List <string>();
                string errorMessage = ex.Message;
                transaction.ReturnStatus = false;
                transaction.ReturnMessage.Add(errorMessage);
                transaction.IsAuthenicated = true;
                transaction.IsException    = true;
            }

            return("ok");
        }