public void InitialiseDatabase(Result result)
		{
			if (!result.Succeeded)
				return;

			using (SQLiteConnection connection = new SQLiteConnection(DatabaseManager.DatabaseEngine.ConnectionString))
			{
				connection.Open();
				using (TransactionScope scope = new TransactionScope())
				{
					try
					{
						SQLiteCommand cmd = connection.CreateCommand();
						cmd.CommandText = GetSQL("SQLite Tables");
						cmd.ExecuteNonQuery();

						cmd.CommandText = GetSQL("Insert First ClientSpace");
						cmd.Parameters.Add(new SQLiteParameter("@ClientSpaceID", SecurityProvider.ClientSpaceID));
						int n = cmd.ExecuteNonQuery();

						if (n > 0) // then a new client was inserted, so insert accompanying data
						{
						}
						scope.Complete();
					}
					catch (Exception ex)
					{
						result.SetFailed("Unable to initialise SQLite database for SecurityProvider: " + ex.Message);
					}
				}
			}
			return;
		}
        public virtual void Initialise(Result result)
        {
            string ns = SchemaResourceNamespace;
            if (ns == null || ns == String.Empty)
                return;

            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    SQLiteConnection connection = (SQLiteConnection)DatabaseManager.DatabaseEngine.GetConnection();
                    SQLiteCommand cmd = connection.CreateCommand();
                    cmd.CommandText = ResourceLoader.LoadTextResource(asm, ns);
                    cmd.ExecuteNonQuery();
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.SetFailed(SchemaResourceNamespace + ": " + Environment.NewLine + ex.Message);
            }
            finally
            {
                DatabaseManager.DatabaseEngine.ReleaseConnection();
            }
        }
 void Instance_OnAjaxRequestAuthenticationCheck(System.Reflection.MethodInfo source, Result result)
 {
     if (!AllowSimultaneousLogins)
         if (AjaxRequestHandler.AuthKey != GetAuthKey(CurrentUsername))
         {
             result.SetFailed("Authentication failed: your account details have been used to log in elsewhere. Please log in again.");
             System.Diagnostics.Trace.WriteLine(CurrentUsername + " / AjaxRequestHandler.AuthKey: " + AjaxRequestHandler.AuthKey + "; GetAuthKey: " + GetAuthKey(CurrentUsername));
         }
 }
        void OnAjaxRequestAuthenticationCheck(System.Reflection.MethodInfo source, Result result)
        {
            if (!CurrentUser.Enabled)
            {
                result.SetFailed("Ajax method called failed because your account has been disabled.");
                return;
            }

            Attribute[] roleAttr = Attribute.GetCustomAttributes(source, typeof(RequiresRoleAttribute));
            Attribute[] permAttr = Attribute.GetCustomAttributes(source, typeof(RequiresPermissionAttribute));
            for (int i = 0; i < roleAttr.Length; i++)
                if (!CurrentUser.HasRole(((RequiresRoleAttribute)roleAttr[i]).RoleCode))
                {
                    result.SetFailed("Ajax method call failed because you do not have one or more required roles.");
                    return;
                }
            for (int i = 0; i < permAttr.Length; i++)
                if (!CurrentUser.HasPermission(((RequiresPermissionAttribute)permAttr[i]).PermissionTypeCode))
                {
                    result.SetFailed("Ajax method call failed because you do not have one or more required permissions.");
                    return;
                }
        }
        public void InitialiseDatabase(Result result)
        {
            if (!result.Succeeded)
                return;

            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    SQLiteConnection connection = (SQLiteConnection)DatabaseManager.DatabaseEngine.GetConnection();
                    SQLiteCommand cmd = connection.CreateCommand();
                    cmd.CommandText = ResourceLoader.LoadTextResource("Sprocket.Security.SQLite.schema.sql");
                    cmd.ExecuteNonQuery();

                    cmd.CommandText = procs["Insert First Client"];
                    cmd.Parameters.Add(new SQLiteParameter("@ClientSpaceID", SecurityProvider.ClientSpaceID));
                    int n = cmd.ExecuteNonQuery();

                    if (n > 0) // then a new client was inserted, so insert accompanying data
                    {
                        User user = new User(SecurityProvider.ClientSpaceID, "admin", "password", "System", "Administrator", "user@domain", true, true, false, 0);
                        PermissionType pt1 = new PermissionType(DatabaseManager.DatabaseEngine.GetUniqueID(), PermissionType.SuperUser, "Unrestricted Access", false);
                        PermissionType pt2 = new PermissionType(DatabaseManager.DatabaseEngine.GetUniqueID(), PermissionType.AdministrativeAccess, "Access Admin Area", false);
                        PermissionType pt3 = new PermissionType(DatabaseManager.DatabaseEngine.GetUniqueID(), PermissionType.UserAdministrator, "Create/Modify Users", false);
                        PermissionType pt4 = new PermissionType(DatabaseManager.DatabaseEngine.GetUniqueID(), PermissionType.RoleAdministrator, "Create/Modify Roles", false);
                        user.UserID = DatabaseManager.DatabaseEngine.GetUniqueID();
                        user.Activated = true;
                        Result r = Store(user);
                        if (r.Succeeded)
                        {
                            r = Store(pt1); if (r.Succeeded)
                            {
                                r = Store(pt2); if (r.Succeeded)
                                {
                                    r = Store(pt3); if (r.Succeeded)
                                    {
                                        r = Store(pt4); if (r.Succeeded)
                                        {
                                            r = AssignPermissionToUser(user.UserID, PermissionType.SuperUser);
                                        }
                                    }
                                }
                            }
                        }
                        if (!r.Succeeded)
                            result.SetFailed(r.Message);
                    }
                    if (result.Succeeded)
                        scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.SetFailed("Unable to initialise SQLite database for SecurityProvider: " + ex.Message);
            }
            finally
            {
                DatabaseManager.DatabaseEngine.ReleaseConnection();
            }
        }
 public void InitialiseDatabase(Result result)
 {
     try
     {
         using (TransactionScope scope = new TransactionScope())
         {
             SQLiteConnection connection = (SQLiteConnection)DatabaseManager.DatabaseEngine.GetConnection();
             SQLiteCommand cmd = connection.CreateCommand();
             cmd.Connection = connection;
             cmd.CommandText = ResourceLoader.LoadTextResource("Sprocket.Web.FileManager.SQLite.schema.sql");
             cmd.ExecuteNonQuery();
             scope.Complete();
         }
     }
     catch (Exception ex)
     {
         result.SetFailed(ex.Message);
     }
     finally
     {
         DatabaseManager.DatabaseEngine.ReleaseConnection();
     }
 }