Example #1
0
        public virtual void SignOut()
        {
            string id = string.Empty;

            try
            {
                id = GetIdFromParameters();
            }
            catch
            {
                return;
            }
            PlugInType plugInType = PlugInType;

            DataRow instanceRow = Maps.Instance.DuradosMap.Database.GetSelectedInstanceRow(id, plugInType);
            int     appId       = (int)instanceRow["AppId"];

            if (GetRegisteredUserId().HasValue&& !IsSignedIn(GetRegisteredUsername()))
            {
                if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["plugInSignOut"] ?? "true"))
                {
                    Map.Logger.Log(this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), "username: "******", id: " + this.Request.QueryString["id"], null, 77, "url: " + System.Web.HttpContext.Current.Request.Url.ToString() + ", appId: " + appId);
                    PlugInHelper.SignOut();
                }
            }
        }
Example #2
0
 public static void ConvertHtmlToPDF(this String htmlFile, String pdfFile, double timeOutInMinute)
 {
     lock (typeof(ExtensionMethods))
     {
         PlugInHelper.GetPdfUtility().ConvertHtmlToPDF(htmlFile, pdfFile, timeOutInMinute);
     }
 }
Example #3
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            string controllerName = ((MvcHandler)httpContext.Handler).RequestContext.RouteData.Values["controller"].ToString();

            Maps.Instance.DuradosMap.Logger.Log("Plugin Authorization Filter " + ((MvcHandler)httpContext.Handler).RequestContext.RouteData.Values["controller"].ToString(), ((MvcHandler)httpContext.Handler).RequestContext.RouteData.Values["action"].ToString(), "username: "******", id: " + System.Web.HttpContext.Current.Request.QueryString["id"], null, 77, "url: " + System.Web.HttpContext.Current.Request.Url.ToString());
            return(Maps.Instance.DuradosMap.Database.GetRegisteredUserId(PlugInHelper.GetPlugInUserId(GetPlugInType(controllerName), httpContext.Request)).HasValue);
            //return GetPlugInSecurity(controllerName, httpContext).GetRegisteredUserId().HasValue;
        }
Example #4
0
        /// <summary>
        /// Create new master user in membership service, in modubiz db, in curent app db
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="createInUsersTable"></param>
        /// <param name="CreateInMembership"></param>
        /// <param name="createInCurrentAppUsersTable"></param>
        /// <param name="createInUserAppTable"></param>
        private void CreateNewMasterUser(string userName, string password, bool createInUsersTable, bool CreateInMembership, bool createInCurrentAppUsersTable, bool createInUserAppTable)
        {
            Dictionary <string, object> parameters = new Dictionary <string, object>();
            string email             = "*****@*****.**";
            string role              = "User";
            string encryptedPassword = CryptorHelper.Encrypt(password, true);

            if (createInUsersTable)
            {
                string firstName = "wix";
                string lastName  = "wix";
                Guid   guid      = Guid.NewGuid();
                string sql       = "INSERT INTO [durados_User] ([Username],[FirstName],[LastName],[Email],[Role],[Guid], [Password]) VALUES (@Username,@FirstName,@LastName,@Email,@Role,@Guid, @Password); SELECT IDENT_CURRENT(N'[durados_User]') AS ID ";

                parameters.Add("@Email", email);
                parameters.Add("@Username", userName);
                parameters.Add("@Password", encryptedPassword);
                parameters.Add("@FirstName", firstName);
                parameters.Add("@LastName", lastName);
                parameters.Add("@Role", role);
                parameters.Add("@Guid", guid);

                object scalar = SqlAccess.ExecuteScalar(Maps.Instance.DuradosMap.Database.ConnectionString, sql, parameters);
            }

            if (createInUserAppTable)
            {
                parameters = new Dictionary <string, object>();
                parameters.Add("newUser", userName);
                parameters.Add("appName", Map.AppName);
                parameters.Add("role", role);
                sqlAccess.ExecuteNonQuery(Maps.Instance.DuradosMap.connectionString, "durados_NewAppAsignment @newUser, @appName, @role", parameters, null);
            }

            if (createInCurrentAppUsersTable)
            {
                int userId = Map.Database.GetUserID(userName);

                if (userId == -1)
                {
                    throw new DuradosException("Problem with get user detalis");
                }

                PlugInHelper.AddUserToApp(Convert.ToInt32(Map.Id), userId, role);
            }

            if (CreateInMembership)
            {
                System.Web.Security.MembershipCreateStatus createStatus = (new Durados.Web.Mvc.Controllers.AccountMembershipService()).CreateUser(userName, password, email);
                if (createStatus == System.Web.Security.MembershipCreateStatus.Success)
                {
                    System.Web.Security.Roles.AddUserToRole(userName, role);
                }
            }
        }
Example #5
0
        public virtual ActionResult AfterRegistration(string username)
        {
            string id = this.Request.QueryString["id"];

            if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(id) && Maps.Instance.DuradosMap.Database.GetGuidByUsername(username) == id)
            {
                System.Web.Security.MembershipUser user = System.Web.Security.Membership.Provider.GetUser(username, true);
                user.IsApproved = true;
                System.Web.Security.Membership.UpdateUser(user);
                PlugInHelper.SignIn(username);
            }
            return(Redirect("/index.aspx"));
        }
