Napoleon was able to create a common ideal that incorporated the feelings and thoughts of the masses. The philosophers from the Enlightenment contributed to foster a notion of national identity. They became conscious of having a common background, language, and origin shared over the centuries. When people were needed in the war effort, the idea of being part of the "revolutionary army" became key to incorporating people with no military training that quickly learned to battle and eventually professionalization was carried in the army.
The creation of the Napoleonic Code incorporated notions that at the time were modern, new, and appealing to the people that already had identified with notions of liberty, fraternity, equality. The initial and sustained military victories gave him the ingredients for staying in power as long as the victories were to be continued.