Example #6
0
        public ActionResult app(string state)
        {
            string json = "";

            try
            {
                //this is a sample
                /**string encryptedBase64String=A9XqFaC4VY7qQeXRwBGthnXaf2bFtIaAMhaTpROibMKdGhM8NFTRIvqWjyN3S9mCPjRprQwjJ7P%2F1a6TNpQPPidE7kPx%2BGhvAEhEYV6dZN02qASI1HVvVdCooHzsFaqVixIqZSGGU8SBQu%2F2GVrPGJiMN9CyvmJBSe3YFtWzNFs0g0OjkG8K8aDmw3VqgcWalFr7CYDyU4H81rgY6DpIwdLNewAPJ5rBvchRMAOvXbgCe4DAGbFNmYEpy9I4TH8oKRMtaDoHOlvPkYKTWFGWmg%3D%3D*/

                json = Base64CryptoHelper.DecryptString(Server.UrlDecode(state).Replace(" ", "+"));/*Fix for decoding problem that causes + to be replaced with space " "*/
                if (String.IsNullOrEmpty(json))
                {
                    if (!String.IsNullOrEmpty(state))
                    {
                        json = state;
                    }
                }
            }
            catch (Exception e)
            {
                return(FailureResponse(CreateAppParameter.CODES.INVALID_SECURITY_DATA, "Security failure", 0, null, null));
            }


            if (String.IsNullOrEmpty(json))
            {
                return(FailureResponse(CreateAppParameter.CODES.INVALID_SECURITY_DATA, "Security failure", 0, null, null));
            }

            PluginArgs oArgs = new PluginArgs();

            try
            {
                JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
                oArgs = (PluginArgs)jsonSerializer.Deserialize <PluginArgs>(json);

                if (string.Compare(oArgs.token, "backand", false) != 0)
                {
                    return(FailureResponse(CreateAppParameter.CODES.INVALID_SECURITY_DATA, "Security failure", 0, null, null));
                    //Security failure due to invalid arguments, redirect to Heroku
                }
            }
            catch (Exception e)
            {
                //Security failure due to invalid arguments, redirect to Heroku
                return(FailureResponse(CreateAppParameter.CODES.INVALID_CONNECTION_DATA, "invalid ConnectionId", 0, null, null));
            }

            //pass security token then sign the user GetUsernameByUserId(uid);
            //oArgs.resource_id = "404";
            string userName = Maps.Instance.DuradosMap.Database.GetUsernameById(oArgs.resource_id);

            PlugInHelper.SignIn(userName);
            int uid = Convert.ToInt32(oArgs.resource_id);

            //oArgs.app_name += "testqa";

            int?connectionId = null;

            string appName       = oArgs.app_name;
            string pluginAppName = appName;
            bool   bAppExist     = Maps.Instance.AppExists(appName, uid).HasValue;

            if (bAppExist == true)
            {
                /**This user has this App/Console*/
                /***Validate Connection String !!! what about updatig connection string scenario?*/
                //Redirect to app (console)
                return(SuccessResponse(0, userName, appName, pluginAppName, true));
            }
            else
            {
                //DuradosController d = new DuradosController();

                bool connectionValidation = false;
                bAppExist = Maps.Instance.AppExists(appName).HasValue;
                ConnectionParameter oConnectionParameter = new ConnectionParameter();
                /**If true app exists but not for this user (resource_id)*/

                if (bAppExist == true)
                {
                    /**Create new and unique app name*/
                    appName = GenerateAppName(appName, uid);
                }

                try
                {
                    oConnectionParameter = ValidateConnection(oArgs.db, oArgs.resource_id);
                    connectionValidation = true;
                }
                catch (Exception exception)
                {
                    Map.Logger.Log(GetControllerNameForLog(this.ControllerContext), this.ControllerContext.RouteData.Values["action"].ToString(), exception.Source, exception, 3, null);
                    //Redirect dur to invalid connection string
                    return(FailureResponse(CreateAppParameter.CODES.INVALID_CONNECTION_DATA, exception.Message, 0, userName, appName));
                }

                if (connectionValidation == true)
                {
                    try
                    {
                        string     serverName = oConnectionParameter.serverName;
                        string     catalog    = oConnectionParameter.catalog;
                        string     dbUserName = oConnectionParameter.dbUsername;
                        string     dbPassword = oConnectionParameter.dbPassword;
                        int        port       = oConnectionParameter.port;
                        SqlProduct productId  = oConnectionParameter.productId;

                        connectionId = SaveConnection(serverName, catalog, dbUserName, dbPassword, oArgs.resource_id, productId, oConnectionParameter.ssl);
                    }
                    catch (Exception exception)
                    {
                        Map.Logger.Log(GetControllerNameForLog(this.ControllerContext), this.ControllerContext.RouteData.Values["action"].ToString(), exception.Source, exception, 1, "fail to save connection string");
                        //Redirect due to create connection id for retrived connection string
                        //return View("~/Views/PlugIn/Heroku/ConnectionHandler.aspx", new ConnectionHandlerParameter() { url = "" });
                        return(FailureResponse(CreateAppParameter.CODES.INVALID_CONNECTION_DATA, exception.Message, 0, userName, appName));
                    }
                }

                if (!connectionId.HasValue || connectionId == null)
                {
                    /**If not valide redirect to failure page*/
                    return(FailureResponse(CreateAppParameter.CODES.INVALID_CONNECTION_DATA, "invalid ConnectionId", 0, userName, appName));
                }
            }

            /**Redirect and Create new App send new connection id*/
            return(SuccessResponse(connectionId.Value, userName, oArgs.app_name, pluginAppName));
        }